1 /*
2 Copyright 2018 Glen Joseph Fernandes
3 ([email protected])
4 
5 Distributed under the Boost Software License, Version 1.0.
6 (http://www.boost.org/LICENSE_1_0.txt)
7 */
8 #ifndef BOOST_CORE_EXCHANGE_HPP
9 #define BOOST_CORE_EXCHANGE_HPP
10 
11 #include <boost/config.hpp>
12 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
13 #include <boost/config/workaround.hpp>
14 #include <utility>
15 #endif
16 
17 namespace boost {
18 
19 #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
20 template<class T, class U>
exchange(T & t,const U & u)21 inline T exchange(T& t, const U& u)
22 {
23     T v = t;
24     t = u;
25     return v;
26 }
27 #else
28 #if BOOST_WORKAROUND(BOOST_MSVC, < 1800)
29 template<class T, class U>
30 inline T exchange(T& t, U&& u)
31 {
32     T v = std::move(t);
33     t = std::forward<U>(u);
34     return v;
35 }
36 #else
37 template<class T, class U = T>
38 BOOST_CXX14_CONSTEXPR inline T exchange(T& t, U&& u)
39 {
40     T v = std::move(t);
41     t = std::forward<U>(u);
42     return v;
43 }
44 #endif
45 #endif
46 
47 } /* boost */
48 
49 #endif
50