fork(3) download
  1.  
  2. template<typename, typename>
  3. struct append_to_type_seq { };
  4.  
  5. template<typename T, typename... Ts, template<typename...> class TT>
  6. struct append_to_type_seq<T, TT<Ts...>>
  7. {
  8. using type = TT<Ts..., T>;
  9. };
  10.  
  11. template<typename T, unsigned int N, template<typename...> class TT>
  12. struct repeat
  13. {
  14. using type = typename
  15. append_to_type_seq<
  16. T,
  17. typename repeat<T, N-1, TT>::type
  18. >::type;
  19. };
  20.  
  21. template<typename T, template<typename...> class TT>
  22. struct repeat<T, 0, TT>
  23. {
  24. using type = TT<>;
  25. };
  26.  
  27. #include <type_traits>
  28. #include <tuple>
  29.  
  30. template<typename... Ts>
  31. struct X { };
  32.  
  33. int main()
  34. {
  35. repeat<double, 5, std::tuple>::type t = std::make_tuple(1., 2., 3., 4., 5.);
  36. static_assert(
  37. std::is_same<
  38. decltype(t),
  39. std::tuple<double, double, double, double, double>
  40. >::value, "!");
  41.  
  42. repeat<double, 3, X>::type y;
  43. static_assert(std::is_same<decltype(y), X<double, double, double>>::value, "!");
  44. }
  45.  
Success #stdin #stdout 0s 2892KB
stdin
Standard input is empty
stdout
Standard output is empty