From 60362f5419335b6198fc049fee05f7beeba312ae Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Sun, 21 Feb 2016 16:49:14 +0900 Subject: [PATCH] add conversion to atd classes --- sprout/array/array.hpp | 8 ++++++-- sprout/tuple/tuple/tuple_decl.hpp | 16 ++++++++++++++++ sprout/utility/pair/pair_decl.hpp | 7 +++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/sprout/array/array.hpp b/sprout/array/array.hpp index 04063fc9..25e2f2c8 100644 --- a/sprout/array/array.hpp +++ b/sprout/array/array.hpp @@ -70,7 +70,9 @@ namespace sprout { private: template SPROUT_CONSTEXPR std::array - to_std_array(sprout::index_tuple) const { + to_std_array(sprout::index_tuple) const + SPROUT_NOEXCEPT_IF(sprout::is_nothrow_copy_constructible::type>::value) + { return std::array{{elems[Indexes]...}}; } public: @@ -265,7 +267,9 @@ namespace sprout { } #endif - SPROUT_CONSTEXPR operator std::array() const { + SPROUT_CONSTEXPR operator std::array() const + SPROUT_NOEXCEPT_IF(sprout::is_nothrow_copy_constructible::type>::value) + { return to_std_array(sprout::make_index_tuple::make()); } }; diff --git a/sprout/tuple/tuple/tuple_decl.hpp b/sprout/tuple/tuple/tuple_decl.hpp index 851a4012..66151dae 100644 --- a/sprout/tuple/tuple/tuple_decl.hpp +++ b/sprout/tuple/tuple/tuple_decl.hpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -298,6 +299,11 @@ namespace sprout { typedef typename std::decay::type type; sprout::eat((sprout::eat(base_type::template get(*this) = sprout::move(type::template get(SPROUT_FORWARD(Tuple, t)))), 0)...); } + template + SPROUT_CONSTEXPR std::tuple + to_std_tuple(sprout::index_tuple) { + return std::tuple(base_type::template get(*this)...); + } public: // tuple construction SPROUT_CONSTEXPR tuple() @@ -462,6 +468,12 @@ namespace sprout { { swap_impl(other, index_tuple_type()); } + + SPROUT_EXPLICIT_CONVERSION SPROUT_CONSTEXPR operator std::tuple() const + SPROUT_NOEXCEPT_IF(sprout::tpp::all_of...>::value) + { + return to_std_tuple(index_tuple_type());; + } }; template<> class tuple<> { @@ -489,6 +501,10 @@ namespace sprout { SPROUT_CONSTEXPR tuple(sprout::tuples::flexibly_construct_t, sprout::pair&&) SPROUT_NOEXCEPT {} // tuple swap SPROUT_CXX14_CONSTEXPR void swap(tuple&) SPROUT_NOEXCEPT {} + + SPROUT_CONSTEXPR operator std::tuple<>() const SPROUT_NOEXCEPT { + return std::tuple<>();; + } }; // diff --git a/sprout/utility/pair/pair_decl.hpp b/sprout/utility/pair/pair_decl.hpp index b7fa3374..8949337c 100644 --- a/sprout/utility/pair/pair_decl.hpp +++ b/sprout/utility/pair/pair_decl.hpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -162,6 +163,12 @@ namespace sprout { sprout::swap(first, other.first); sprout::swap(second, other.second); } + + SPROUT_EXPLICIT_CONVERSION SPROUT_CONSTEXPR operator std::pair() const + SPROUT_NOEXCEPT_IF(sprout::is_nothrow_copy_constructible::value && sprout::is_nothrow_copy_constructible::value) + { + return std::pair(first, second); + } }; //