1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2024-11-12 21:09:01 +00:00
Sprout/sprout/utility/pair/pair_decl.hpp

187 lines
5.9 KiB
C++
Raw Normal View History

2013-08-08 09:54:33 +00:00
/*=============================================================================
2016-02-25 09:48:28 +00:00
Copyright (c) 2011-2016 Bolero MURAKAMI
2013-08-08 09:54:33 +00:00
https://github.com/bolero-MURAKAMI/Sprout
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
2013-03-27 08:55:14 +00:00
#ifndef SPROUT_UTILITY_PAIR_PAIR_DECL_HPP
#define SPROUT_UTILITY_PAIR_PAIR_DECL_HPP
2013-03-31 01:09:02 +00:00
#include <utility>
2013-03-27 08:55:14 +00:00
#include <type_traits>
#include <sprout/config.hpp>
2013-04-06 04:06:51 +00:00
#include <sprout/index_tuple/metafunction.hpp>
2016-02-21 07:49:14 +00:00
#include <sprout/type_traits/is_nothrow_copy_constructible.hpp>
2013-03-27 08:55:14 +00:00
#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>
2013-03-27 08:55:14 +00:00
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>
2013-03-27 08:55:14 +00:00
SPROUT_CONSTEXPR pair(
2013-04-05 09:11:56 +00:00
sprout::tuples::tuple<Args1...> first_args, sprout::tuples::tuple<Args2...> second_args,
sprout::index_tuple<Indexes1...>, sprout::index_tuple<Indexes2...>
2013-03-27 08:55:14 +00:00
);
public:
2013-03-31 09:20:59 +00:00
SPROUT_CONSTEXPR pair()
: first()
, second()
{}
2013-10-29 10:15:52 +00:00
pair(pair const&) = default;
pair(pair&&) = default;
2013-03-31 09:20:59 +00:00
SPROUT_CONSTEXPR pair(T1 const& x, T2 const& y)
: first(x)
, second(y)
{}
2013-03-31 01:09:02 +00:00
template<
typename U, typename V,
typename = typename std::enable_if<
std::is_constructible<first_type, U&&>::value && std::is_constructible<second_type, V&&>::value
>::type
>
2013-03-31 09:20:59 +00:00
SPROUT_CONSTEXPR pair(U&& x, V&& y)
: first(SPROUT_FORWARD(U, x))
, second(SPROUT_FORWARD(V, y))
2013-03-31 09:20:59 +00:00
{}
2013-03-31 01:09:02 +00:00
template<
typename U, typename V,
typename = typename std::enable_if<
std::is_constructible<first_type, U const&>::value && std::is_constructible<second_type, V const&>::value
>::type
>
2013-03-31 09:20:59 +00:00
SPROUT_CONSTEXPR pair(sprout::pair<U, V> const& other)
: first(other.first)
, second(other.second)
{}
2013-03-31 01:09:02 +00:00
template<
typename U, typename V,
typename = typename std::enable_if<
std::is_constructible<first_type, U&&>::value && std::is_constructible<second_type, V&&>::value
>::type
>
2013-03-31 09:20:59 +00:00
SPROUT_CONSTEXPR pair(sprout::pair<U, V>&& other)
: first(SPROUT_FORWARD(U, other.first))
, second(SPROUT_FORWARD(V, other.second))
2013-03-31 09:20:59 +00:00
{}
2013-03-31 01:09:02 +00:00
template<
typename... Args1, typename... Args2,
typename = typename std::enable_if<
std::is_constructible<first_type, Args1&&...>::value && std::is_constructible<second_type, Args2&&...>::value
>::type
>
2013-03-27 08:55:14 +00:00
SPROUT_CONSTEXPR pair(
2013-03-31 01:09:02 +00:00
std::piecewise_construct_t,
sprout::tuples::tuple<Args1...> first_args, sprout::tuples::tuple<Args2...> second_args
2013-03-27 08:55:14 +00:00
);
2013-03-31 01:09:02 +00:00
template<
typename U, typename V,
typename = typename std::enable_if<
std::is_constructible<first_type, U const&>::value && std::is_constructible<second_type, V const&>::value
>::type
>
SPROUT_CONSTEXPR pair(sprout::tuples::tuple<U, V> const& other);
template<
typename U, typename V,
typename = typename std::enable_if<
std::is_constructible<first_type, U&&>::value && std::is_constructible<second_type, V&&>::value
>::type
>
SPROUT_CONSTEXPR pair(sprout::tuples::tuple<U, V>&& other);
2013-10-29 10:15:52 +00:00
SPROUT_CXX14_CONSTEXPR pair& operator=(pair const& rhs) {
first = rhs.first;
second = rhs.second;
return *this;
}
SPROUT_CXX14_CONSTEXPR pair& operator=(pair&& rhs)
2014-08-14 13:55:49 +00:00
SPROUT_NOEXCEPT_IF(std::is_nothrow_move_assignable<T1>::value && std::is_nothrow_move_assignable<T2>::value)
2013-03-31 09:20:59 +00:00
{
first = SPROUT_FORWARD(T1, rhs.first);
second = SPROUT_FORWARD(T2, rhs.second);
2013-03-31 09:20:59 +00:00
return *this;
}
2013-03-31 01:09:02 +00:00
template<
typename U, typename V,
typename = typename std::enable_if<
std::is_assignable<first_type&, U const&>::value && std::is_assignable<second_type&, V const&>::value
>::type
>
SPROUT_CXX14_CONSTEXPR pair& operator=(sprout::pair<U, V> const& rhs) {
2013-03-31 09:20:59 +00:00
first = rhs.first;
second = rhs.second;
return *this;
}
2013-03-31 01:09:02 +00:00
template<
typename U, typename V,
typename = typename std::enable_if<
std::is_assignable<first_type&, U&&>::value && std::is_assignable<second_type&, V&&>::value
>::type
>
SPROUT_CXX14_CONSTEXPR pair& operator=(sprout::pair<U, V>&& rhs) {
first = SPROUT_FORWARD(U, rhs.first);
second = SPROUT_FORWARD(V, rhs.second);
2013-03-31 09:20:59 +00:00
return *this;
}
2013-03-31 01:09:02 +00:00
template<
typename U, typename V,
typename = typename std::enable_if<
std::is_assignable<first_type&, U const&>::value && std::is_assignable<second_type&, V const&>::value
>::type
>
SPROUT_CXX14_CONSTEXPR pair& operator=(sprout::tuples::tuple<U, V> const& rhs);
2013-03-31 01:09:02 +00:00
template<
typename U, typename V,
typename = typename std::enable_if<
std::is_assignable<first_type&, U&&>::value && std::is_assignable<second_type&, V&&>::value
>::type
>
2014-08-14 13:55:49 +00:00
SPROUT_CXX14_CONSTEXPR pair&
operator=(sprout::tuples::tuple<U, V>&& rhs);
2013-03-31 01:09:02 +00:00
2014-08-14 13:55:49 +00:00
SPROUT_CXX14_CONSTEXPR void
swap(pair& other)
SPROUT_NOEXCEPT_IF(
SPROUT_NOEXCEPT_EXPR(sprout::swap(first, other.first))
&& SPROUT_NOEXCEPT_EXPR(sprout::swap(second, other.second))
)
{
2013-03-31 09:20:59 +00:00
sprout::swap(first, other.first);
sprout::swap(second, other.second);
}
2016-02-21 07:49:14 +00:00
SPROUT_EXPLICIT_CONVERSION SPROUT_CONSTEXPR operator std::pair<T1, T2>() const
SPROUT_NOEXCEPT_IF(sprout::is_nothrow_copy_constructible<T1>::value && sprout::is_nothrow_copy_constructible<T2>::value)
{
return std::pair<T1, T2>(first, second);
}
2013-03-27 08:55:14 +00:00
};
//
// swap
//
template<typename T1, typename T2>
inline SPROUT_CXX14_CONSTEXPR void
2013-03-27 08:55:14 +00:00
swap(sprout::pair<T1, T2>& lhs, sprout::pair<T1, T2>& rhs)
2014-08-14 13:55:49 +00:00
SPROUT_NOEXCEPT_IF_EXPR(lhs.swap(rhs))
2013-03-31 09:20:59 +00:00
{
lhs.swap(rhs);
}
2013-03-27 08:55:14 +00:00
} // namespace sprout
#endif // #ifndef SPROUT_UTILITY_PAIR_PAIR_DECL_HPP