c++ - Convert scalar + std::array + std::tuple into a big tuple -
consider following code:
template <class scalar, class array, class tuple> class test {};
where array
std::array
, , tuple
std::tuple
. in class, have lot of sfinae, , create big tuple called types
contain complete list of types. allow me test conditions variadic lists.
so challenge create type have following behaviour. if:
scalar = int
array = std::array<double, 3>
tuple = std::tuple<char, float, std::string>
then:
types = std::tuple<int, double, double, double, char, float, std::string>
which concatenation of internal data of scalar
, array
, tuple
.
how ?
this seems work:
template<typename t1, typename t2> struct concat_tuples; template<typename... t1, typename... t2> struct concat_tuples<std::tuple<t1...>, std::tuple<t2...>> { using type = std::tuple<t1..., t2...>; }; // n_tuple<int, 3>::type == std::tuple<int, int, int> template<typename t, size_t n> struct n_tuple; template<typename t> struct n_tuple<t, 0> { using type = std::tuple<>; }; template<typename t, size_t n> struct n_tuple { using type = typename concat_tuples< typename n_tuple<t, n-1>::type, std::tuple<t> >::type; }; template <class scalar, class array, class tuple> struct test; template <class scalar, typename t, size_t n, typename... ts> struct test<scalar, std::array<t, n>, std::tuple<ts...>> { using type = typename concat_tuples< typename concat_tuples< std::tuple<scalar>, typename n_tuple<t, n>::type >::type, std::tuple<ts...> >::type; };
live demo here.
Comments
Post a Comment