Boost logo

Boost :

From: Hamish Mackenzie (boost_at_[hidden])
Date: 2002-02-18 20:56:18


On Mon, 2002-02-18 at 22:49, Rainer Deyke wrote:
> ----- Original Message -----
> From: "Hamish Mackenzie" <boost_at_[hidden]>
> To: <boost_at_[hidden]>
> Sent: Monday, February 18, 2002 3:01 PM
> Subject: RE: [boost] Most needed/desired features in C++
>
>
> > I thought this was solved by Koenig lookup?
> >
> > using std::swap;
> > swap( x, y );
> >
> > Then Koenig lookup will find swap if it is in the namespace that x
> and y
> > are in will it not?
>
> You can't be sure that every user of 'std::swap' uses
> argument-dependent lookup.

I don't think we need to change the language, just the library.

Steps
1) Add boost/swap.hpp (attached)
2) Move all swap functions in the boost namespace into boost_swap_detail
namespace. This is particularly important for template versions that the
user may wish to overload.

Users can then call
  foo x;
  foo y;
  boost::swap( x, y )
to their hearts content safe in the knowledge that it will choose their
swap function if they have defined one that matches and is in the same
namespace as foo.

The price to pay is that no class in the boost namespace will be
swapable until it has its own swap function. Attempting to swap them
will result in an ambiguity in swap_impl (between the two other template
swap functions in swap.hpp). This is because Koenig lookup makes both
visible and the compiler can't choose.

Hamish




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