fork(1) download
  1. #include <tuple>
  2. #include <type_traits>
  3. #include <array>
  4. #include <typeinfo>
  5. #include <iostream>
  6.  
  7. template<typename T1, typename T2>
  8. struct concat_tuples;
  9.  
  10. template<typename... T1, typename... T2>
  11. struct concat_tuples<std::tuple<T1...>, std::tuple<T2...>>
  12. {
  13. using type = std::tuple<T1..., T2...>;
  14. };
  15.  
  16. template<typename T, size_t n>
  17. struct n_tuple;
  18.  
  19. template<typename T>
  20. struct n_tuple<T, 0>
  21. {
  22. using type = std::tuple<>;
  23. };
  24.  
  25. template<typename T, size_t n>
  26. struct n_tuple
  27. {
  28. using type = typename concat_tuples<
  29. typename n_tuple<T, n-1>::type,
  30. std::tuple<T>
  31. >::type;
  32. };
  33.  
  34. template <class Scalar, class Array, class Tuple>
  35. struct Test;
  36.  
  37. template <class Scalar, typename T, size_t n, typename... Ts>
  38. struct Test<Scalar, std::array<T, n>, std::tuple<Ts...>>
  39. {
  40. using type = typename concat_tuples<
  41. typename concat_tuples<
  42. std::tuple<Scalar>,
  43. typename n_tuple<T, n>::type
  44. >::type,
  45. std::tuple<Ts...>
  46. >::type;
  47. };
  48.  
  49. int main() {
  50. static_assert(std::is_same<n_tuple<int, 3>::type, std::tuple<int, int, int>>::value, "NOT EQUAL");
  51. static_assert(std::is_same<Test<float, std::array<int, 3>, std::tuple<char, bool>>::type, std::tuple<float, int, int, int, char, bool>>::value, "NOT EQUAL");
  52. }
  53.  
Success #stdin #stdout 0s 3336KB
stdin
Standard input is empty
stdout
Standard output is empty