2018-07-07 23:13:03 -04:00
|
|
|
/*
|
|
|
|
Copyright 2018 Glen Joseph Fernandes
|
|
|
|
(glenjofe@gmail.com)
|
|
|
|
|
|
|
|
Distributed under the Boost Software License, Version 1.0.
|
|
|
|
(http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
*/
|
|
|
|
#ifndef BOOST_CORE_EXCHANGE_HPP
|
|
|
|
#define BOOST_CORE_EXCHANGE_HPP
|
|
|
|
|
|
|
|
#include <boost/config.hpp>
|
|
|
|
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
2018-07-08 10:52:35 -04:00
|
|
|
#include <boost/config/workaround.hpp>
|
2018-07-07 23:13:03 -04:00
|
|
|
#include <utility>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace boost {
|
|
|
|
namespace detail {
|
|
|
|
|
|
|
|
template<class T>
|
2018-07-08 10:52:35 -04:00
|
|
|
struct exchange_type {
|
2018-07-07 23:13:03 -04:00
|
|
|
typedef T type;
|
|
|
|
};
|
|
|
|
|
|
|
|
} /* detail */
|
|
|
|
|
2018-07-08 10:52:35 -04:00
|
|
|
#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
2018-07-07 23:13:03 -04:00
|
|
|
template<class T>
|
2018-07-08 10:52:35 -04:00
|
|
|
inline T exchange(T& t, const typename detail::exchange_type<T>::type& u)
|
2018-07-07 23:13:03 -04:00
|
|
|
{
|
|
|
|
T v = t;
|
|
|
|
t = u;
|
|
|
|
return v;
|
|
|
|
}
|
2018-07-08 10:52:35 -04:00
|
|
|
#elif BOOST_WORKAROUND(BOOST_MSVC, < 1800)
|
|
|
|
template<class T>
|
|
|
|
inline T exchange(T& t, const typename detail::exchange_type<T>::type& u)
|
|
|
|
{
|
|
|
|
T v = std::move(t);
|
|
|
|
t = u;
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
inline T exchange(T& t, typename detail::exchange_type<T>::type&& u)
|
|
|
|
{
|
|
|
|
T v = std::move(t);
|
|
|
|
t = std::move(u);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
template<class T, class U = T>
|
|
|
|
BOOST_CXX14_CONSTEXPR inline T exchange(T& t, U&& u)
|
|
|
|
{
|
|
|
|
T v = std::move(t);
|
|
|
|
t = std::forward<U>(u);
|
|
|
|
return v;
|
|
|
|
}
|
2018-07-07 23:13:03 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
} /* boost */
|
|
|
|
|
|
|
|
#endif
|