fork download
  1. #include <iostream>
  2. #include <functional>
  3.  
  4. struct Bar {
  5. int z;
  6.  
  7. Bar(int z) : z(z) {}
  8.  
  9. void add(int x, int y) { std::cout << x + y + z << std::endl; }
  10. };
  11.  
  12. template <typename T, typename... Arguments>
  13. struct Foo {
  14. std::function<void(T&, Arguments ...)> f;
  15.  
  16. template <typename F> Foo(F&& f) : f(std::forward<F>(f)) {}
  17.  
  18. void execute(Arguments ... args) {
  19. T c(2);
  20. f(c, args ...);
  21. }
  22. };
  23.  
  24. int main() {
  25. auto b = Foo<Bar, int, int>(&Bar::add);
  26. b.execute(4, 5);
  27.  
  28. return 0;
  29. }
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
11