Topic: Is the ARM right cf template function argument matching ?


Author: ajp@dsl.eng.cam.ac.uk (Andy Piper)
Date: Wed, 17 Nov 1993 09:10:47 GMT
Raw View
The ARM p345-346 gives the sequence of events for argument matching of
template functions:

"[2] Look for a function template from which a function that can be called
with an exact match can be generated; if found, call it. ... Not even
trivial conversions will be appied in this case."

I know that the second part has been relaxed in cfront 3.0.x to allow
trivial conversions, but I it would seem to me (IMHO) that conversions
should be allowed in some circumstances. Obviously the rules make
sense for definitions like:

template<class T> T max(T,T);

However, for things like:

template<class T> Matrix<T> operator*(const Matrix<T>&, const
Matrix<T>&);

The rule makes less sense, and in fact makes a parameterized Matrix a
second class citizen to a non parameterized Matrix. For instance I
might define a conversion from a Vector to a Matrix since I can
(mathematically) validly perform the above operation for Matrix *
Vector where I just consider the Vector to be a special type of
Matrix. Using a mf definition of operator* I can achieve this for:

Matrix * Vector

But not for:

Vector * Matrix

 - I need to use a template function and because conversions are not
allowed the above will fail. This to me seems inconsistent with the
operation of normal classes. IMHO [2] ought to be changed to:

"[2] Look for a function template from which a function that can be called
with an exact match can be generated; if found, call it.
[2a] If all the type arguments of a function template are known to be
of class type then try ordinary overloading resolution for that
function template."

Is this stupid ? :-). I'm sorry if this has been discussed already or
is different in the working paper.

andy


--
Andy Piper     email: ajp@eng.cam.ac.uk
Cambridge University Engineering Department  tel: +44 223 33 2754
Trumpington St
Cambridge, UK
--
Andy Piper     email: ajp@eng.cam.ac.uk
Cambridge University Engineering Department  tel: +44 223 33 2754
Trumpington St
Cambridge, UK