1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2025-08-03 12:49:50 +00:00

add constexpr algorithm C++14 version: move, move_backward, swap_ranges, iter_swap

This commit is contained in:
bolero-MURAKAMI 2013-10-15 14:01:34 +09:00
parent d5c84b07c9
commit a3427d375f
23 changed files with 430 additions and 47 deletions

View file

@ -8,6 +8,7 @@
#ifndef SPROUT_UTILITY_SWAP_HPP
#define SPROUT_UTILITY_SWAP_HPP
#include <cstddef>
#include <utility>
#include <sprout/config.hpp>
@ -15,20 +16,29 @@ namespace sprout_swap_detail {
using std::swap;
template<typename T>
inline void
inline SPROUT_CXX14_CONSTEXPR void
swap_impl(T& a, T& b)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(swap(a, b)))
{
return swap(a, b);
swap(a, b);
}
template<typename T, std::size_t N>
inline SPROUT_CXX14_CONSTEXPR void
swap_impl(T (& a)[N], T (& b)[N])
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(swap(*a, *b)))
{
for (std::size_t i = 0; i < N; ++i) {
swap(a[i], b[i]);
}
}
} // namespace sprout_swap_detail
namespace sprout {
//
// swap
// 20.2.2 swap
//
template<typename T1, typename T2>
inline void
inline SPROUT_CXX14_CONSTEXPR void
swap(T1& lhs, T2& rhs)
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout_swap_detail::swap_impl(lhs, rhs)))
{