|
Boost : |
From: Daniel Frey (daniel.frey_at_[hidden])
Date: 2003-09-09 07:47:56
John Maddock wrote:
> It seems to me that this may be of interest here as well:
>
>>The interesting thing is, this is actually implementable right now within
>>the current language - I've attached a sample implementation to the end of
>>this message, hopefully it really is legal code, although I admit that
I think your code is great as it isn't an intrusive approach at first
sight: No need to flag your class to be swappable. 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:
namespace boost
{
template< typename T >
inline void swap( T& lhs, T& rhs )
{
using std::swap;
swap( lhs, rhs );
}
}
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& );
Regards, Daniel
-- Daniel Frey aixigo AG - financial training, research and technology Schloß-Rahe-Straße 15, 52072 Aachen, Germany fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99 eMail: daniel.frey_at_[hidden], web: http://www.aixigo.de
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk