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

add conversion to atd classes

This commit is contained in:
bolero-MURAKAMI 2016-02-21 16:49:14 +09:00
parent 5bf0907974
commit 60362f5419
3 changed files with 29 additions and 2 deletions

View file

@ -70,7 +70,9 @@ namespace sprout {
private: private:
template<sprout::index_t... Indexes> template<sprout::index_t... Indexes>
SPROUT_CONSTEXPR std::array<T, N> SPROUT_CONSTEXPR std::array<T, N>
to_std_array(sprout::index_tuple<Indexes...>) const { to_std_array(sprout::index_tuple<Indexes...>) const
SPROUT_NOEXCEPT_IF(sprout::is_nothrow_copy_constructible<typename std::remove_cv<T>::type>::value)
{
return std::array<T, N>{{elems[Indexes]...}}; return std::array<T, N>{{elems[Indexes]...}};
} }
public: public:
@ -265,7 +267,9 @@ namespace sprout {
} }
#endif #endif
SPROUT_CONSTEXPR operator std::array<T, N>() const { SPROUT_CONSTEXPR operator std::array<T, N>() const
SPROUT_NOEXCEPT_IF(sprout::is_nothrow_copy_constructible<typename std::remove_cv<T>::type>::value)
{
return to_std_array(sprout::make_index_tuple<N>::make()); return to_std_array(sprout::make_index_tuple<N>::make());
} }
}; };

View file

@ -22,6 +22,7 @@
#include <sprout/utility/pack.hpp> #include <sprout/utility/pack.hpp>
#include <sprout/utility/pair/pair_fwd.hpp> #include <sprout/utility/pair/pair_fwd.hpp>
#include <sprout/type_traits/integral_constant.hpp> #include <sprout/type_traits/integral_constant.hpp>
#include <sprout/type_traits/is_nothrow_copy_constructible.hpp>
#include <sprout/type_traits/is_convert_constructible.hpp> #include <sprout/type_traits/is_convert_constructible.hpp>
#include <sprout/type_traits/enabler_if.hpp> #include <sprout/type_traits/enabler_if.hpp>
#include <sprout/tpp/algorithm/all_of.hpp> #include <sprout/tpp/algorithm/all_of.hpp>
@ -298,6 +299,11 @@ namespace sprout {
typedef typename std::decay<Tuple>::type type; typedef typename std::decay<Tuple>::type type;
sprout::eat((sprout::eat(base_type::template get<Indexes>(*this) = sprout::move(type::template get<Indexes>(SPROUT_FORWARD(Tuple, t)))), 0)...); sprout::eat((sprout::eat(base_type::template get<Indexes>(*this) = sprout::move(type::template get<Indexes>(SPROUT_FORWARD(Tuple, t)))), 0)...);
} }
template<sprout::index_t... Indexes>
SPROUT_CONSTEXPR std::tuple<Types...>
to_std_tuple(sprout::index_tuple<Indexes...>) {
return std::tuple<Types...>(base_type::template get<Indexes>(*this)...);
}
public: public:
// tuple construction // tuple construction
SPROUT_CONSTEXPR tuple() SPROUT_CONSTEXPR tuple()
@ -462,6 +468,12 @@ namespace sprout {
{ {
swap_impl(other, index_tuple_type()); swap_impl(other, index_tuple_type());
} }
SPROUT_EXPLICIT_CONVERSION SPROUT_CONSTEXPR operator std::tuple<Types...>() const
SPROUT_NOEXCEPT_IF(sprout::tpp::all_of<sprout::is_nothrow_copy_constructible<Types>...>::value)
{
return to_std_tuple(index_tuple_type());;
}
}; };
template<> template<>
class tuple<> { class tuple<> {
@ -489,6 +501,10 @@ namespace sprout {
SPROUT_CONSTEXPR tuple(sprout::tuples::flexibly_construct_t, sprout::pair<UType1, UType2>&&) SPROUT_NOEXCEPT {} SPROUT_CONSTEXPR tuple(sprout::tuples::flexibly_construct_t, sprout::pair<UType1, UType2>&&) SPROUT_NOEXCEPT {}
// tuple swap // tuple swap
SPROUT_CXX14_CONSTEXPR void swap(tuple&) SPROUT_NOEXCEPT {} SPROUT_CXX14_CONSTEXPR void swap(tuple&) SPROUT_NOEXCEPT {}
SPROUT_CONSTEXPR operator std::tuple<>() const SPROUT_NOEXCEPT {
return std::tuple<>();;
}
}; };
// //

View file

@ -12,6 +12,7 @@
#include <type_traits> #include <type_traits>
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/index_tuple/metafunction.hpp> #include <sprout/index_tuple/metafunction.hpp>
#include <sprout/type_traits/is_nothrow_copy_constructible.hpp>
#include <sprout/utility/forward.hpp> #include <sprout/utility/forward.hpp>
#include <sprout/utility/swap.hpp> #include <sprout/utility/swap.hpp>
#include <sprout/utility/pair/pair_fwd.hpp> #include <sprout/utility/pair/pair_fwd.hpp>
@ -162,6 +163,12 @@ namespace sprout {
sprout::swap(first, other.first); sprout::swap(first, other.first);
sprout::swap(second, other.second); sprout::swap(second, other.second);
} }
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);
}
}; };
// //