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 Ft, Ft ff>
  13. struct Foo {
  14. template <typename... Arguments>
  15. void execute(Arguments... args) {
  16. T d(3);
  17.  
  18. std::function<void(T&, Arguments...)> f = ff;
  19. f(d, args ...);
  20. }
  21. };
  22.  
  23. int main() {
  24. auto b = Foo<Bar, decltype(&Bar::add), &Bar::add>();
  25. b.execute(4, 5);
  26.  
  27. return 0;
  28. }
  29.  
Success #stdin #stdout 0s 2896KB
stdin
Standard input is empty
stdout
12