mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2025-08-03 12:49:50 +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
|
@ -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…
Add table
Add a link
Reference in a new issue