mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2024-11-12 21:09:01 +00:00
[sprout.tuple] support C++14 constexpr
This commit is contained in:
parent
63ae5babd0
commit
3f4a24289e
1 changed files with 31 additions and 27 deletions
|
@ -110,7 +110,7 @@ namespace sprout {
|
|||
template<std::size_t, typename...>
|
||||
friend class sprout::tuples::detail::tuple_impl;
|
||||
protected:
|
||||
void swap(tuple_impl&) SPROUT_NOEXCEPT {}
|
||||
SPROUT_CXX14_CONSTEXPR void swap(tuple_impl&) SPROUT_NOEXCEPT {}
|
||||
public:
|
||||
tuple_impl() = default;
|
||||
template<typename... UTypes>
|
||||
|
@ -121,14 +121,18 @@ namespace sprout {
|
|||
SPROUT_CONSTEXPR tuple_impl(tuple_impl<Index, UTypes...> const&) SPROUT_NOEXCEPT {}
|
||||
template<typename... UTypes>
|
||||
SPROUT_CONSTEXPR tuple_impl(tuple_impl<Index, UTypes...>&&) SPROUT_NOEXCEPT {}
|
||||
tuple_impl& operator=(tuple_impl const&) = default;
|
||||
tuple_impl& operator=(tuple_impl&& t) = default;
|
||||
template<typename... UTypes>
|
||||
tuple_impl& operator=(sprout::tuples::detail::tuple_impl<Index, UTypes...> const&) SPROUT_NOEXCEPT {
|
||||
SPROUT_CXX14_CONSTEXPR tuple_impl& operator=(tuple_impl const&) SPROUT_NOEXCEPT {
|
||||
return *this;
|
||||
}
|
||||
SPROUT_CXX14_CONSTEXPR tuple_impl& operator=(tuple_impl&& t) SPROUT_NOEXCEPT {
|
||||
return *this;
|
||||
}
|
||||
template<typename... UTypes>
|
||||
tuple_impl& operator=(sprout::tuples::detail::tuple_impl<Index, UTypes...>&&) SPROUT_NOEXCEPT {
|
||||
SPROUT_CXX14_CONSTEXPR tuple_impl& operator=(sprout::tuples::detail::tuple_impl<Index, UTypes...> const&) SPROUT_NOEXCEPT {
|
||||
return *this;
|
||||
}
|
||||
template<typename... UTypes>
|
||||
SPROUT_CXX14_CONSTEXPR tuple_impl& operator=(sprout::tuples::detail::tuple_impl<Index, UTypes...>&&) SPROUT_NOEXCEPT {
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
@ -159,7 +163,7 @@ namespace sprout {
|
|||
return t;
|
||||
}
|
||||
public:
|
||||
void swap(tuple_impl& t)
|
||||
SPROUT_CXX14_CONSTEXPR void swap(tuple_impl& t)
|
||||
SPROUT_NOEXCEPT_EXPR(
|
||||
SPROUT_NOEXCEPT_EXPR(sprout::swap(head(std::declval<tuple_impl&>()), head(t)))
|
||||
&& SPROUT_NOEXCEPT_EXPR(std::declval<inherited_type&>().swap(tail(t)))
|
||||
|
@ -182,9 +186,9 @@ namespace sprout {
|
|||
: inherited_type(sprout::forward<UTail>(tail)...)
|
||||
, base_type(sprout::forward<UHead>(h))
|
||||
{}
|
||||
SPROUT_CONSTEXPR tuple_impl(tuple_impl const&) = default;
|
||||
tuple_impl(tuple_impl const&) = default;
|
||||
#if defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ == 8 && __GNUC_PATCHLEVEL__ <= 1))
|
||||
SPROUT_CONSTEXPR tuple_impl(tuple_impl&&) = default;
|
||||
tuple_impl(tuple_impl&&) = default;
|
||||
#else
|
||||
SPROUT_CONSTEXPR tuple_impl(tuple_impl&& t)
|
||||
SPROUT_NOEXCEPT_EXPR(std::is_nothrow_move_constructible<Head>::value && std::is_nothrow_move_constructible<inherited_type>::value)
|
||||
|
@ -210,12 +214,12 @@ namespace sprout {
|
|||
: inherited_type()
|
||||
, base_type()
|
||||
{}
|
||||
tuple_impl& operator=(tuple_impl const& t) {
|
||||
SPROUT_CXX14_CONSTEXPR tuple_impl& operator=(tuple_impl const& t) {
|
||||
head(*this) = head(t);
|
||||
tail(*this) = tail(t);
|
||||
return *this;
|
||||
}
|
||||
tuple_impl& operator=(tuple_impl&& t)
|
||||
SPROUT_CXX14_CONSTEXPR tuple_impl& operator=(tuple_impl&& t)
|
||||
SPROUT_NOEXCEPT_EXPR(std::is_nothrow_move_assignable<Head>::value && std::is_nothrow_move_assignable<inherited_type>::value)
|
||||
{
|
||||
head(*this) = sprout::forward<Head>(head(t));
|
||||
|
@ -223,22 +227,22 @@ namespace sprout {
|
|||
return *this;
|
||||
}
|
||||
template<typename... UTypes>
|
||||
tuple_impl& operator=(sprout::tuples::detail::tuple_impl<Index, UTypes...> const& t) {
|
||||
SPROUT_CXX14_CONSTEXPR tuple_impl& operator=(sprout::tuples::detail::tuple_impl<Index, UTypes...> const& t) {
|
||||
head(*this) = sprout::tuples::detail::tuple_impl<Index, UTypes...>::head(t);
|
||||
tail(*this) = sprout::tuples::detail::tuple_impl<Index, UTypes...>::tail(t);
|
||||
return *this;
|
||||
}
|
||||
template<typename UHead, typename... UTail>
|
||||
tuple_impl& operator=(sprout::tuples::detail::tuple_impl<Index, UHead, UTail...>&& t) {
|
||||
SPROUT_CXX14_CONSTEXPR tuple_impl& operator=(sprout::tuples::detail::tuple_impl<Index, UHead, UTail...>&& t) {
|
||||
head(*this) = sprout::forward<UHead>(sprout::tuples::detail::tuple_impl<Index, UHead, UTail...>::head(t));
|
||||
tail(*this) = sprout::move(sprout::tuples::detail::tuple_impl<Index, UHead, UTail...>::tail(t));
|
||||
return *this;
|
||||
}
|
||||
tuple_impl& operator=(sprout::tuples::detail::tuple_impl<Index> const&) {
|
||||
SPROUT_CXX14_CONSTEXPR tuple_impl& operator=(sprout::tuples::detail::tuple_impl<Index> const&) {
|
||||
*this = sprout::move(tuple_impl());
|
||||
return *this;
|
||||
}
|
||||
tuple_impl& operator=(sprout::tuples::detail::tuple_impl<Index>&&) {
|
||||
SPROUT_CXX14_CONSTEXPR tuple_impl& operator=(sprout::tuples::detail::tuple_impl<Index>&&) {
|
||||
*this = sprout::move(tuple_impl());
|
||||
return *this;
|
||||
}
|
||||
|
@ -315,8 +319,8 @@ namespace sprout {
|
|||
explicit SPROUT_CONSTEXPR tuple(UTypes&&... elements)
|
||||
: impl_type(sprout::forward<UTypes>(elements)...)
|
||||
{}
|
||||
SPROUT_CONSTEXPR tuple(tuple const&) = default;
|
||||
SPROUT_CONSTEXPR tuple(tuple&&) = default;
|
||||
tuple(tuple const&) = default;
|
||||
tuple(tuple&&) = default;
|
||||
template<
|
||||
typename... UTypes,
|
||||
typename = typename std::enable_if<
|
||||
|
@ -392,11 +396,11 @@ namespace sprout {
|
|||
>
|
||||
SPROUT_CONSTEXPR tuple(sprout::tuples::flexibly_construct_t, sprout::pair<UType1, UType2>&& t);
|
||||
// tuple assignment
|
||||
tuple& operator=(tuple const& rhs) {
|
||||
SPROUT_CXX14_CONSTEXPR tuple& operator=(tuple const& rhs) {
|
||||
static_cast<impl_type&>(*this) = rhs;
|
||||
return *this;
|
||||
}
|
||||
tuple& operator=(tuple&& rhs)
|
||||
SPROUT_CXX14_CONSTEXPR tuple& operator=(tuple&& rhs)
|
||||
SPROUT_NOEXCEPT_EXPR(sprout::tpp::all_of<std::is_nothrow_move_assignable<Types>...>::value)
|
||||
{
|
||||
static_cast<impl_type&>(*this) = sprout::move(rhs);
|
||||
|
@ -408,7 +412,7 @@ namespace sprout {
|
|||
sizeof...(Types) == sizeof...(UTypes) && sprout::tpp::all_of<std::is_assignable<Types&, UTypes const&>...>::value
|
||||
>::type
|
||||
>
|
||||
tuple& operator=(sprout::tuples::tuple<UTypes...> const& rhs) {
|
||||
SPROUT_CXX14_CONSTEXPR tuple& operator=(sprout::tuples::tuple<UTypes...> const& rhs) {
|
||||
static_cast<impl_type&>(*this) = rhs;
|
||||
return *this;
|
||||
}
|
||||
|
@ -418,12 +422,12 @@ namespace sprout {
|
|||
sizeof...(Types) == sizeof...(UTypes) && sprout::tpp::all_of<std::is_assignable<Types&, UTypes&&>...>::value
|
||||
>::type
|
||||
>
|
||||
tuple& operator=(sprout::tuples::tuple<UTypes...>&& rhs) {
|
||||
SPROUT_CXX14_CONSTEXPR tuple& operator=(sprout::tuples::tuple<UTypes...>&& rhs) {
|
||||
static_cast<impl_type&>(*this) = sprout::move(rhs);
|
||||
return *this;
|
||||
}
|
||||
// tuple swap
|
||||
void swap(tuple& other)
|
||||
SPROUT_CXX14_CONSTEXPR void swap(tuple& other)
|
||||
SPROUT_NOEXCEPT_EXPR(sprout::tpp::all_of_c<SPROUT_NOEXCEPT_EXPR_OR_DEFAULT(sprout::swap(std::declval<Types&>(), std::declval<Types&>()), false)...>::value)
|
||||
{
|
||||
impl_type::swap(other);
|
||||
|
@ -433,9 +437,9 @@ namespace sprout {
|
|||
class tuple<> {
|
||||
public:
|
||||
// tuple construction
|
||||
SPROUT_CONSTEXPR tuple() = default;
|
||||
SPROUT_CONSTEXPR tuple(tuple const&) = default;
|
||||
SPROUT_CONSTEXPR tuple(tuple&&) = default;
|
||||
tuple() = default;
|
||||
tuple(tuple const&) = default;
|
||||
tuple(tuple&&) = default;
|
||||
template<typename... UTypes>
|
||||
explicit SPROUT_CONSTEXPR tuple(sprout::tuples::flexibly_construct_t, UTypes&&...) {}
|
||||
template<typename... UTypes>
|
||||
|
@ -447,14 +451,14 @@ namespace sprout {
|
|||
template<typename UType1, typename UType2>
|
||||
SPROUT_CONSTEXPR tuple(sprout::tuples::flexibly_construct_t, sprout::pair<UType1, UType2>&&) {}
|
||||
// tuple swap
|
||||
void swap(tuple&) SPROUT_NOEXCEPT {}
|
||||
SPROUT_CXX14_CONSTEXPR void swap(tuple&) SPROUT_NOEXCEPT {}
|
||||
};
|
||||
|
||||
//
|
||||
// swap
|
||||
//
|
||||
template<typename... Types>
|
||||
inline void
|
||||
inline SPROUT_CXX14_CONSTEXPR void
|
||||
swap(sprout::tuples::tuple<Types...>& lhs, sprout::tuples::tuple<Types...>& rhs)
|
||||
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs)))
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue