Boost logo

Boost :

From: John Maddock (John_Maddock_at_[hidden])
Date: 1999-11-23 07:08:27


Beman -

The paremeter traits idea would indeed be a very useful addition.

// could specialize for all the built-in types.

Yes, for integral types that fit in a machine word, passing by value is
likely to be optimal case, longer types (long long etc) passing by
reference is likely to be optimal. So....

specialise for bool, short, unsigned short, int, unsigned int, then for
long only if UINT_MAX == ULONG_MAX.

I was also playing with this idea and wondered whether a version for const
arguments would be useful, using your code as a basis it would look
something like:

template< typename T >
struct const_parameter_traits
{
    typedef T template_type;
    typedef T raw_type;
    typedef const T const & parameter_type;
    static const char * which() { return "non-specialized template";
}
};

template< typename T >
struct const_parameter_traits< T* >
{
    typedef T * template_type;
    typedef T raw_type;
    typedef const T * parameter_type;
    static const char * which() { return "T* specialization"; }
};

template< typename T >
struct const_parameter_traits<const T* >
{
    typedef const T * template_type;
    typedef T raw_type;
    typedef const T * parameter_type;
    static const char * which() { return "T* specialization"; }
};

template< typename T >
struct const_parameter_traits< T& >
{
    typedef T & template_type;
    typedef T raw_type;
    typedef const T & parameter_type;
    static const char * which() { return "T& specialization"; }
};

template< typename T >
struct const_parameter_traits<const T& >
{
    typedef const T & template_type;
    typedef T raw_type;
    typedef const T & parameter_type;
    static const char * which() { return "T& specialization"; }
};

template<>
struct const_parameter_traits< int >
{
    typedef int template_type;
    typedef int raw_type;
    typedef int parameter_type;
    static const char * which() { return "long specialization"; }
};

// etc...

- John.


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