fork(1) download
  1. #include <iostream>
  2. #include <tuple>
  3. using namespace std;
  4.  
  5. // bar : does something with an arbitrary tuple
  6. // (no variadic template arguments)
  7. template <class Tuple>
  8. void bar(Tuple t)
  9. {
  10. // .... do something with the tuple ...
  11. std::cout << std::tuple_size<Tuple>::value;
  12. }
  13.  
  14. // foo : takes a function pointer and an arbitrary number of other
  15. // arguments
  16. template <class Func, typename... Ts>
  17. void foo(Func f, Ts... args_in)
  18. {
  19. // construct a tuple containing the variadic arguments
  20. std::tuple<Ts...> t = std::make_tuple(args_in...);
  21.  
  22. // pass this tuple to the function f
  23. f(t);
  24. }
  25.  
  26. int main()
  27. {
  28. // this is not highly refined; you must provide the types of the
  29. // arguments (any suggestions?)
  30. foo(bar<std::tuple<int, const char *, double>>, 123, "foobar", 43.262);
  31. return 0;
  32. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
3