fork download
  1. #include <iostream>
  2. #include <tuple>
  3. using namespace std;
  4.  
  5. template<class Func, size_t index>
  6. class ForwardsApplicator{
  7. public:
  8. template<class ...Components>
  9. void operator()(Func func, const std::tuple<Components...>& t){
  10. ForwardsApplicator<Func, index - 1>()(func, t);
  11. func(std::get<index - 1>(t));
  12. }
  13. };
  14.  
  15. template<class Func>
  16. class ForwardsApplicator<Func, 0> {
  17. public:
  18. template<class ...Components>
  19. void operator()(Func func, const std::tuple<Components...>& t){}
  20. };
  21.  
  22. template<class Func, class ...Components>
  23. void apply(Func func, const std::tuple<Components...>& t) {
  24. ForwardsApplicator<Func, sizeof...(Components)>()(func, t);
  25. }
  26.  
  27.  
  28.  
  29. class Lambda{
  30. public:
  31. template<class T>
  32. void operator()(T arg){ std::cout << arg << "; "; }
  33. };
  34.  
  35. int main() {
  36. apply(Lambda{}, std::make_tuple(1, 2.0f));
  37. }
  38.  
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
1; 2;