Boost logo

Boost :

Subject: Re: [boost] [non-instrusive move] interest in new library?
From: Joseph Gauterin (joseph.gauterin_at_[hidden])
Date: 2013-01-10 04:45:53

Out of curiosity, how are you detecting if a member function swap exists?
>it detects at compile-time if the type of the
>argument(s) has a member swap function

In general, there's no way of knowing if a member swap function is
more efficient than a single assignment. It isn't even for all the
examples you gave - boost::array<T,N>::swap performs N boost::swaps,
which, if T doesn't provide an efficient swap, results in N calls to
std::swap, and 3*N assignments. In general I'm wary of using swap in a
generic context unless the intent is to swap (i.e. not as a potential
optimization of assignment).

>The library is non-intrusive and generic, it will perform an efficient move
>in terms of swap for any type providing a member
>swap operation, e.g, std::vector, boost::array, user-defined types etc.

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