Boost logo

Boost :

From: Darin Adler (darin_at_[hidden])
Date: 1999-11-28 19:41:35


Lets try that again. (The previous version didn't work for
BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION platforms.)

Here's a less verbose implementation of call_traits that depends on a proper
implementation of the <limits> header. Tested with CodeWarrior 5.2, but not
the others:

--------------------------------

    // Provides an efficient type for passing function arguments.
    // See documentation for contributors.

    #ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION

    template< typename T > struct call_traits< T >
    {
        typedef const T & type;
        enum { by_value = false };
    };

    #else // ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION

    template< typename T, bool is_numeric
        = std::numeric_limits<T>::is_specialized > struct call_traits;
        
    template< typename T > struct call_traits< T, false >
    {
        typedef const T & type;
        enum { by_value = false };
    };

    template< typename T > struct call_traits< T, true >
    {
        typedef const T type;
        enum { by_value = true };
    };

    template< typename T > struct call_traits< T*, false >
        {typedef T * const type; enum { by_value = true }; };
    template< typename T > struct call_traits< T&, false >
        {typedef T & type; enum { by_value = true }; };
    template< typename T, std::size_t sz > struct call_traits<T[sz], false>
        {typedef T * const type; enum { by_value = true }; };

    #endif // ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION

--------------------------------

This has two advantages that I know of:

    1) Under CodeWarrior, it passes "long long" by value, for example.
    2) We avoid another list of all the built-in integer types.

This has one disadvantage that I know of:

    1) It requires a working version of <limits>.

    -- Darin


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