Boost logo

Boost :

From: Thomas Witt (witt_at_[hidden])
Date: 2003-09-09 09:44:06


Daniel,

Daniel Frey wrote:

> OTOH you need to
> provide a swap function, so you have to take into account that the class
> needs to support it anyway by some code.

?

>
> Some classes might not do that with a member function swap, but with a
> friend function that has two arguments. Also, most classes that have a
> member-function also provide a free function with two parameters
> resolving to the member functions. That given, this might also be a
> reasonable implementation which might work on more compilers today:

Daniel John is talking about std::swap. Your solution does not adress
one of the fundamental problems I see. Having a member, what might be
the natural thing to do, would require a free function as well. This is
tedious and should be avoided.

>
> namespace boost
> {
> template< typename T >
> inline void swap( T& lhs, T& rhs )
> {
> using std::swap;
> swap( lhs, rhs );
> }
> }

This is a user solution to libraries(users)-cannot-overload-std::swap.
AFAICS this is not a solution to the std lib problem.

>
> ADL should find the better match if T provides a swap(T&,T&), otherwise
> the default from std:: will be used. The question is IMHO which
> requirements to T (in a namespace N) we request:
>
> void N::T::swap( T& );
>
> or
>
> void N::swap( T&, T& );

This is _a_ question but not _the_ question.

Regards

Thomas

-- 
Dipl.-Ing. Thomas Witt
Institut fuer Verkehrswesen, Eisenbahnbau und -betrieb, Universitaet 
Hannover
voice: +49(0) 511 762 - 4273, fax: +49(0) 511 762-3001
http://www.ive.uni-hannover.de

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