Boost logo

Boost :

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


> call_traits<> and empty_member<> have been added to an experimental
> version of utility.hpp:
>
> http://www.boost.org/libs/experimental/utility.hpp
> http://www.boost.org/libs/experimental/call_traits_test.hpp
>
> The test program works under GCC 2.95.2, Metrowerks CodeWarrior 5.2,
> and MS VC++ 6.0 SP3.
>
> Comments appreciated!

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:

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

#include <limits>

[...]

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

    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 };
    };

    #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION

    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 handles long long properly.
    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