Boost logo

Boost Users :

Subject: Re: [Boost-users] [utility] swap
From: Neil Groves (neil_at_[hidden])
Date: 2010-03-05 13:35:32


On Fri, Mar 5, 2010 at 10:30 AM, Joseph Gauterin <
joseph.gauterin_at_[hidden]> wrote:

> It's really a replacement for the common idiom:
>
> using std::swap;
> swap(a,b);
>

IIRC one should write 'using namespace std' to avoid artificially preferring
std::swap over swap from other namespaces.

>
> Which enables the use of ADL with a fallback to std::swap.
> Unfortunately, there are a number of compilers that choke on that
> idiom. boost::swap abstracts the idiom in a more portable way (and
> adds support for arrays).
>

While your point is completely correct, I think that it is an important
point that boost::swap allows the use of qualified calls to swap while
maintaining extensibility. This allows one to avoid using XXX::swap in
header files etc. This is extremely useful when writing header only
libraries for example.

Neil Groves



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net