Boost logo

Boost :

From: Reece Dunn (msclrhd_at_[hidden])
Date: 2003-12-10 13:35:53


Jeremy Maitin-Shepard wrote:

>What is the advantage in typing "BOOST_TYPENAME" when it would _always_
>be semantically equivalent to "class"?

One of the applications of the typename keyword is to signify a *type* as
opposed to a class in a template argument. This means that

template< typename T, class Traits >
struct typename_demo
{
   typedef typename Traits::value_type value_type; // ok
   typedef typename T::arg_type arg_type; // T is a type, not a class
};

This means that T can be int, float, ... as well as being a class. Although
the code above will not generate an error by the compiler, it is intended
for the developer to see that the second template argument must be a class,
not an int, for example.

BOOST_TYPENAME would be implemented as

#if(compiler-supports-typename)
# define BOOST_TYPENAME typename
#else
# define BOOST_TYPENAME class // older compilers
#endif

and thus you can retain the above distinction while supporting non-compliant
compilers.

Regards,
Reece H Dunn

_________________________________________________________________
Hotmail messages direct to your mobile phone http://www.msn.co.uk/msnmobile


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk