Boost logo

Boost :

From: Jens Maurer (Jens.Maurer_at_[hidden])
Date: 2001-01-24 18:06:50


Stephen Silver wrote:
> The std::swap I have for my GMP mpz_t wrapper is like this:
>
> namespace std
> {
> template <>
> void swap(::Integer& a, ::Integer& b)
> {
> ::mpz_swap(a.mpz, b.mpz);
> }
> }
>
> This is a specialization, not an overload, and is legal.

This is fine for classes such as the one you describe. However,
this covers only a small part of the problem, because most
entities in boost are class templates, e.g. rational<T>.
This would require something like

namespace std
{
    template <class T>
    void swap(boost::rational<T>& a, boost::rational<T>& b)
    {
        a.swap(b);
    }
}

which is an overload and not a specialization, partly because
there is no such thing as a partial specialization of
function templates in C++.

And function overloads in namespace std are forbidden, just to
re-iterate once more.

Jens Maurer


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