Boost logo

Boost :

From: Daryle Walker (darylew_at_[hidden])
Date: 2001-02-06 18:40:49


With the debacle over issues with overloading standard routines (brought to
the forefront by boost::rational), should we have a swapping routine in
boost? It would be generalized as a class/function template pair:

//==========================================================================
namespace boost
{

    template < typename T >
        struct swapper;
    template < typename T >
        void swap( T &a, T &b );

    template < typename T >
    struct swapper
    {
        void operator ()( T &a, T &b );
    };

    template < typename T >
    inline
    void
    swapper<T>::operator ()
    (
        T & a,
        T & b
    )
    {
        // it's not "std::swap<T>(a,b)" so non-template overloads can work
        std::swap( a, b );
    }

    template < typename T >
    inline
    void
    swap
    (
        T & a,
        T & b
    )
    {
        swapper<T>()( a, b );
    }

}
//==========================================================================

Other types in "boost" that need to specialize "swap" can specialize the
"swapper" class template or overload a "swap" non-template function. User
types not in boost could just specialize the "swapper" class template.

-- 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com

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