mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-23 21:25:49 +00:00
add tuple construction (from pair)
This commit is contained in:
parent
2e8b85e90c
commit
f905d1f02a
9 changed files with 685 additions and 447 deletions
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/tuple/tuple/tuple_fwd.hpp>
|
||||
#include <sprout/tuple/tuple/tuple_decl.hpp>
|
||||
#include <sprout/tuple/tuple/tuple.hpp>
|
||||
#include <sprout/tuple/tuple/comparison.hpp>
|
||||
#include <sprout/tuple/tuple/get.hpp>
|
||||
|
|
|
@ -1,328 +1,149 @@
|
|||
#ifndef SPROUT_TUPLE_TUPLE_TUPLE_HPP
|
||||
#define SPROUT_TUPLE_TUPLE_TUPLE_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <utility>
|
||||
#include <type_traits>
|
||||
#include <tuple>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/utility/move.hpp>
|
||||
#include <sprout/utility/swap.hpp>
|
||||
#include <sprout/utility/pair/pair_decl.hpp>
|
||||
#include <sprout/type_traits/is_convert_constructible.hpp>
|
||||
#include <sprout/tpp/algorithm/all_of.hpp>
|
||||
#include <sprout/tuple/tuple/tuple_fwd.hpp>
|
||||
#include <sprout/tuple/tuple/tuple_decl.hpp>
|
||||
#include <sprout/tuple/tuple/flexibly_construct.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace tuples {
|
||||
namespace detail {
|
||||
template<std::size_t Index, typename Head, bool IsEmpty>
|
||||
class head_base;
|
||||
// EBO disabled
|
||||
// template<std::size_t Index, typename Head>
|
||||
// class head_base<Index, Head, true>
|
||||
// : public Head
|
||||
// {
|
||||
// public:
|
||||
// static SPROUT_CONSTEXPR Head& head(head_base& t) SPROUT_NOEXCEPT {
|
||||
// return t;
|
||||
// }
|
||||
// static SPROUT_CONSTEXPR Head const& head(head_base const& t) SPROUT_NOEXCEPT {
|
||||
// return t;
|
||||
// }
|
||||
// public:
|
||||
// SPROUT_CONSTEXPR head_base()
|
||||
// : Head()
|
||||
// {}
|
||||
// SPROUT_CONSTEXPR head_base(Head const& v)
|
||||
// : Head(v)
|
||||
// {}
|
||||
// template<typename UHead>
|
||||
// SPROUT_CONSTEXPR head_base(UHead&& v)
|
||||
// : Head(sprout::forward<UHead>(v))
|
||||
// {}
|
||||
// };
|
||||
template<std::size_t Index, typename Head>
|
||||
class head_base<Index, Head, true> {
|
||||
public:
|
||||
static SPROUT_CONSTEXPR Head& head(head_base& t) SPROUT_NOEXCEPT {
|
||||
return t.head_;
|
||||
}
|
||||
static SPROUT_CONSTEXPR Head const& head(head_base const& t) SPROUT_NOEXCEPT {
|
||||
return t.head_;
|
||||
}
|
||||
private:
|
||||
Head head_;
|
||||
public:
|
||||
SPROUT_CONSTEXPR head_base()
|
||||
: head_()
|
||||
{}
|
||||
SPROUT_CONSTEXPR head_base(Head const& v)
|
||||
: head_(v)
|
||||
{}
|
||||
template<typename UHead>
|
||||
SPROUT_CONSTEXPR head_base(UHead&& v)
|
||||
: head_(sprout::forward<UHead>(v))
|
||||
{}
|
||||
};
|
||||
template<std::size_t Index, typename Head>
|
||||
class head_base<Index, Head, false> {
|
||||
public:
|
||||
static SPROUT_CONSTEXPR Head& head(head_base& t) SPROUT_NOEXCEPT {
|
||||
return t.head_;
|
||||
}
|
||||
static SPROUT_CONSTEXPR Head const& head(head_base const& t) SPROUT_NOEXCEPT {
|
||||
return t.head_;
|
||||
}
|
||||
private:
|
||||
Head head_;
|
||||
public:
|
||||
SPROUT_CONSTEXPR head_base()
|
||||
: head_()
|
||||
{}
|
||||
SPROUT_CONSTEXPR head_base(Head const& v)
|
||||
: head_(v)
|
||||
{}
|
||||
template<typename UHead>
|
||||
SPROUT_CONSTEXPR head_base(UHead&& v)
|
||||
: head_(sprout::forward<UHead>(v))
|
||||
{}
|
||||
};
|
||||
|
||||
template<std::size_t Index, typename... Types>
|
||||
class tuple_impl;
|
||||
template<std::size_t Index>
|
||||
class tuple_impl<Index> {
|
||||
public:
|
||||
template<typename...>
|
||||
friend class tuple;
|
||||
template<std::size_t, typename...>
|
||||
friend class sprout::tuples::detail::tuple_impl;
|
||||
protected:
|
||||
void swap(tuple_impl&) SPROUT_NOEXCEPT {}
|
||||
public:
|
||||
tuple_impl() = default;
|
||||
template<typename... UTypes>
|
||||
explicit SPROUT_CONSTEXPR tuple_impl(UTypes&&... args) SPROUT_NOEXCEPT {}
|
||||
SPROUT_CONSTEXPR tuple_impl(tuple_impl const&) = default;
|
||||
SPROUT_CONSTEXPR tuple_impl(tuple_impl&&) = default;
|
||||
template<typename... UTypes>
|
||||
SPROUT_CONSTEXPR tuple_impl(tuple_impl<Index, UTypes...> const& t) SPROUT_NOEXCEPT {}
|
||||
template<typename... UTypes>
|
||||
SPROUT_CONSTEXPR tuple_impl(tuple_impl<Index, UTypes...>&& t) 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 {
|
||||
return *this;
|
||||
}
|
||||
template<typename... UTypes>
|
||||
tuple_impl& operator=(sprout::tuples::detail::tuple_impl<Index, UTypes...>&&) SPROUT_NOEXCEPT {
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
template<std::size_t Index, typename Head, typename... Tail>
|
||||
class tuple_impl<Index, Head, Tail...>
|
||||
: public sprout::tuples::detail::tuple_impl<Index + 1, Tail...>
|
||||
, private sprout::tuples::detail::head_base<Index, Head, std::is_empty<Head>::value>
|
||||
{
|
||||
public:
|
||||
template<typename...>
|
||||
friend class tuple;
|
||||
template<std::size_t, typename...>
|
||||
friend class sprout::tuples::detail::tuple_impl;
|
||||
public:
|
||||
typedef sprout::tuples::detail::tuple_impl<Index + 1, Tail...> inherited_type;
|
||||
typedef sprout::tuples::detail::head_base<Index, Head, std::is_empty<Head>::value> base_type;
|
||||
public:
|
||||
static SPROUT_CONSTEXPR Head& head(tuple_impl& t) SPROUT_NOEXCEPT {
|
||||
return base_type::head(t);
|
||||
}
|
||||
static SPROUT_CONSTEXPR Head const& head(tuple_impl const& t) SPROUT_NOEXCEPT {
|
||||
return base_type::head(t);
|
||||
}
|
||||
static SPROUT_CONSTEXPR inherited_type& tail(tuple_impl& t) SPROUT_NOEXCEPT {
|
||||
return t;
|
||||
}
|
||||
static SPROUT_CONSTEXPR inherited_type const& tail(tuple_impl const& t) SPROUT_NOEXCEPT {
|
||||
return t;
|
||||
}
|
||||
public:
|
||||
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)))
|
||||
)
|
||||
{
|
||||
sprout::swap(head(*this), head(t));
|
||||
inherited_type::swap(tail(t));
|
||||
}
|
||||
public:
|
||||
SPROUT_CONSTEXPR tuple_impl()
|
||||
: inherited_type()
|
||||
, base_type()
|
||||
{}
|
||||
explicit SPROUT_CONSTEXPR tuple_impl(Head const& h, Tail const&... tail)
|
||||
: inherited_type(tail...)
|
||||
, base_type(h)
|
||||
{}
|
||||
template<typename UHead, typename... UTail>
|
||||
explicit SPROUT_CONSTEXPR tuple_impl(UHead&& h, UTail&&... tail)
|
||||
: inherited_type(sprout::forward<UTail>(tail)...)
|
||||
, base_type(sprout::forward<UHead>(h))
|
||||
{}
|
||||
SPROUT_CONSTEXPR tuple_impl(tuple_impl const&) = default;
|
||||
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)
|
||||
: inherited_type(sprout::move(tail(t)))
|
||||
, base_type(sprout::forward<Head>(head(t)))
|
||||
{}
|
||||
template<typename... UTypes>
|
||||
SPROUT_CONSTEXPR tuple_impl(tuple_impl<Index, UTypes...> const& t)
|
||||
: inherited_type(sprout::tuples::detail::tuple_impl<Index, UTypes...>::tail(t))
|
||||
, base_type(sprout::tuples::detail::tuple_impl<Index, UTypes...>::head(t))
|
||||
{}
|
||||
template<typename UHead, typename... UTail>
|
||||
SPROUT_CONSTEXPR tuple_impl(tuple_impl<Index, UHead, UTail...>&& t)
|
||||
: inherited_type(sprout::move(sprout::tuples::detail::tuple_impl<Index, UHead, UTail...>::tail(t)))
|
||||
, base_type(sprout::forward<UHead>(sprout::tuples::detail::tuple_impl<Index, UHead, UTail...>::head(t)))
|
||||
{}
|
||||
SPROUT_CONSTEXPR tuple_impl(tuple_impl<Index> const& t)
|
||||
: inherited_type()
|
||||
, base_type()
|
||||
{}
|
||||
SPROUT_CONSTEXPR tuple_impl(tuple_impl<Index>&& t)
|
||||
: inherited_type()
|
||||
, base_type()
|
||||
{}
|
||||
tuple_impl& operator=(tuple_impl const& t) {
|
||||
head(*this) = head(t);
|
||||
tail(*this) = tail(t);
|
||||
return *this;
|
||||
}
|
||||
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));
|
||||
tail(*this) = sprout::move(tail(t));
|
||||
return *this;
|
||||
}
|
||||
template<typename... UTypes>
|
||||
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) {
|
||||
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& t) {
|
||||
*this = sprout::move(tuple_impl());
|
||||
return *this;
|
||||
}
|
||||
tuple_impl& operator=(sprout::tuples::detail::tuple_impl<Index>&& t) {
|
||||
*this = sprout::move(tuple_impl());
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
} // namespace detail
|
||||
//
|
||||
// tuple
|
||||
//
|
||||
// tuple construction
|
||||
template<typename... Types>
|
||||
inline SPROUT_CONSTEXPR sprout::tuples::tuple<Types...>::tuple()
|
||||
: impl_type()
|
||||
{}
|
||||
template<typename... Types>
|
||||
inline SPROUT_CONSTEXPR sprout::tuples::tuple<Types...>::tuple(Types const&... elements)
|
||||
: impl_type(elements...)
|
||||
{}
|
||||
template<typename... Types>
|
||||
template<
|
||||
typename... UTypes,
|
||||
typename
|
||||
>
|
||||
inline SPROUT_CONSTEXPR sprout::tuples::tuple<Types...>::tuple(UTypes&&... elements)
|
||||
: impl_type(sprout::forward<UTypes>(elements)...)
|
||||
{}
|
||||
template<typename... Types>
|
||||
inline SPROUT_CONSTEXPR sprout::tuples::tuple<Types...>::tuple(tuple const&) = default;
|
||||
template<typename... Types>
|
||||
inline SPROUT_CONSTEXPR sprout::tuples::tuple<Types...>::tuple(tuple&&) = default;
|
||||
template<typename... Types>
|
||||
template<
|
||||
typename... UTypes,
|
||||
typename
|
||||
>
|
||||
inline SPROUT_CONSTEXPR sprout::tuples::tuple<Types...>::tuple(sprout::tuples::tuple<UTypes...> const& t)
|
||||
: impl_type(static_cast<sprout::tuples::detail::tuple_impl<0, UTypes...> const&>(t))
|
||||
{}
|
||||
template<typename... Types>
|
||||
template<
|
||||
typename... UTypes,
|
||||
typename
|
||||
>
|
||||
inline SPROUT_CONSTEXPR sprout::tuples::tuple<Types...>::tuple(sprout::tuples::tuple<UTypes...>&& t)
|
||||
: impl_type(static_cast<sprout::tuples::detail::tuple_impl<0, UTypes...>&&>(t))
|
||||
{}
|
||||
template<typename... Types>
|
||||
template<
|
||||
typename... UTypes,
|
||||
typename
|
||||
>
|
||||
inline SPROUT_CONSTEXPR sprout::tuples::tuple<Types...>::tuple(sprout::pair<UTypes...> const& t)
|
||||
: impl_type(t.first, t.second)
|
||||
{}
|
||||
template<typename... Types>
|
||||
template<
|
||||
typename... UTypes,
|
||||
typename
|
||||
>
|
||||
inline SPROUT_CONSTEXPR sprout::tuples::tuple<Types...>::tuple(sprout::pair<UTypes...>&& t)
|
||||
: impl_type(sprout::move(t.first), sprout::move(t.second))
|
||||
{}
|
||||
template<typename... Types>
|
||||
template<typename... UTypes>
|
||||
inline SPROUT_CONSTEXPR sprout::tuples::tuple<Types...>::tuple(sprout::tuples::flexibly_construct_t, UTypes&&... elements)
|
||||
: impl_type(sprout::forward<UTypes>(elements)...)
|
||||
{}
|
||||
template<typename... Types>
|
||||
template<typename... UTypes>
|
||||
inline SPROUT_CONSTEXPR sprout::tuples::tuple<Types...>::tuple(sprout::tuples::flexibly_construct_t, sprout::tuples::tuple<UTypes...> const& t)
|
||||
: impl_type(static_cast<sprout::tuples::detail::tuple_impl<0, UTypes...> const&>(t))
|
||||
{}
|
||||
template<typename... Types>
|
||||
template<typename... UTypes>
|
||||
inline SPROUT_CONSTEXPR sprout::tuples::tuple<Types...>::tuple(sprout::tuples::flexibly_construct_t, sprout::tuples::tuple<UTypes...>&& t)
|
||||
: impl_type(static_cast<sprout::tuples::detail::tuple_impl<0, UTypes...>&&>(t))
|
||||
{}
|
||||
template<typename... Types>
|
||||
template<typename... UTypes>
|
||||
inline SPROUT_CONSTEXPR sprout::tuples::tuple<Types...>::tuple(sprout::tuples::flexibly_construct_t, sprout::pair<UTypes...> const& t)
|
||||
: impl_type(t.first, t.second)
|
||||
{}
|
||||
template<typename... Types>
|
||||
template<typename... UTypes>
|
||||
inline SPROUT_CONSTEXPR sprout::tuples::tuple<Types...>::tuple(sprout::tuples::flexibly_construct_t, sprout::pair<UTypes...>&& t)
|
||||
: impl_type(sprout::move(t.first), sprout::move(t.second))
|
||||
{}
|
||||
// tuple assignment
|
||||
template<typename... Types>
|
||||
sprout::tuples::tuple<Types...>& sprout::tuples::tuple<Types...>::operator=(tuple const& rhs) {
|
||||
static_cast<impl_type&>(*this) = rhs;
|
||||
return *this;
|
||||
}
|
||||
template<typename... Types>
|
||||
sprout::tuples::tuple<Types...>& sprout::tuples::tuple<Types...>::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);
|
||||
return *this;
|
||||
}
|
||||
template<typename... Types>
|
||||
template<typename... UTypes>
|
||||
sprout::tuples::tuple<Types...>& sprout::tuples::tuple<Types...>::operator=(sprout::tuples::tuple<UTypes...> const& rhs) {
|
||||
static_cast<impl_type&>(*this) = rhs;
|
||||
return *this;
|
||||
}
|
||||
template<typename... Types>
|
||||
template<typename... UTypes>
|
||||
sprout::tuples::tuple<Types...>& sprout::tuples::tuple<Types...>::operator=(sprout::tuples::tuple<UTypes...>&& rhs) {
|
||||
static_cast<impl_type&>(*this) = sprout::move(rhs);
|
||||
return *this;
|
||||
}
|
||||
// tuple swap
|
||||
template<typename... Types>
|
||||
inline void sprout::tuples::tuple<Types...>::swap(tuple& other)
|
||||
SPROUT_NOEXCEPT_EXPR(has_nothrow_swap::value)
|
||||
{
|
||||
impl_type::swap(other);
|
||||
}
|
||||
|
||||
//
|
||||
// tuple
|
||||
//
|
||||
template<typename... Types>
|
||||
class tuple
|
||||
: public sprout::tuples::detail::tuple_impl<0, Types...>
|
||||
{
|
||||
private:
|
||||
typedef sprout::tuples::detail::tuple_impl<0, Types...> inherited_type;
|
||||
public:
|
||||
// tuple construction
|
||||
SPROUT_CONSTEXPR tuple()
|
||||
: inherited_type()
|
||||
{}
|
||||
explicit SPROUT_CONSTEXPR tuple(Types const&... elements)
|
||||
: inherited_type(elements...)
|
||||
{}
|
||||
template<
|
||||
typename... UTypes,
|
||||
typename = typename std::enable_if<
|
||||
sizeof...(Types) == sizeof...(UTypes) && sprout::tpp::all_of<sprout::is_convert_constructible<Types, UTypes&&>...>::value
|
||||
>::type
|
||||
>
|
||||
explicit SPROUT_CONSTEXPR tuple(UTypes&&... elements)
|
||||
: inherited_type(sprout::forward<UTypes>(elements)...)
|
||||
{}
|
||||
template<typename... UTypes>
|
||||
explicit SPROUT_CONSTEXPR tuple(sprout::tuples::flexibly_construct_t, UTypes&&... elements)
|
||||
: inherited_type(sprout::forward<UTypes>(elements)...)
|
||||
{}
|
||||
SPROUT_CONSTEXPR tuple(tuple const&) = default;
|
||||
SPROUT_CONSTEXPR tuple(tuple&&) = default;
|
||||
template<
|
||||
typename... UTypes,
|
||||
typename = typename std::enable_if<
|
||||
sizeof...(Types) == sizeof...(UTypes) && sprout::tpp::all_of<sprout::is_convert_constructible<Types, UTypes const&>...>::value
|
||||
>::type
|
||||
>
|
||||
SPROUT_CONSTEXPR tuple(sprout::tuples::tuple<UTypes...> const& t)
|
||||
: inherited_type(static_cast<sprout::tuples::detail::tuple_impl<0, UTypes...> const&>(t))
|
||||
{}
|
||||
template<
|
||||
typename... UTypes,
|
||||
typename = typename std::enable_if<
|
||||
sizeof...(Types) == sizeof...(UTypes) && sprout::tpp::all_of<sprout::is_convert_constructible<Types, UTypes&&>...>::value
|
||||
>::type
|
||||
>
|
||||
SPROUT_CONSTEXPR tuple(sprout::tuples::tuple<UTypes...>&& t)
|
||||
: inherited_type(static_cast<sprout::tuples::detail::tuple_impl<0, UTypes...>&&>(t))
|
||||
{}
|
||||
template<typename... UTypes>
|
||||
SPROUT_CONSTEXPR tuple(sprout::tuples::flexibly_construct_t, sprout::tuples::tuple<UTypes...> const& t)
|
||||
: inherited_type(static_cast<sprout::tuples::detail::tuple_impl<0, UTypes...> const&>(t))
|
||||
{}
|
||||
template<typename... UTypes>
|
||||
SPROUT_CONSTEXPR tuple(sprout::tuples::flexibly_construct_t, sprout::tuples::tuple<UTypes...>&& t)
|
||||
: inherited_type(static_cast<sprout::tuples::detail::tuple_impl<0, UTypes...>&&>(t))
|
||||
{}
|
||||
// tuple assignment
|
||||
tuple& operator=(tuple const& rhs) {
|
||||
static_cast<inherited_type&>(*this) = rhs;
|
||||
return *this;
|
||||
}
|
||||
tuple& operator=(tuple&& rhs)
|
||||
SPROUT_NOEXCEPT_EXPR(std::is_nothrow_move_assignable<inherited_type>::value)
|
||||
{
|
||||
static_cast<inherited_type&>(*this) = sprout::move(rhs);
|
||||
return *this;
|
||||
}
|
||||
template<typename... UTypes>
|
||||
tuple& operator=(sprout::tuples::tuple<UTypes...> const& rhs) {
|
||||
static_cast<inherited_type&>(*this) = rhs;
|
||||
return *this;
|
||||
}
|
||||
template<typename... UTypes>
|
||||
tuple& operator=(sprout::tuples::tuple<UTypes...>&& rhs) {
|
||||
static_cast<inherited_type&>(*this) = sprout::move(rhs);
|
||||
return *this;
|
||||
}
|
||||
// tuple swap
|
||||
void swap(tuple& other)
|
||||
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::declval<inherited_type&>().swap(other)))
|
||||
{
|
||||
inherited_type::swap(other);
|
||||
}
|
||||
};
|
||||
template<>
|
||||
class tuple<> {
|
||||
public:
|
||||
// tuple swap
|
||||
void swap(tuple&) SPROUT_NOEXCEPT {}
|
||||
};
|
||||
// tuple construction
|
||||
inline SPROUT_CONSTEXPR sprout::tuples::tuple<>::tuple() = default;
|
||||
inline SPROUT_CONSTEXPR sprout::tuples::tuple<>::tuple(tuple const&) = default;
|
||||
inline SPROUT_CONSTEXPR sprout::tuples::tuple<>::tuple(tuple&&) = default;
|
||||
template<typename... UTypes>
|
||||
inline SPROUT_CONSTEXPR sprout::tuples::tuple<>::tuple(sprout::tuples::flexibly_construct_t, UTypes&&... elements) {}
|
||||
template<typename... UTypes>
|
||||
inline SPROUT_CONSTEXPR sprout::tuples::tuple<>::tuple(sprout::tuples::flexibly_construct_t, sprout::tuples::tuple<UTypes...> const& t) {}
|
||||
template<typename... UTypes>
|
||||
inline SPROUT_CONSTEXPR sprout::tuples::tuple<>::tuple(sprout::tuples::flexibly_construct_t, sprout::tuples::tuple<UTypes...>&& t) {}
|
||||
// tuple swap
|
||||
inline void sprout::tuples::tuple<>::swap(tuple&) SPROUT_NOEXCEPT {}
|
||||
|
||||
//
|
||||
// swap
|
||||
|
@ -334,49 +155,7 @@ namespace sprout {
|
|||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
template<std::size_t I, typename T>
|
||||
struct tuple_element_impl;
|
||||
template<typename Head, typename... Tail>
|
||||
struct tuple_element_impl<0, sprout::tuples::tuple<Head, Tail...> > {
|
||||
public:
|
||||
typedef Head type;
|
||||
};
|
||||
template<std::size_t I, typename Head, typename... Tail>
|
||||
struct tuple_element_impl<I, sprout::tuples::tuple<Head, Tail...> >
|
||||
: public sprout::tuples::detail::tuple_element_impl<I - 1, sprout::tuples::tuple<Tail...> >
|
||||
{};
|
||||
} // namespace detail
|
||||
} // namespace tuples
|
||||
|
||||
using sprout::tuples::tuple;
|
||||
using sprout::tuples::swap;
|
||||
} // namespace sprout
|
||||
|
||||
namespace std {
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic push
|
||||
# pragma clang diagnostic ignored "-Wmismatched-tags"
|
||||
#endif
|
||||
//
|
||||
// tuple_size
|
||||
//
|
||||
template<typename... Types>
|
||||
struct tuple_size<sprout::tuples::tuple<Types...> >
|
||||
: public std::integral_constant<std::size_t, sizeof...(Types)>
|
||||
{};
|
||||
|
||||
//
|
||||
// tuple_element
|
||||
//
|
||||
template<std::size_t I, typename... Types>
|
||||
struct tuple_element<I, sprout::tuples::tuple<Types...> >
|
||||
: public sprout::tuples::detail::tuple_element_impl<I, sprout::tuples::tuple<Types...> >
|
||||
{};
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic pop
|
||||
#endif
|
||||
} // namespace std
|
||||
|
||||
#endif // #ifndef SPROUT_TUPLE_TUPLE_TUPLE_HPP
|
||||
|
|
382
sprout/tuple/tuple/tuple_decl.hpp
Normal file
382
sprout/tuple/tuple/tuple_decl.hpp
Normal file
|
@ -0,0 +1,382 @@
|
|||
#ifndef SPROUT_TUPLE_TUPLE_TUPLE_DECL_HPP
|
||||
#define SPROUT_TUPLE_TUPLE_TUPLE_DECL_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <utility>
|
||||
#include <type_traits>
|
||||
#include <tuple>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/utility/move.hpp>
|
||||
#include <sprout/utility/swap.hpp>
|
||||
#include <sprout/utility/pair/pair_fwd.hpp>
|
||||
#include <sprout/type_traits/is_convert_constructible.hpp>
|
||||
#include <sprout/tpp/algorithm/all_of.hpp>
|
||||
#include <sprout/tuple/tuple/tuple_fwd.hpp>
|
||||
#include <sprout/tuple/tuple/flexibly_construct.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace tuples {
|
||||
namespace detail {
|
||||
template<std::size_t Index, typename Head, bool IsEmpty>
|
||||
class head_base;
|
||||
// EBO disabled
|
||||
// template<std::size_t Index, typename Head>
|
||||
// class head_base<Index, Head, true>
|
||||
// : public Head
|
||||
// {
|
||||
// public:
|
||||
// static SPROUT_CONSTEXPR Head& head(head_base& t) SPROUT_NOEXCEPT {
|
||||
// return t;
|
||||
// }
|
||||
// static SPROUT_CONSTEXPR Head const& head(head_base const& t) SPROUT_NOEXCEPT {
|
||||
// return t;
|
||||
// }
|
||||
// public:
|
||||
// SPROUT_CONSTEXPR head_base()
|
||||
// : Head()
|
||||
// {}
|
||||
// SPROUT_CONSTEXPR head_base(Head const& v)
|
||||
// : Head(v)
|
||||
// {}
|
||||
// template<typename UHead>
|
||||
// SPROUT_CONSTEXPR head_base(UHead&& v)
|
||||
// : Head(sprout::forward<UHead>(v))
|
||||
// {}
|
||||
// };
|
||||
template<std::size_t Index, typename Head>
|
||||
class head_base<Index, Head, true> {
|
||||
public:
|
||||
static SPROUT_CONSTEXPR Head& head(head_base& t) SPROUT_NOEXCEPT {
|
||||
return t.head_;
|
||||
}
|
||||
static SPROUT_CONSTEXPR Head const& head(head_base const& t) SPROUT_NOEXCEPT {
|
||||
return t.head_;
|
||||
}
|
||||
private:
|
||||
Head head_;
|
||||
public:
|
||||
SPROUT_CONSTEXPR head_base()
|
||||
: head_()
|
||||
{}
|
||||
SPROUT_CONSTEXPR head_base(Head const& v)
|
||||
: head_(v)
|
||||
{}
|
||||
template<typename UHead>
|
||||
SPROUT_CONSTEXPR head_base(UHead&& v)
|
||||
: head_(sprout::forward<UHead>(v))
|
||||
{}
|
||||
};
|
||||
template<std::size_t Index, typename Head>
|
||||
class head_base<Index, Head, false> {
|
||||
public:
|
||||
static SPROUT_CONSTEXPR Head& head(head_base& t) SPROUT_NOEXCEPT {
|
||||
return t.head_;
|
||||
}
|
||||
static SPROUT_CONSTEXPR Head const& head(head_base const& t) SPROUT_NOEXCEPT {
|
||||
return t.head_;
|
||||
}
|
||||
private:
|
||||
Head head_;
|
||||
public:
|
||||
SPROUT_CONSTEXPR head_base()
|
||||
: head_()
|
||||
{}
|
||||
SPROUT_CONSTEXPR head_base(Head const& v)
|
||||
: head_(v)
|
||||
{}
|
||||
template<typename UHead>
|
||||
SPROUT_CONSTEXPR head_base(UHead&& v)
|
||||
: head_(sprout::forward<UHead>(v))
|
||||
{}
|
||||
};
|
||||
|
||||
template<std::size_t Index, typename... Types>
|
||||
class tuple_impl;
|
||||
template<std::size_t Index>
|
||||
class tuple_impl<Index> {
|
||||
public:
|
||||
template<typename...>
|
||||
friend class tuple;
|
||||
template<std::size_t, typename...>
|
||||
friend class sprout::tuples::detail::tuple_impl;
|
||||
protected:
|
||||
void swap(tuple_impl&) SPROUT_NOEXCEPT {}
|
||||
public:
|
||||
tuple_impl() = default;
|
||||
template<typename... UTypes>
|
||||
explicit SPROUT_CONSTEXPR tuple_impl(UTypes&&... args) SPROUT_NOEXCEPT {}
|
||||
SPROUT_CONSTEXPR tuple_impl(tuple_impl const&) = default;
|
||||
SPROUT_CONSTEXPR tuple_impl(tuple_impl&&) = default;
|
||||
template<typename... UTypes>
|
||||
SPROUT_CONSTEXPR tuple_impl(tuple_impl<Index, UTypes...> const& t) SPROUT_NOEXCEPT {}
|
||||
template<typename... UTypes>
|
||||
SPROUT_CONSTEXPR tuple_impl(tuple_impl<Index, UTypes...>&& t) 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 {
|
||||
return *this;
|
||||
}
|
||||
template<typename... UTypes>
|
||||
tuple_impl& operator=(sprout::tuples::detail::tuple_impl<Index, UTypes...>&&) SPROUT_NOEXCEPT {
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
template<std::size_t Index, typename Head, typename... Tail>
|
||||
class tuple_impl<Index, Head, Tail...>
|
||||
: public sprout::tuples::detail::tuple_impl<Index + 1, Tail...>
|
||||
, private sprout::tuples::detail::head_base<Index, Head, std::is_empty<Head>::value>
|
||||
{
|
||||
public:
|
||||
template<typename...>
|
||||
friend class tuple;
|
||||
template<std::size_t, typename...>
|
||||
friend class sprout::tuples::detail::tuple_impl;
|
||||
public:
|
||||
typedef sprout::tuples::detail::tuple_impl<Index + 1, Tail...> inherited_type;
|
||||
typedef sprout::tuples::detail::head_base<Index, Head, std::is_empty<Head>::value> base_type;
|
||||
public:
|
||||
static SPROUT_CONSTEXPR Head& head(tuple_impl& t) SPROUT_NOEXCEPT {
|
||||
return base_type::head(t);
|
||||
}
|
||||
static SPROUT_CONSTEXPR Head const& head(tuple_impl const& t) SPROUT_NOEXCEPT {
|
||||
return base_type::head(t);
|
||||
}
|
||||
static SPROUT_CONSTEXPR inherited_type& tail(tuple_impl& t) SPROUT_NOEXCEPT {
|
||||
return t;
|
||||
}
|
||||
static SPROUT_CONSTEXPR inherited_type const& tail(tuple_impl const& t) SPROUT_NOEXCEPT {
|
||||
return t;
|
||||
}
|
||||
public:
|
||||
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)))
|
||||
)
|
||||
{
|
||||
sprout::swap(head(*this), head(t));
|
||||
inherited_type::swap(tail(t));
|
||||
}
|
||||
public:
|
||||
SPROUT_CONSTEXPR tuple_impl()
|
||||
: inherited_type()
|
||||
, base_type()
|
||||
{}
|
||||
explicit SPROUT_CONSTEXPR tuple_impl(Head const& h, Tail const&... tail)
|
||||
: inherited_type(tail...)
|
||||
, base_type(h)
|
||||
{}
|
||||
template<typename UHead, typename... UTail>
|
||||
explicit SPROUT_CONSTEXPR tuple_impl(UHead&& h, UTail&&... tail)
|
||||
: inherited_type(sprout::forward<UTail>(tail)...)
|
||||
, base_type(sprout::forward<UHead>(h))
|
||||
{}
|
||||
SPROUT_CONSTEXPR tuple_impl(tuple_impl const&) = default;
|
||||
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)
|
||||
: inherited_type(sprout::move(tail(t)))
|
||||
, base_type(sprout::forward<Head>(head(t)))
|
||||
{}
|
||||
template<typename... UTypes>
|
||||
SPROUT_CONSTEXPR tuple_impl(tuple_impl<Index, UTypes...> const& t)
|
||||
: inherited_type(sprout::tuples::detail::tuple_impl<Index, UTypes...>::tail(t))
|
||||
, base_type(sprout::tuples::detail::tuple_impl<Index, UTypes...>::head(t))
|
||||
{}
|
||||
template<typename UHead, typename... UTail>
|
||||
SPROUT_CONSTEXPR tuple_impl(tuple_impl<Index, UHead, UTail...>&& t)
|
||||
: inherited_type(sprout::move(sprout::tuples::detail::tuple_impl<Index, UHead, UTail...>::tail(t)))
|
||||
, base_type(sprout::forward<UHead>(sprout::tuples::detail::tuple_impl<Index, UHead, UTail...>::head(t)))
|
||||
{}
|
||||
SPROUT_CONSTEXPR tuple_impl(tuple_impl<Index> const& t)
|
||||
: inherited_type()
|
||||
, base_type()
|
||||
{}
|
||||
SPROUT_CONSTEXPR tuple_impl(tuple_impl<Index>&& t)
|
||||
: inherited_type()
|
||||
, base_type()
|
||||
{}
|
||||
tuple_impl& operator=(tuple_impl const& t) {
|
||||
head(*this) = head(t);
|
||||
tail(*this) = tail(t);
|
||||
return *this;
|
||||
}
|
||||
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));
|
||||
tail(*this) = sprout::move(tail(t));
|
||||
return *this;
|
||||
}
|
||||
template<typename... UTypes>
|
||||
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) {
|
||||
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& t) {
|
||||
*this = sprout::move(tuple_impl());
|
||||
return *this;
|
||||
}
|
||||
tuple_impl& operator=(sprout::tuples::detail::tuple_impl<Index>&& t) {
|
||||
*this = sprout::move(tuple_impl());
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
//
|
||||
// tuple
|
||||
//
|
||||
template<typename... Types>
|
||||
class tuple
|
||||
: public sprout::tuples::detail::tuple_impl<0, Types...>
|
||||
{
|
||||
private:
|
||||
typedef sprout::tuples::detail::tuple_impl<0, Types...> impl_type;
|
||||
public:
|
||||
struct has_nothrow_swap
|
||||
: public sprout::tpp::all_of_c<
|
||||
SPROUT_NOEXCEPT_EXPR_OR_DEFAULT(sprout::swap(std::declval<Types&>(), std::declval<Types&>()), false)...
|
||||
>
|
||||
{};
|
||||
public:
|
||||
// tuple construction
|
||||
SPROUT_CONSTEXPR tuple();
|
||||
explicit SPROUT_CONSTEXPR tuple(Types const&... elements);
|
||||
template<
|
||||
typename... UTypes,
|
||||
typename = typename std::enable_if<
|
||||
sizeof...(Types) == sizeof...(UTypes) && sprout::tpp::all_of<sprout::is_convert_constructible<Types, UTypes&&>...>::value
|
||||
>::type
|
||||
>
|
||||
explicit SPROUT_CONSTEXPR tuple(UTypes&&... elements);
|
||||
SPROUT_CONSTEXPR tuple(tuple const&);
|
||||
SPROUT_CONSTEXPR tuple(tuple&&);
|
||||
template<
|
||||
typename... UTypes,
|
||||
typename = typename std::enable_if<
|
||||
sizeof...(Types) == sizeof...(UTypes) && sprout::tpp::all_of<sprout::is_convert_constructible<Types, UTypes const&>...>::value
|
||||
>::type
|
||||
>
|
||||
SPROUT_CONSTEXPR tuple(sprout::tuples::tuple<UTypes...> const& t);
|
||||
template<
|
||||
typename... UTypes,
|
||||
typename = typename std::enable_if<
|
||||
sizeof...(Types) == sizeof...(UTypes) && sprout::tpp::all_of<sprout::is_convert_constructible<Types, UTypes&&>...>::value
|
||||
>::type
|
||||
>
|
||||
SPROUT_CONSTEXPR tuple(sprout::tuples::tuple<UTypes...>&& t);
|
||||
template<
|
||||
typename... UTypes,
|
||||
typename = typename std::enable_if<
|
||||
sizeof...(Types) == 2 && sprout::tpp::all_of<sprout::is_convert_constructible<Types, UTypes&&>...>::value
|
||||
>::type
|
||||
>
|
||||
SPROUT_CONSTEXPR tuple(sprout::pair<UTypes...> const& t);
|
||||
template<
|
||||
typename... UTypes,
|
||||
typename = typename std::enable_if<
|
||||
sizeof...(Types) == 2 && sprout::tpp::all_of<sprout::is_convert_constructible<Types, UTypes&&>...>::value
|
||||
>::type
|
||||
>
|
||||
SPROUT_CONSTEXPR tuple(sprout::pair<UTypes...>&& t);
|
||||
template<typename... UTypes>
|
||||
explicit SPROUT_CONSTEXPR tuple(sprout::tuples::flexibly_construct_t, UTypes&&... elements);
|
||||
template<typename... UTypes>
|
||||
SPROUT_CONSTEXPR tuple(sprout::tuples::flexibly_construct_t, sprout::tuples::tuple<UTypes...> const& t);
|
||||
template<typename... UTypes>
|
||||
SPROUT_CONSTEXPR tuple(sprout::tuples::flexibly_construct_t, sprout::tuples::tuple<UTypes...>&& t);
|
||||
template<typename... UTypes>
|
||||
SPROUT_CONSTEXPR tuple(sprout::tuples::flexibly_construct_t, sprout::pair<UTypes...> const& t);
|
||||
template<typename... UTypes>
|
||||
SPROUT_CONSTEXPR tuple(sprout::tuples::flexibly_construct_t, sprout::pair<UTypes...>&& t);
|
||||
// tuple assignment
|
||||
tuple& operator=(tuple const& rhs);
|
||||
tuple& operator=(tuple&& rhs)
|
||||
SPROUT_NOEXCEPT_EXPR(sprout::tpp::all_of<std::is_nothrow_move_assignable<Types>...>::value);
|
||||
template<typename... UTypes>
|
||||
tuple& operator=(sprout::tuples::tuple<UTypes...> const& rhs);
|
||||
template<typename... UTypes>
|
||||
tuple& operator=(sprout::tuples::tuple<UTypes...>&& rhs);
|
||||
// tuple swap
|
||||
void swap(tuple& other)
|
||||
SPROUT_NOEXCEPT_EXPR(has_nothrow_swap::value);
|
||||
};
|
||||
template<>
|
||||
class tuple<> {
|
||||
public:
|
||||
// tuple construction
|
||||
SPROUT_CONSTEXPR tuple();
|
||||
SPROUT_CONSTEXPR tuple(tuple const&);
|
||||
SPROUT_CONSTEXPR tuple(tuple&&);
|
||||
template<typename... UTypes>
|
||||
explicit SPROUT_CONSTEXPR tuple(sprout::tuples::flexibly_construct_t, UTypes&&... elements);
|
||||
template<typename... UTypes>
|
||||
SPROUT_CONSTEXPR tuple(sprout::tuples::flexibly_construct_t, sprout::tuples::tuple<UTypes...> const& t);
|
||||
template<typename... UTypes>
|
||||
SPROUT_CONSTEXPR tuple(sprout::tuples::flexibly_construct_t, sprout::tuples::tuple<UTypes...>&& t);
|
||||
// tuple swap
|
||||
void swap(tuple&) SPROUT_NOEXCEPT;
|
||||
};
|
||||
|
||||
//
|
||||
// swap
|
||||
//
|
||||
template<typename... Types>
|
||||
inline void
|
||||
swap(sprout::tuples::tuple<Types...>& lhs, sprout::tuples::tuple<Types...>& rhs)
|
||||
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs)));
|
||||
|
||||
namespace detail {
|
||||
template<std::size_t I, typename T>
|
||||
struct tuple_element_impl;
|
||||
template<typename Head, typename... Tail>
|
||||
struct tuple_element_impl<0, sprout::tuples::tuple<Head, Tail...> > {
|
||||
public:
|
||||
typedef Head type;
|
||||
};
|
||||
template<std::size_t I, typename Head, typename... Tail>
|
||||
struct tuple_element_impl<I, sprout::tuples::tuple<Head, Tail...> >
|
||||
: public sprout::tuples::detail::tuple_element_impl<I - 1, sprout::tuples::tuple<Tail...> >
|
||||
{};
|
||||
} // namespace detail
|
||||
} // namespace tuples
|
||||
|
||||
using sprout::tuples::tuple;
|
||||
using sprout::tuples::swap;
|
||||
} // namespace sprout
|
||||
|
||||
namespace std {
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic push
|
||||
# pragma clang diagnostic ignored "-Wmismatched-tags"
|
||||
#endif
|
||||
//
|
||||
// tuple_size
|
||||
//
|
||||
template<typename... Types>
|
||||
struct tuple_size<sprout::tuples::tuple<Types...> >
|
||||
: public std::integral_constant<std::size_t, sizeof...(Types)>
|
||||
{};
|
||||
|
||||
//
|
||||
// tuple_element
|
||||
//
|
||||
template<std::size_t I, typename... Types>
|
||||
struct tuple_element<I, sprout::tuples::tuple<Types...> >
|
||||
: public sprout::tuples::detail::tuple_element_impl<I, sprout::tuples::tuple<Types...> >
|
||||
{};
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic pop
|
||||
#endif
|
||||
} // namespace std
|
||||
|
||||
#endif // #ifndef SPROUT_TUPLE_TUPLE_TUPLE_DECL_HPP
|
|
@ -5,6 +5,9 @@
|
|||
|
||||
namespace sprout {
|
||||
namespace tuples {
|
||||
//
|
||||
// tuple
|
||||
//
|
||||
template<typename... Types>
|
||||
class tuple;
|
||||
} // namespace tuples
|
||||
|
|
|
@ -21,10 +21,7 @@ namespace sprout {
|
|||
public:
|
||||
typedef Head type;
|
||||
};
|
||||
template<
|
||||
std::size_t N,
|
||||
typename... Args
|
||||
>
|
||||
template<std::size_t N, typename... Args>
|
||||
struct tppack_at_impl
|
||||
: public sprout::detail::tppack_at_impl_1<N, Args...>
|
||||
{
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
#define SPROUT_UTILITY_PAIR_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/utility/pair/pair_fwd.hpp>
|
||||
#include <sprout/utility/pair/pair_decl.hpp>
|
||||
#include <sprout/utility/pair/pair.hpp>
|
||||
#include <sprout/utility/pair/comparison.hpp>
|
||||
#include <sprout/utility/pair/tuple.hpp>
|
||||
|
|
|
@ -1,121 +1,113 @@
|
|||
#ifndef SPROUT_UTILITY_PAIR_PAIR_HPP
|
||||
#define SPROUT_UTILITY_PAIR_PAIR_HPP
|
||||
|
||||
#include <utility>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/index_tuple.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/utility/move.hpp>
|
||||
#include <sprout/utility/swap.hpp>
|
||||
#include <sprout/utility/pair/pair_decl.hpp>
|
||||
#include <sprout/tuple/tuple/tuple.hpp>
|
||||
#include <sprout/tuple/tuple/get.hpp>
|
||||
|
||||
namespace sprout {
|
||||
// Copyright (C) 2011 RiSK (sscrisk)
|
||||
|
||||
//
|
||||
// pair
|
||||
//
|
||||
template <typename T1, typename T2>
|
||||
struct pair {
|
||||
public:
|
||||
typedef T1 first_type;
|
||||
typedef T2 second_type;
|
||||
public:
|
||||
T1 first;
|
||||
T2 second;
|
||||
private:
|
||||
template <typename... Args1, typename... Args2, sprout::index_t... Indexes1, sprout::index_t... Indexes2>
|
||||
SPROUT_CONSTEXPR pair(
|
||||
sprout::tuples::tuple<Args1...> first_args,
|
||||
sprout::tuples::tuple<Args2...> second_args,
|
||||
sprout::index_tuple<Indexes1...>,
|
||||
sprout::index_tuple<Indexes2...>
|
||||
)
|
||||
: first(sprout::tuples::get<Indexes1>(first_args)...)
|
||||
, second(sprout::tuples::get<Indexes2>(second_args)...)
|
||||
{}
|
||||
public:
|
||||
pair(pair const&) = default;
|
||||
pair(pair&&) = default;
|
||||
SPROUT_CONSTEXPR pair()
|
||||
: first()
|
||||
, second()
|
||||
{}
|
||||
SPROUT_CONSTEXPR pair(T1 const& x, T2 const& y)
|
||||
: first(x)
|
||||
, second(y)
|
||||
{}
|
||||
template<typename U, typename V>
|
||||
SPROUT_CONSTEXPR pair(U&& x, V&& y)
|
||||
: first(sprout::forward<U>(x))
|
||||
, second(sprout::forward<V>(y))
|
||||
{}
|
||||
template<typename U, typename V>
|
||||
SPROUT_CONSTEXPR pair(sprout::pair<U, V> const& p)
|
||||
: first(p.first)
|
||||
, second(p.second)
|
||||
{}
|
||||
template<typename U, typename V>
|
||||
SPROUT_CONSTEXPR pair(sprout::pair<U, V>&& p)
|
||||
: first(sprout::forward<U>(p.first))
|
||||
, second(sprout::forward<V>(p.second))
|
||||
{}
|
||||
template <typename... Args1, typename... Args2, sprout::index_t... Indexes1, sprout::index_t... Indexes2>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<T1, T2>::pair(
|
||||
sprout::tuples::tuple<Args1...> first_args,
|
||||
sprout::tuples::tuple<Args2...> second_args,
|
||||
sprout::index_tuple<Indexes1...>,
|
||||
sprout::index_tuple<Indexes2...>
|
||||
)
|
||||
: first(sprout::tuples::get<Indexes1>(first_args)...)
|
||||
, second(sprout::tuples::get<Indexes2>(second_args)...)
|
||||
{}
|
||||
template <typename T1, typename T2>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<T1, T2>::pair(pair const&) = default;
|
||||
template <typename T1, typename T2>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<T1, T2>::pair(pair&&) = default;
|
||||
template <typename T1, typename T2>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<T1, T2>::pair()
|
||||
: first()
|
||||
, second()
|
||||
{}
|
||||
template <typename T1, typename T2>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<T1, T2>::pair(T1 const& x, T2 const& y)
|
||||
: first(x)
|
||||
, second(y)
|
||||
{}
|
||||
template <typename T1, typename T2>
|
||||
template<typename U, typename V>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<T1, T2>::pair(U&& x, V&& y)
|
||||
: first(sprout::forward<U>(x))
|
||||
, second(sprout::forward<V>(y))
|
||||
{}
|
||||
template <typename T1, typename T2>
|
||||
template<typename U, typename V>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<T1, T2>::pair(sprout::pair<U, V> const& other)
|
||||
: first(other.first)
|
||||
, second(other.second)
|
||||
{}
|
||||
template <typename T1, typename T2>
|
||||
template<typename U, typename V>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<T1, T2>::pair(sprout::pair<U, V>&& other)
|
||||
: first(sprout::move(other.first))
|
||||
, second(sprout::move(other.second))
|
||||
{}
|
||||
#if SPROUT_USE_DELEGATING_CONSTRUCTORS
|
||||
template <typename... Args1, typename... Args2>
|
||||
SPROUT_CONSTEXPR pair(
|
||||
sprout::tuples::tuple<Args1...> first_args,
|
||||
sprout::tuples::tuple<Args2...> second_args
|
||||
template <typename T1, typename T2>
|
||||
template <typename... Args1, typename... Args2>
|
||||
inline SPROUT_CONSTEXPR sprout::pair<T1, T2>::pair(
|
||||
sprout::tuples::tuple<Args1...> first_args,
|
||||
sprout::tuples::tuple<Args2...> second_args
|
||||
)
|
||||
: pair(
|
||||
first_args,
|
||||
second_args,
|
||||
sprout::index_range<0, sizeof...(Args1)>::make(),
|
||||
sprout::index_range<0, sizeof...(Args2)>::make()
|
||||
)
|
||||
: pair(
|
||||
first_args,
|
||||
second_args,
|
||||
sprout::index_range<0, sizeof...(Args1)>::make(),
|
||||
sprout::index_range<0, sizeof...(Args2)>::make()
|
||||
)
|
||||
{}
|
||||
#else // #if SPROUT_USE_DELEGATING_CONSTRUCTORS
|
||||
template <typename... Args1, typename... Args2>
|
||||
SPROUT_CONSTEXPR pair(
|
||||
sprout::tuples::tuple<Args1...> first_args,
|
||||
sprout::tuples::tuple<Args2...> second_args
|
||||
);
|
||||
{}
|
||||
#endif // #if SPROUT_USE_DELEGATING_CONSTRUCTORS
|
||||
pair& operator=(pair const& p) = default;
|
||||
template<typename U, typename V>
|
||||
pair& operator=(sprout::pair<U, V> const& p) {
|
||||
first = p.first;
|
||||
second = p.second;
|
||||
return *this;
|
||||
}
|
||||
pair& operator=(pair&& p)
|
||||
SPROUT_NOEXCEPT_EXPR(std::is_nothrow_move_assignable<T1>::value && std::is_nothrow_move_assignable<T2>::value)
|
||||
{
|
||||
first = sprout::forward<T1>(p.first);
|
||||
second = std::forward<T2>(p.second);
|
||||
return *this;
|
||||
}
|
||||
template<typename U, typename V>
|
||||
pair& operator=(sprout::pair<U, V>&& p) {
|
||||
first = std::forward<U>(p.first);
|
||||
second = std::forward<V>(p.second);
|
||||
return *this;
|
||||
}
|
||||
void swap(pair& p)
|
||||
SPROUT_NOEXCEPT_EXPR(
|
||||
SPROUT_NOEXCEPT_EXPR(swap(first, p.first))
|
||||
&& SPROUT_NOEXCEPT_EXPR(swap(second, p.second))
|
||||
)
|
||||
{
|
||||
sprout::swap(first, p.first);
|
||||
sprout::swap(second, p.second);
|
||||
}
|
||||
};
|
||||
template <typename T1, typename T2>
|
||||
inline sprout::pair<T1, T2>& sprout::pair<T1, T2>::operator=(pair const& other) = default;
|
||||
template <typename T1, typename T2>
|
||||
template<typename U, typename V>
|
||||
inline sprout::pair<T1, T2>& sprout::pair<T1, T2>::operator=(sprout::pair<U, V> const& other) {
|
||||
first = other.first;
|
||||
second = other.second;
|
||||
return *this;
|
||||
}
|
||||
template <typename T1, typename T2>
|
||||
inline sprout::pair<T1, T2>& sprout::pair<T1, T2>::operator=(pair&& other)
|
||||
SPROUT_NOEXCEPT_EXPR(std::is_nothrow_move_assignable<T1>::value && std::is_nothrow_move_assignable<T2>::value)
|
||||
{
|
||||
first = sprout::move(other.first);
|
||||
second = sprout::move(other.second);
|
||||
return *this;
|
||||
}
|
||||
template <typename T1, typename T2>
|
||||
template<typename U, typename V>
|
||||
inline sprout::pair<T1, T2>& sprout::pair<T1, T2>::operator=(sprout::pair<U, V>&& other) {
|
||||
first = sprout::move(other.first);
|
||||
second = sprout::move(other.second);
|
||||
return *this;
|
||||
}
|
||||
template <typename T1, typename T2>
|
||||
inline void sprout::pair<T1, T2>::swap(pair& other)
|
||||
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::swap(first, other.first)) && SPROUT_NOEXCEPT_EXPR(sprout::swap(second, other.second))) {
|
||||
sprout::swap(first, other.first);
|
||||
sprout::swap(second, other.second);
|
||||
}
|
||||
|
||||
//
|
||||
// swap
|
||||
//
|
||||
template<class T1, class T2>
|
||||
template<typename T1, typename T2>
|
||||
inline void
|
||||
swap(sprout::pair<T1, T2>& lhs, sprout::pair<T1, T2>& rhs)
|
||||
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs)))
|
||||
|
|
68
sprout/utility/pair/pair_decl.hpp
Normal file
68
sprout/utility/pair/pair_decl.hpp
Normal file
|
@ -0,0 +1,68 @@
|
|||
#ifndef SPROUT_UTILITY_PAIR_PAIR_DECL_HPP
|
||||
#define SPROUT_UTILITY_PAIR_PAIR_DECL_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/index_tuple.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/utility/swap.hpp>
|
||||
#include <sprout/utility/pair/pair_fwd.hpp>
|
||||
#include <sprout/tuple/tuple/tuple_fwd.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// pair
|
||||
//
|
||||
template <typename T1, typename T2>
|
||||
struct pair {
|
||||
public:
|
||||
typedef T1 first_type;
|
||||
typedef T2 second_type;
|
||||
public:
|
||||
T1 first;
|
||||
T2 second;
|
||||
private:
|
||||
template <typename... Args1, typename... Args2, sprout::index_t... Indexes1, sprout::index_t... Indexes2>
|
||||
SPROUT_CONSTEXPR pair(
|
||||
sprout::tuples::tuple<Args1...> first_args,
|
||||
sprout::tuples::tuple<Args2...> second_args,
|
||||
sprout::index_tuple<Indexes1...>,
|
||||
sprout::index_tuple<Indexes2...>
|
||||
);
|
||||
public:
|
||||
SPROUT_CONSTEXPR pair(pair const&);
|
||||
SPROUT_CONSTEXPR pair(pair&&);
|
||||
SPROUT_CONSTEXPR pair();
|
||||
SPROUT_CONSTEXPR pair(T1 const& x, T2 const& y);
|
||||
template<typename U, typename V>
|
||||
SPROUT_CONSTEXPR pair(U&& x, V&& y);
|
||||
template<typename U, typename V>
|
||||
SPROUT_CONSTEXPR pair(sprout::pair<U, V> const& other);
|
||||
template<typename U, typename V>
|
||||
SPROUT_CONSTEXPR pair(sprout::pair<U, V>&& other);
|
||||
template <typename... Args1, typename... Args2>
|
||||
SPROUT_CONSTEXPR pair(
|
||||
sprout::tuples::tuple<Args1...> first_args,
|
||||
sprout::tuples::tuple<Args2...> second_args
|
||||
);
|
||||
pair& operator=(pair const& other);
|
||||
template<typename U, typename V>
|
||||
pair& operator=(sprout::pair<U, V> const& other);
|
||||
pair& operator=(pair&& other)
|
||||
SPROUT_NOEXCEPT_EXPR(std::is_nothrow_move_assignable<T1>::value && std::is_nothrow_move_assignable<T2>::value);
|
||||
template<typename U, typename V>
|
||||
pair& operator=(sprout::pair<U, V>&& other);
|
||||
void swap(pair& other)
|
||||
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::swap(first, other.first)) && SPROUT_NOEXCEPT_EXPR(sprout::swap(second, other.second)));
|
||||
};
|
||||
|
||||
//
|
||||
// swap
|
||||
//
|
||||
template<typename T1, typename T2>
|
||||
inline void
|
||||
swap(sprout::pair<T1, T2>& lhs, sprout::pair<T1, T2>& rhs)
|
||||
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs)));
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_UTILITY_PAIR_PAIR_DECL_HPP
|
14
sprout/utility/pair/pair_fwd.hpp
Normal file
14
sprout/utility/pair/pair_fwd.hpp
Normal file
|
@ -0,0 +1,14 @@
|
|||
#ifndef SPROUT_UTILITY_PAIR_PAIR_FWD_HPP
|
||||
#define SPROUT_UTILITY_PAIR_PAIR_FWD_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// pair
|
||||
//
|
||||
template <typename T1, typename T2>
|
||||
struct pair;
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_UTILITY_PAIR_PAIR_FWD_HPP
|
Loading…
Reference in a new issue