fork download
  1. #include <iostream>
  2. #include <tuple>
  3. #include <vector>
  4.  
  5. namespace detail
  6. {
  7. template <typename... Ts>
  8. struct tuple_change { };
  9.  
  10. template <typename... Ts>
  11. struct tuple_change<std::tuple<Ts...>>
  12. {
  13. using type = std::tuple<std::vector<Ts>...>;
  14. };
  15.  
  16. template <int... Is>
  17. struct index { };
  18.  
  19. template <int N, int... Is>
  20. struct gen_seq : gen_seq<N - 1, N - 1, Is...> { };
  21.  
  22. template <int... Is>
  23. struct gen_seq<0, Is...> : index<Is...> { };
  24. }
  25.  
  26. template <typename... Args, int... Is>
  27. void fill(std::tuple<Args...>& var, detail::index<Is...>)
  28. {
  29. auto l = { (std::get<Is>(var).assign(5, 11), 0)... };
  30. // here I just decided to make the size 5
  31. (void)l;
  32. }
  33.  
  34. template <typename... Args>
  35. void fill(std::tuple<Args...>& var)
  36. {
  37. fill(var, detail::gen_seq<sizeof...(Args)>{});
  38. }
  39.  
  40. template <typename T>
  41. static void print(std::vector<T>& v)
  42. {
  43. for (auto a : v)
  44. {
  45. std::cout << std::boolalpha << a << std::endl;
  46. }
  47. std::cout << std::endl;
  48. }
  49.  
  50. template <typename... Ts, int... Is>
  51. static void print(std::tuple<Ts...>& var, detail::index<Is...>)
  52. {
  53. auto l = { (print(std::get<Is>(var)), 0)... };
  54. (void)l;
  55. }
  56.  
  57. template <typename... Ts>
  58. static void print(std::tuple<Ts...>& var)
  59. {
  60. print(var, detail::gen_seq<sizeof...(Ts)>{});
  61. }
  62.  
  63. using result_type = detail::tuple_change<std::tuple<int, bool>>::type;
  64.  
  65. int main()
  66. {
  67. result_type r;
  68.  
  69. fill(r);
  70. print(r);
  71. }
Success #stdin #stdout 0s 3032KB
stdin
Standard input is empty
stdout
11
11
11
11
11

true
true
true
true
true