mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-23 21:25:49 +00:00
fix swap
This commit is contained in:
parent
4f5c2787d7
commit
18b388c89f
1 changed files with 13 additions and 3 deletions
|
@ -10,12 +10,22 @@
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <type_traits>
|
||||||
#include <sprout/config.hpp>
|
#include <sprout/config.hpp>
|
||||||
|
#include <sprout/utility/move.hpp>
|
||||||
|
#include <sprout/type_traits/enabler_if.hpp>
|
||||||
|
|
||||||
namespace sprout_swap_detail {
|
namespace sprout_swap_detail {
|
||||||
using std::swap;
|
using std::swap;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T, typename sprout::enabler_if<std::is_scalar<T>::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<typename T, typename sprout::enabler_if<!std::is_scalar<T>::value>::type = sprout::enabler>
|
||||||
inline SPROUT_CXX14_CONSTEXPR void
|
inline SPROUT_CXX14_CONSTEXPR void
|
||||||
swap_impl(T& a, T& b)
|
swap_impl(T& a, T& b)
|
||||||
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(swap(a, b)))
|
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(swap(a, b)))
|
||||||
|
@ -25,10 +35,10 @@ namespace sprout_swap_detail {
|
||||||
template<typename T, std::size_t N>
|
template<typename T, std::size_t N>
|
||||||
inline SPROUT_CXX14_CONSTEXPR void
|
inline SPROUT_CXX14_CONSTEXPR void
|
||||||
swap_impl(T (& a)[N], T (& b)[N])
|
swap_impl(T (& a)[N], T (& b)[N])
|
||||||
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(swap(*a, *b)))
|
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout_swap_detail::swap_impl(*a, *b)))
|
||||||
{
|
{
|
||||||
for (std::size_t i = 0; i < N; ++i) {
|
for (std::size_t i = 0; i < N; ++i) {
|
||||||
swap(a[i], b[i]);
|
sprout_swap_detail::swap_impl(a[i], b[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace sprout_swap_detail
|
} // namespace sprout_swap_detail
|
||||||
|
|
Loading…
Reference in a new issue