diff --git a/libs/tuple/test/tuple.cpp b/libs/tuple/test/tuple.cpp index 0c8d9baf..0c52ab8c 100644 --- a/libs/tuple/test/tuple.cpp +++ b/libs/tuple/test/tuple.cpp @@ -219,15 +219,6 @@ namespace testspr { } // tuple_cat - { - typedef sprout::tuples::results::tuple_cat::type concatenated_type; - TESTSPR_BOTH_ASSERT(sprout::tuples::tuple_size::value == 4); - TESTSPR_BOTH_ASSERT((std::is_same::type, int>::value)); - TESTSPR_BOTH_ASSERT((std::is_same::type, double>::value)); - TESTSPR_BOTH_ASSERT((std::is_same::type, int>::value)); - TESTSPR_BOTH_ASSERT((std::is_same::type, double>::value)); - } - { SPROUT_STATIC_CONSTEXPR auto tup3 = sprout::tuples::tuple_cat(tup1, tup2); TESTSPR_BOTH_ASSERT(sprout::tuples::get<0>(tup3) == 1); diff --git a/sprout/tuple/tuple/get.hpp b/sprout/tuple/tuple/get.hpp index 85a27914..3d74039d 100644 --- a/sprout/tuple/tuple/get.hpp +++ b/sprout/tuple/tuple/get.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -81,7 +82,7 @@ namespace sprout_tuple_detail { tuple_get(T&& t) SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::tuple_access_traits::type>::template tuple_get(std::declval())) { - return sprout::tuples::tuple_access_traits::template tuple_get(t); + return sprout::move(sprout::tuples::tuple_access_traits::template tuple_get(t)); } template inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_traits::template lvalue_reference::type diff --git a/sprout/tuple/tuple/make_tuple.hpp b/sprout/tuple/tuple/make_tuple.hpp index e6617b5a..92091695 100644 --- a/sprout/tuple/tuple/make_tuple.hpp +++ b/sprout/tuple/tuple/make_tuple.hpp @@ -12,10 +12,12 @@ #include #include #include +#include #include #include #include -#include +//#include +#include namespace sprout { namespace tuples { @@ -46,121 +48,108 @@ namespace sprout { return sprout::tuples::tuple(args...); } - namespace results { - namespace detail { - template - struct tuple_cat_impl; - template<> - struct tuple_cat_impl<> { - typedef sprout::tuples::tuple<> type; - }; - template - struct tuple_cat_impl { - private: - template - struct make; - template - struct make > { - public: - typedef sprout::tuples::tuple::type...> type; - }; - public: - typedef typename make< - Tuple, typename sprout::tuple_indexes::type - >::type type; - }; - template - struct tuple_cat_impl { - private: - template - struct make; - template - struct make, Tup2, sprout::index_tuple > { - public: - typedef sprout::tuples::tuple< - typename sprout::tuples::tuple_element::type..., - typename sprout::tuples::tuple_element::type... - > type; - }; - public: - typedef typename sprout::tuples::results::detail::tuple_cat_impl< - typename make< - T, typename sprout::tuple_indexes::type, - U, typename sprout::tuple_indexes::type - >::type, - Tuples... - >::type type; - }; - } // namespace detail - // - // tuple_cat - // - template - struct tuple_cat - : public sprout::tuples::results::detail::tuple_cat_impl< - typename std::decay::type... - > - {}; - } // namespace results - - namespace detail { - template - struct tuple_cat_1st_indexes; - template<> - struct tuple_cat_1st_indexes<> { - public: - typedef sprout::index_tuple<> type; - }; - template - struct tuple_cat_1st_indexes - : public sprout::tuple_indexes::type> - {}; - - template - struct tuple_cat_impl; - template - struct tuple_cat_impl > { - public: - template - static SPROUT_CONSTEXPR Result - call(Args&&... args) { - return Result(SPROUT_FORWARD(Args, args)...); - } - }; - template - struct tuple_cat_impl, Head, Tail...> { - public: - template - static SPROUT_CONSTEXPR Result - call(T&& t, Args&&... args) { - return sprout::tuples::detail::tuple_cat_impl< - Result, - typename sprout::tuples::detail::tuple_cat_1st_indexes::type, - Tail... - >::call( - SPROUT_FORWARD(Args, args)..., - sprout::tuples::get(SPROUT_FORWARD(T, t))... - ); - } - }; - } // namespace detail // // tuple_cat // + namespace detail { + template + struct tuple_cat_indexes_impl; + template + struct tuple_cat_indexes_impl, TupleSizes...> { + public: + typedef typename sprout::types::tuple_cat::type...>::type for_pack; + typedef typename sprout::types::tuple_cat::type...>::type for_element; + }; + template + struct tuple_cat_indexes + : public sprout::tuples::detail::tuple_cat_indexes_impl< + typename sprout::make_index_tuple::type, + sprout::tuples::tuple_size::type>::value... + > + {}; + + template + static SPROUT_CONSTEXPR Result + tuple_cat_impl(sprout::index_tuple, sprout::index_tuple, Tuples&&... tuples) { + return Result(sprout::tuples::get(sprout::pack_get(SPROUT_FORWARD(Tuples, tuples)...))...); + }; + } // namespace detail template - inline SPROUT_CONSTEXPR typename sprout::tuples::results::tuple_cat::type + inline SPROUT_CONSTEXPR typename sprout::types::tuple_cat::type...>::type tuple_cat(Tuples&&... tuples) { - return sprout::tuples::detail::tuple_cat_impl< - typename sprout::tuples::results::tuple_cat::type, - typename sprout::tuples::detail::tuple_cat_1st_indexes::type, - Tuples... - >::call(SPROUT_FORWARD(Tuples, tuples)...); + typedef typename sprout::types::tuple_cat::type...>::type type; + typedef sprout::tuples::detail::tuple_cat_indexes indexes; + return sprout::tuples::detail::tuple_cat_impl(indexes::for_pack::make(), indexes::for_element::make(), SPROUT_FORWARD(Tuples, tuples)...); } + +// namespace results { +// // +// // tuple_cat +// // +// template +// struct tuple_cat +// : public sprout::types::tuple_cat::type...> +// {}; +// } // namespace results +// +// namespace detail { +// template +// struct tuple_cat_1st_indexes; +// template<> +// struct tuple_cat_1st_indexes<> { +// public: +// typedef sprout::index_tuple<> type; +// }; +// template +// struct tuple_cat_1st_indexes +// : public sprout::tuple_indexes::type> +// {}; +// +// template +// struct tuple_cat_impl; +// template +// struct tuple_cat_impl > { +// public: +// template +// static SPROUT_CONSTEXPR Result +// call(Args&&... args) { +// return Result(SPROUT_FORWARD(Args, args)...); +// } +// }; +// template +// struct tuple_cat_impl, Head, Tail...> { +// public: +// template +// static SPROUT_CONSTEXPR Result +// call(T&& t, Args&&... args) { +// return sprout::tuples::detail::tuple_cat_impl< +// Result, +// typename sprout::tuples::detail::tuple_cat_1st_indexes::type, +// Tail... +// >::call( +// SPROUT_FORWARD(Args, args)..., +// sprout::tuples::get(SPROUT_FORWARD(T, t))... +// ); +// } +// }; +// } // namespace detail +// // +// // tuple_cat +// // +// template +// inline SPROUT_CONSTEXPR typename sprout::tuples::results::tuple_cat::type +// tuple_cat(Tuples&&... tuples) { +// return sprout::tuples::detail::tuple_cat_impl< +// typename sprout::tuples::results::tuple_cat::type, +// typename sprout::tuples::detail::tuple_cat_1st_indexes::type, +// Tuples... +// >::call(SPROUT_FORWARD(Tuples, tuples)...); +// } } // namespace tuples - namespace results { - using sprout::tuples::results::tuple_cat; - } // namespace results +// namespace results { +// using sprout::tuples::results::tuple_cat; +// } // namespace results using sprout::tuples::make_tuple; using sprout::tuples::forward_as_tuple; diff --git a/sprout/tuple/tuple/tuple_access_traits.hpp b/sprout/tuple/tuple/tuple_access_traits.hpp index 6f63daa6..d1bc8157 100644 --- a/sprout/tuple/tuple/tuple_access_traits.hpp +++ b/sprout/tuple/tuple/tuple_access_traits.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include namespace sprout { @@ -29,7 +30,7 @@ namespace sprout { template static SPROUT_CONSTEXPR typename sprout::tuples::tuple_element::type&& tuple_get(Tuple&& t) SPROUT_NOEXCEPT { - return std::get(t); + return sprout::move(std::get(t)); } template static SPROUT_CONSTEXPR typename sprout::tuples::tuple_element::type const&