
David Abrahams wrote:
http://svn.boost.org/svn/boost/sandbox/move/boost/move/detail/has_swap_overl... I think that might be an older version of the same functionality. In fact, I think I forgot about the old version when I posted the one I did. So you might compare and see if one is better.
It's actually the other way around: The version that Daniel James added to svn/boost/sandbox/move is the better one. It has three more has_swap_overload specializations: for std::basic_string, std::multiset, and std::multimap. And it has the std forward declarations included from <boost/functional/detail/container_fwd.hpp>.
It's a pity that has_swap_overload<T> yields false negatives, when T has std as associated namespace.
It's easy enough to fix that with specialization, as my posted example shows.
Hmmm... So has_swap_overload<T> should have a specialization for each class template that has a template type parameter (allowing std as associated namespace of the template argument) and a custom swap. That's a pity.
IMO the best solution is like this:
std is an associated namespace of T ? has_member_swap<T> : has_nonmember_swap<T>
plus any specializations required to handle something like tr1::array that might not have a member swap.
FYI, the tr1::array that comes with VC9 SP1 /does/ have a member swap, as well as a swap overload. Anyway, I was also considering a more "lightweight" way to tweak MSVC's Swaptimization, merely based upon tr1::has_nothrow_copy (which is included VC9 SP1). Because when using MSVC9, whenever a function like vector<T>::push_back needs to reallocate, it moves its elements /either/ by copy-construction /or/ by default-construction + swap, depending on whether "Swaptimization" is turned on for type T. Isn't it reasonable to just do default-construction + swap, /unless/ T has no-throw copy-construction? if tr1::has_nothrow_copy<T> move by means of copy else move by means of default-construction + swap Kind regards, Niels