/*============================================================================= Copyright (c) 2011-2015 Bolero MURAKAMI https://github.com/bolero-MURAKAMI/Sprout Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ #ifndef SPROUT_UTILITY_SWAP_HPP #define SPROUT_UTILITY_SWAP_HPP #include #include #include #include #include #include namespace sprout_swap_detail { using std::swap; template::value>::type = sprout::enabler> inline SPROUT_CXX14_CONSTEXPR void swap_impl(T& a, T& b) SPROUT_NOEXCEPT { T temp = sprout::move(a); a = sprout::move(b); b = sprout::move(temp); } template::value>::type = sprout::enabler> inline SPROUT_CXX14_CONSTEXPR void swap_impl(T& a, T& b) SPROUT_NOEXCEPT_IF_EXPR(swap(a, b)) { swap(a, b); } template inline SPROUT_CXX14_CONSTEXPR void swap_impl(T (& a)[N], T (& b)[N]) SPROUT_NOEXCEPT_IF_EXPR(sprout_swap_detail::swap_impl(*a, *b)) { for (std::size_t i = 0; i < N; ++i) { sprout_swap_detail::swap_impl(a[i], b[i]); } } } // namespace sprout_swap_detail namespace sprout { // // 20.2.2 swap // template inline SPROUT_CXX14_CONSTEXPR void swap(T1& lhs, T2& rhs) SPROUT_NOEXCEPT_IF_EXPR(sprout_swap_detail::swap_impl(lhs, rhs)) { return sprout_swap_detail::swap_impl(lhs, rhs); } } // namespace sprout #endif // #ifndef SPROUT_UTILITY_SWAP_HPP