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

fix make_tuple implementation

This commit is contained in:
bolero-MURAKAMI 2014-08-23 22:07:03 +09:00
parent 343d1ff74b
commit 0c15b01b0d
4 changed files with 101 additions and 119 deletions

View file

@ -219,15 +219,6 @@ namespace testspr {
}
// tuple_cat
{
typedef sprout::tuples::results::tuple_cat<decltype(tup1), decltype(tup2)>::type concatenated_type;
TESTSPR_BOTH_ASSERT(sprout::tuples::tuple_size<concatenated_type>::value == 4);
TESTSPR_BOTH_ASSERT((std::is_same<sprout::tuples::tuple_element<0, concatenated_type>::type, int>::value));
TESTSPR_BOTH_ASSERT((std::is_same<sprout::tuples::tuple_element<1, concatenated_type>::type, double>::value));
TESTSPR_BOTH_ASSERT((std::is_same<sprout::tuples::tuple_element<2, concatenated_type>::type, int>::value));
TESTSPR_BOTH_ASSERT((std::is_same<sprout::tuples::tuple_element<3, concatenated_type>::type, double>::value));
}
{
SPROUT_STATIC_CONSTEXPR auto tup3 = sprout::tuples::tuple_cat(tup1, tup2);
TESTSPR_BOTH_ASSERT(sprout::tuples::get<0>(tup3) == 1);

View file

@ -13,6 +13,7 @@
#include <sprout/config.hpp>
#include <sprout/workaround/std/cstddef.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/utility/move.hpp>
#include <sprout/tuple/tuple/tuple.hpp>
#include <sprout/tuple/tuple/tuple_size.hpp>
#include <sprout/tuple/tuple/tuple_element.hpp>
@ -81,7 +82,7 @@ namespace sprout_tuple_detail {
tuple_get(T&& t)
SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::tuple_access_traits<typename std::remove_reference<T>::type>::template tuple_get<I>(std::declval<T&&>()))
{
return sprout::tuples::tuple_access_traits<T>::template tuple_get<I>(t);
return sprout::move(sprout::tuples::tuple_access_traits<T>::template tuple_get<I>(t));
}
template<std::size_t I, typename T>
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_traits<T const>::template lvalue_reference<I>::type

View file

@ -12,10 +12,12 @@
#include <sprout/config.hpp>
#include <sprout/index_tuple/metafunction.hpp>
#include <sprout/utility/forward.hpp>
#include <sprout/utility/pack.hpp>
#include <sprout/functional/ref.hpp>
#include <sprout/tuple/tuple/tuple.hpp>
#include <sprout/tuple/tuple/get.hpp>
#include <sprout/tuple/indexes.hpp>
//#include <sprout/tuple/indexes.hpp>
#include <sprout/type/operation/tuple_cat.hpp>
namespace sprout {
namespace tuples {
@ -46,121 +48,108 @@ namespace sprout {
return sprout::tuples::tuple<Types&...>(args...);
}
namespace results {
namespace detail {
template<typename... Tuples>
struct tuple_cat_impl;
template<>
struct tuple_cat_impl<> {
typedef sprout::tuples::tuple<> type;
};
template<typename Tuple>
struct tuple_cat_impl<Tuple> {
private:
template<typename Tup, typename IndexTuple>
struct make;
template<typename Tup, sprout::index_t... Indexes>
struct make<Tup, sprout::index_tuple<Indexes...> > {
public:
typedef sprout::tuples::tuple<typename sprout::tuples::tuple_element<Indexes, Tup>::type...> type;
};
public:
typedef typename make<
Tuple, typename sprout::tuple_indexes<Tuple>::type
>::type type;
};
template<typename T, typename U, typename... Tuples>
struct tuple_cat_impl<T, U, Tuples...> {
private:
template<typename Tup1, typename IndexTuple1, typename Tup2, typename IndexTuple2>
struct make;
template<typename Tup1, sprout::index_t... Indexes1, typename Tup2, sprout::index_t... Indexes2>
struct make<Tup1, sprout::index_tuple<Indexes1...>, Tup2, sprout::index_tuple<Indexes2...> > {
public:
typedef sprout::tuples::tuple<
typename sprout::tuples::tuple_element<Indexes1, Tup1>::type...,
typename sprout::tuples::tuple_element<Indexes2, Tup2>::type...
> type;
};
public:
typedef typename sprout::tuples::results::detail::tuple_cat_impl<
typename make<
T, typename sprout::tuple_indexes<T>::type,
U, typename sprout::tuple_indexes<U>::type
>::type,
Tuples...
>::type type;
};
} // namespace detail
//
// tuple_cat
//
template<typename... Tuples>
struct tuple_cat
: public sprout::tuples::results::detail::tuple_cat_impl<
typename std::decay<Tuples>::type...
>
{};
} // namespace results
namespace detail {
template<typename... Tuples>
struct tuple_cat_1st_indexes;
template<>
struct tuple_cat_1st_indexes<> {
public:
typedef sprout::index_tuple<> type;
};
template<typename Head, typename... Tail>
struct tuple_cat_1st_indexes<Head, Tail...>
: public sprout::tuple_indexes<typename std::remove_reference<Head>::type>
{};
template<typename Result, typename IndexTuple, typename... Tuples>
struct tuple_cat_impl;
template<typename Result>
struct tuple_cat_impl<Result, sprout::index_tuple<> > {
public:
template<typename... Args>
static SPROUT_CONSTEXPR Result
call(Args&&... args) {
return Result(SPROUT_FORWARD(Args, args)...);
}
};
template<typename Result, sprout::index_t... Indexes, typename Head, typename... Tail>
struct tuple_cat_impl<Result, sprout::index_tuple<Indexes...>, Head, Tail...> {
public:
template<typename T, typename... Args>
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<Tail...>::type,
Tail...
>::call(
SPROUT_FORWARD(Args, args)...,
sprout::tuples::get<Indexes>(SPROUT_FORWARD(T, t))...
);
}
};
} // namespace detail
//
// tuple_cat
//
namespace detail {
template<typename PackIndexTuple, std::size_t... TupleSizes>
struct tuple_cat_indexes_impl;
template<sprout::index_t... PackIndexes, std::size_t... TupleSizes>
struct tuple_cat_indexes_impl<sprout::index_tuple<PackIndexes...>, TupleSizes...> {
public:
typedef typename sprout::types::tuple_cat<typename sprout::index_n<PackIndexes, TupleSizes>::type...>::type for_pack;
typedef typename sprout::types::tuple_cat<typename sprout::make_index_tuple<TupleSizes>::type...>::type for_element;
};
template<typename... Tuples>
struct tuple_cat_indexes
: public sprout::tuples::detail::tuple_cat_indexes_impl<
typename sprout::make_index_tuple<sizeof...(Tuples)>::type,
sprout::tuples::tuple_size<typename std::decay<Tuples>::type>::value...
>
{};
template<typename Result, sprout::index_t... PackIndexes, sprout::index_t... ElemIndexes, typename... Tuples>
static SPROUT_CONSTEXPR Result
tuple_cat_impl(sprout::index_tuple<PackIndexes...>, sprout::index_tuple<ElemIndexes...>, Tuples&&... tuples) {
return Result(sprout::tuples::get<ElemIndexes>(sprout::pack_get<PackIndexes>(SPROUT_FORWARD(Tuples, tuples)...))...);
};
} // namespace detail
template<typename... Tuples>
inline SPROUT_CONSTEXPR typename sprout::tuples::results::tuple_cat<Tuples...>::type
inline SPROUT_CONSTEXPR typename sprout::types::tuple_cat<typename std::decay<Tuples>::type...>::type
tuple_cat(Tuples&&... tuples) {
return sprout::tuples::detail::tuple_cat_impl<
typename sprout::tuples::results::tuple_cat<Tuples...>::type,
typename sprout::tuples::detail::tuple_cat_1st_indexes<Tuples...>::type,
Tuples...
>::call(SPROUT_FORWARD(Tuples, tuples)...);
typedef typename sprout::types::tuple_cat<typename std::decay<Tuples>::type...>::type type;
typedef sprout::tuples::detail::tuple_cat_indexes<Tuples...> indexes;
return sprout::tuples::detail::tuple_cat_impl<type>(indexes::for_pack::make(), indexes::for_element::make(), SPROUT_FORWARD(Tuples, tuples)...);
}
// namespace results {
// //
// // tuple_cat
// //
// template<typename... Tuples>
// struct tuple_cat
// : public sprout::types::tuple_cat<typename std::decay<Tuples>::type...>
// {};
// } // namespace results
//
// namespace detail {
// template<typename... Tuples>
// struct tuple_cat_1st_indexes;
// template<>
// struct tuple_cat_1st_indexes<> {
// public:
// typedef sprout::index_tuple<> type;
// };
// template<typename Head, typename... Tail>
// struct tuple_cat_1st_indexes<Head, Tail...>
// : public sprout::tuple_indexes<typename std::remove_reference<Head>::type>
// {};
//
// template<typename Result, typename IndexTuple, typename... Tuples>
// struct tuple_cat_impl;
// template<typename Result>
// struct tuple_cat_impl<Result, sprout::index_tuple<> > {
// public:
// template<typename... Args>
// static SPROUT_CONSTEXPR Result
// call(Args&&... args) {
// return Result(SPROUT_FORWARD(Args, args)...);
// }
// };
// template<typename Result, sprout::index_t... Indexes, typename Head, typename... Tail>
// struct tuple_cat_impl<Result, sprout::index_tuple<Indexes...>, Head, Tail...> {
// public:
// template<typename T, typename... Args>
// 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<Tail...>::type,
// Tail...
// >::call(
// SPROUT_FORWARD(Args, args)...,
// sprout::tuples::get<Indexes>(SPROUT_FORWARD(T, t))...
// );
// }
// };
// } // namespace detail
// //
// // tuple_cat
// //
// template<typename... Tuples>
// inline SPROUT_CONSTEXPR typename sprout::tuples::results::tuple_cat<Tuples...>::type
// tuple_cat(Tuples&&... tuples) {
// return sprout::tuples::detail::tuple_cat_impl<
// typename sprout::tuples::results::tuple_cat<Tuples...>::type,
// typename sprout::tuples::detail::tuple_cat_1st_indexes<Tuples...>::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;

View file

@ -11,6 +11,7 @@
#include <tuple>
#include <sprout/config.hpp>
#include <sprout/workaround/std/cstddef.hpp>
#include <sprout/utility/move.hpp>
#include <sprout/tuple/tuple/tuple_element.hpp>
namespace sprout {
@ -29,7 +30,7 @@ namespace sprout {
template<std::size_t I>
static SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, Tuple>::type&&
tuple_get(Tuple&& t) SPROUT_NOEXCEPT {
return std::get<I>(t);
return sprout::move(std::get<I>(t));
}
template<std::size_t I>
static SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, Tuple>::type const&