fork download
  1. #include <vector>
  2. #include <tuple>
  3. #include <type_traits>
  4.  
  5. template <typename... T>
  6. struct transpose {};
  7.  
  8. template <typename... T>
  9. struct transpose<std::tuple<std::vector<T>...>>
  10. {
  11. using type = std::vector<std::tuple<T...>>;
  12. };
  13.  
  14. template <typename... T>
  15. struct transpose<std::vector<std::tuple<T...>>>
  16. {
  17. using type = std::tuple<std::vector<T>...>;
  18. };
  19.  
  20. template <int... Is>
  21. struct seq {};
  22.  
  23. template <int N, int... Is>
  24. struct gen_seq : gen_seq<N - 1, N - 1, Is...> {};
  25.  
  26. template <int... Is>
  27. struct gen_seq<0, Is...> : seq<Is...> {};
  28.  
  29. template <typename... T, int... Is>
  30. auto tuple_transpose(std::tuple<std::vector<T>...>& var, seq<Is...>) -> typename transpose<decltype(var)>::type
  31. {
  32. return { std::make_tuple(std::get<Is>(var)...) };
  33. }
  34.  
  35. template <typename... T>
  36. auto tuple_transpose(std::tuple<std::vector<T>...>& var) -> typename transpose<decltype(var)>::type
  37. {
  38. return tuple_transpose(var, gen_seq<sizeof...(T)>{});
  39. }
  40.  
  41. int main()
  42. {
  43. std::tuple<std::vector<int>, std::vector<bool>> var;
  44. tuple_transpose(var);
  45.  
  46.  
  47. }
Compilation error #stdin compilation error #stdout 0s 2848KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:44:24: error: no matching function for call to ‘tuple_transpose(std::tuple<std::vector<int, std::allocator<int> >, std::vector<bool, std::allocator<bool> > >&)’
prog.cpp:44:24: note: candidates are:
prog.cpp:30:6: note: template<class ... T, int ...Is> typename transpose<decltype (var)>::type tuple_transpose(std::tuple<std::vector<T, std::allocator<T> >...>&, seq<Is ...>)
prog.cpp:30:6: note:   template argument deduction/substitution failed:
prog.cpp:44:24: note:   candidate expects 2 arguments, 1 provided
prog.cpp:36:6: note: template<class ... T> typename transpose<decltype (var)>::type tuple_transpose(std::tuple<std::vector<T, std::allocator<T> >...>&)
prog.cpp:36:6: note:   template argument deduction/substitution failed:
prog.cpp: In substitution of ‘template<class ... T> typename transpose<decltype (var)>::type tuple_transpose(std::tuple<std::vector<T, std::allocator<T> >...>&) [with T = {int, bool}]’:
prog.cpp:44:24:   required from here
prog.cpp:36:6: error: no type named ‘type’ in ‘struct transpose<std::tuple<std::vector<int, std::allocator<int> >, std::vector<bool, std::allocator<bool> > >&>’
stdout
Standard output is empty