fork(10) download
  1. #include <iostream>
  2. #include <tuple>
  3. #include <string>
  4.  
  5. // helper function to print a tuple of any size
  6. template<class Tuple, std::size_t N>
  7. struct TuplePrinter {
  8. static void print(const Tuple& t)
  9. {
  10. TuplePrinter<Tuple, N-1>::print(t);
  11. std::cout << ", " << std::get<N-1>(t);
  12. }
  13. };
  14.  
  15. template<class Tuple>
  16. struct TuplePrinter<Tuple, 1> {
  17. static void print(const Tuple& t)
  18. {
  19. std::cout << std::get<0>(t);
  20. }
  21. };
  22.  
  23. template<class... Args>
  24. void print(const std::tuple<Args...>& t)
  25. {
  26. std::cout << "(";
  27. TuplePrinter<decltype(t), sizeof...(Args)>::print(t);
  28. std::cout << ")\n";
  29. }
  30. // end helper function
  31.  
  32. int main()
  33. {
  34. std::tuple<int, std::string, float> t1(10, "Test", 3.14);
  35. int n = 7;
  36. auto t2 = std::tuple_cat(t1, std::make_pair("Foo", "bar"), t1, std::tie(n));
  37. n = 10;
  38. print(t2);
  39. }
Success #stdin #stdout 0s 3232KB
stdin
Standard input is empty
stdout
(10, Test, 3.14, Foo, bar, 10, Test, 3.14, 10)