
On 22 May 2001, Carl R. Witty wrote:
"D. Tweed"
writes: In my experience the C++ idiom `you only pay for what you use' (==> templates are essentially type-checked macros) and the fact most compilers are evolved from C compilers makes working with templates a real pain in practice.
I'm not sure what you mean by type-checked here. Templates are not type-checked at definition time, but are type-checked when they are used; the same is true of ordinary macros.
I was thinking in terms of (to take a really simple example)
template<class T>
void
initialiseArray(T** arr,const T& elt,int bnd)
{
for(int i=0;i

On 23-May-2001, D. Tweed
On 22 May 2001, Carl R. Witty wrote:
"D. Tweed"
writes: In my experience the C++ idiom `you only pay for what you use' (==> templates are essentially type-checked macros) and the fact most compilers are evolved from C compilers makes working with templates a real pain in practice.
I'm not sure what you mean by type-checked here. Templates are not type-checked at definition time, but are type-checked when they are used; the same is true of ordinary macros.
I was thinking in terms of (to take a really simple example)
template<class T> void initialiseArray(T** arr,const T& elt,int bnd) ... If I try and use intialiseArray(<obj of type foo>,<obj of type bar>), with the template function I get the error when passing in the parameters;
In other words, *calls to* template functions are type-checked at compile time.
However, *definitions of* template functions are only type-checked when they
are instantiated.
--
Fergus Henderson

On Thu, 24 May 2001, Fergus Henderson wrote:
I'm not sure what you mean by type-checked here. Templates are not type-checked at definition time, but are type-checked when they are used; the same is true of ordinary macros.
I was thinking in terms of (to take a really simple example)
template<class T> void initialiseArray(T** arr,const T& elt,int bnd) ... If I try and use intialiseArray(<obj of type foo>,<obj of type bar>), with the template function I get the error when passing in the parameters;
In other words, *calls to* template functions are type-checked at compile time. However, *definitions of* template functions are only type-checked when they are instantiated.
Umm... the point I was trying to make (in an inept way) was that the type-check error messages that you get are in the context of the original function that you physically wrote; whereas in the macro version rather the error is in terms of the munged source code, which can make abstracting it to the `original erroneous source line' difficult. ___cheers,_dave________________________________________________________ www.cs.bris.ac.uk/~tweed/pi.htm|tweed's law: however many computers email: tweed@cs.bris.ac.uk | you have, half your time is spent work tel: (0117) 954-5250 | waiting for compilations to finish.
participants (2)
-
D. Tweed
-
Fergus Henderson