Boost logo

Boost :

Subject: [boost] [utility] [swap] How about Boost.Move?
From: Antony Polukhin (antoshkka_at_[hidden])
Date: 2013-07-25 09:44:42


Hi,

Sources of Boost.Variant have a swap implementation that takes advantage of
move emulation. That code can be useful for Boost.Swap.

The idea is not to use std::swap in case of ADL failure, but use a swap
implementation that is aware of move emulation:

namespace boost_swap_impl
{
namespace swap_move_emulated {
template <typename T>
inline void swap(T& lhs, T& rhs)
{
    T tmp( boost::move(lhs) );
    lhs = boost::move(rhs);
    rhs = boost::move(tmp);
}
}

  template<class T>
  void swap_impl(T& left, T& right)
  {
    //using namespace std;//use std::swap if argument dependent lookup fails
    using namespace boost_swap_impl::swap_move_emulated;
    swap(left,right);
  }
// ...

With that code types that use move emulation can be swapped faster and even
move only types can be swapped.

So, what do the community think about such optimization?

-- 
Best regards,
Antony Polukhin

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk