Workaround MSVC10 and MSVC11 for exchange

This commit is contained in:
Glen Fernandes
2018-07-08 10:52:35 -04:00
parent 2cd4753a02
commit 630ab2aae4

View File

@ -10,12 +10,45 @@ Distributed under the Boost Software License, Version 1.0.
#include <boost/config.hpp>
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
#include <boost/config/workaround.hpp>
#include <utility>
#endif
namespace boost {
namespace detail {
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
template<class T>
struct exchange_type {
typedef T type;
};
} /* detail */
#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
template<class T>
inline T exchange(T& t, const typename detail::exchange_type<T>::type& u)
{
T v = t;
t = u;
return v;
}
#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)
{
@ -23,23 +56,6 @@ BOOST_CXX14_CONSTEXPR inline T exchange(T& t, U&& u)
t = std::forward<U>(u);
return v;
}
#else
namespace detail {
template<class T>
struct exchanger {
typedef T type;
};
} /* detail */
template<class T>
inline T exchange(T& t, const typename detail::exchanger<T>::type& u)
{
T v = t;
t = u;
return v;
}
#endif
} /* boost */