Boost logo

Boost :

From: Frank Mori Hess (fmhess_at_[hidden])
Date: 2008-04-12 10:35:52

On Saturday 12 April 2008 08:31, Niels Dekker - mail address until
2008-12-31 wrote:
> Hmmm... I can't find optional<T>::swap in my copy of optional.hpp
> (straight from the trunk)! It looks like optional<T> only has a
> non-member boost::swap function! I think it should definitely have a
> swap member function, as well! As a guideline, whenever providing a
> non-member swap function for a class type, one should provide a swap
> member function as well! (E.g., Scott Meyers, Effective C++ Third
> Edition, item 25!). Why? Because the STL does it that way, /and/
> because it allows swapping a temporary.
> Of course, optional<T>::swap could be implemented very easily:
> void swap( optional & arg )
> {
> using std::swap;
> swap(*this, arg);
> }
> By default, it would call the original boost::swap(optional<T>&,
> optional<T>&), by appying ADL. But it would also allow end users to
> customize the behavior of optional<T>::swap for their specific types,
> either by providing a template specialization of boost::swap or
> std::swap, or by adding an overloaded swap function to the namespace of
> T.

Maybe it was just my compiler, but I've had problems in the past with
member swap functions breaking ADL for swap used inside the class. IIRC,
it would find the member swap function and stop there, never doing ADL.


Boost list run by bdawes at, gregod at, cpdaniel at, john at