Advertisement
Rochet2

tuples c++11

May 15th, 2018
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <tuple>
  3.  
  4. template<int ...>
  5. struct seq { };
  6. template<int N, int ...S>
  7. struct gens : gens<N-1, N-1, S...> { };
  8. template<int ...S>
  9. struct gens<0, S...> {
  10.   typedef seq<S...> type;
  11. };
  12.  
  13. template<int ...S, typename ...T>
  14. void PUSH(seq<S...> const &, std::tuple<T...> const & t)
  15. {
  16.     using expander = int[]; expander{(std::cout.operator<<(std::get<S>(t)), 0)...};
  17.     std::cout << std::endl;
  18. }
  19.  
  20. template<typename ...T1, typename ...T2>
  21. void foo(std::tuple<T1...>const& a, std::tuple<T2...>const& b)
  22. {
  23.     static typename gens<sizeof...(T1)>::type idx1;
  24.     static typename gens<sizeof...(T2)>::type idx2;
  25.     PUSH(idx1, (a));
  26.     PUSH(idx2, (b));
  27. }
  28.  
  29. int main() {
  30.     auto t = std::make_tuple(1,2,3);
  31.     foo(t, std::make_tuple(1,2,5,6,8));
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement