fork(1) download
  1. #include <functional>
  2. #include <string>
  3. #include <tuple>
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. template<typename ...Args>
  9. struct TypeList {};
  10.  
  11. typedef TypeList<int, float, string> Types;
  12.  
  13. template <typename ...Args>
  14. struct MakeTupleOfTypes;
  15.  
  16. template <typename ...Args>
  17. struct MakeTupleOfTypes<TypeList<Args...>>
  18. {
  19. typedef tuple<Args...> type;
  20. };
  21.  
  22. template <typename ...Args>
  23. struct MakeTupleOfFunction;
  24.  
  25. template <typename ...Args>
  26. struct MakeTupleOfFunction<TypeList<Args...>>
  27. {
  28. typedef tuple<function<void(Args)>...> type; // <-- VS2013 error here
  29. };
  30.  
  31.  
  32. typedef TypeList<int, float, string> Types;
  33. typedef MakeTupleOfTypes<Types>::type TupleOfTypes;
  34. typedef MakeTupleOfFunction<Types>::type TupleOfFunctions;
  35.  
  36. void f1(int x) { cout << x << endl; }
  37. void f2(float x) { cout << x << endl; }
  38. void f3(string x) { cout << x << endl; }
  39.  
  40. int main()
  41. {
  42. TupleOfTypes values;
  43. get<0>(values) = 42;
  44. get<1>(values) = 3.14159;
  45. get<2>(values) = "Hello, World!";
  46.  
  47. TupleOfFunctions functions;
  48. get<0>(functions) = &f1;
  49. get<1>(functions) = &f2;
  50. get<2>(functions) = &f3;
  51.  
  52. get<0>(functions)(get<0>(values));
  53. get<1>(functions)(get<1>(values));
  54. get<2>(functions)(get<2>(values));
  55.  
  56. return 0;
  57. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
42
3.14159
Hello, World!