Boost logo

Boost :

From: Daryle Walker (darylew_at_[hidden])
Date: 2001-01-23 14:07:18


on 1/21/01 10:33 PM, Paul Moore at gustav_at_[hidden] wrote:

[SNIP]
> This could be replaced with
>
> IntType r(n%m);
> std::swap(n,m)
> std::swap(m,r);

Does it have to be the "swap" from the "std" namespace? Could it be
generalized to just "swap" like

//=============================
using std::swap;
IntType r( n % m );
swap( n, m );
swap( m, r );
//=============================

Since we can't put specializations of template functions, like "swap", in
the "std" namespace, you should allow "swap"s in the class's namespace and
depend on Koeing lookup. I try to define "swap"s so it can be used that
way:

//=============================
namespace boost
{
    class unsigned_bigint
    {
        //...
        void swap( unsigned_bigint &other );
        //...
    };

    void swap( unsigned_bigint &a, unsigned_bigint &b );

    //...

    void unsigned_bigint::swap( unsigned_bigint &other )
    {
        using std::swap;
        swap( this->impl_, other.impl_ );
    }

    void swap( unsigned_bigint &a, unsigned_bigint &b )
    {
        a.swap( b );
    }
}
//=============================

(Remind me to get this class out after the next "more_io" update.)

[SNIP]
> BTW, I suspect this means that rational<> should provide a swap()
> specialisation, to delegate to (potential) swap() specialisations for
> IntType. Can anyone remind me what the canonical form of swap()
> is?

I'm not sure of the "canonical" form, but I think what I have above is a
good model.

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