Silicium
exchange.hpp
Go to the documentation of this file.
1 #ifndef SILICIUM_REACTIVE_EXCHANGE_HPP
2 #define SILICIUM_REACTIVE_EXCHANGE_HPP
3 
5 #include <utility>
6 #include <boost/config.hpp>
7 
8 namespace Si
9 {
10  namespace detail
11  {
12  template <class T, class U>
13  T exchange_impl(T &dest, U &&source, std::true_type)
14  {
15  auto old = Si::move_if_noexcept(dest);
16  dest = std::forward<U>(source);
17  return old;
18  }
19 
20  template <class T, class U>
21  T exchange_impl(T &dest, U &&source, std::false_type)
22  {
23  auto old = dest;
24  dest = std::forward<U>(source);
25  return old;
26  }
27  }
28 
29  template <class T, class U>
30  T exchange(T &dest, U &&source)
31  {
32  return detail::exchange_impl(
33  dest,
34  std::forward<U>(source),
35  std::integral_constant<bool,
36 #ifdef _MSC_VER
37  true
38 #else
39  BOOST_NOEXCEPT_EXPR(dest = std::forward<U>(source))
40 #endif
41  >()
42  );
43  }
44 }
45 
46 #endif
Definition: absolute_path.hpp:19
BOOST_CONSTEXPR Result move_if_noexcept(T &x)
Definition: move_if_noexcept.hpp:17
T exchange(T &dest, U &&source)
Definition: exchange.hpp:30
T exchange_impl(T &dest, U &&source, std::true_type)
Definition: exchange.hpp:13