fork(1) download
  1. #include <functional>
  2. #include <iostream>
  3.  
  4. void apply(std::function<void()> f, int) {
  5. f();
  6. }
  7.  
  8. template <typename Head, typename ...Tail>
  9. void apply(std::function<void(Head, Tail...)> f, int i=0) {
  10. auto g = [=](Tail&& ...args){
  11. f(i, std::forward<Tail>(args)...);
  12. };
  13.  
  14. apply(std::function<void(Tail...)>{g}, ++i);
  15. }
  16.  
  17. void foo(int a, int b, int c, int d) {
  18. std::cout << a << b << c << d << "\n";
  19. }
  20.  
  21. int main() {
  22. auto f = std::function<void(int,int,int,int)>(foo);
  23. apply(f);
  24. }
  25.  
Success #stdin #stdout 0s 3276KB
stdin
Standard input is empty
stdout
0123