fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct Foo
  5. {
  6. void Bar(int a)
  7. {
  8. cout<<"non-const "<<a<<endl;
  9. }
  10. void BarConst(int a) const
  11. {
  12. cout<<"const "<<a<<endl;
  13. }
  14. };
  15. struct CallMe
  16. {
  17. template<class This, class F, class... Args>
  18. void Invoke(This *obj, F&& f, Args&&... args) const
  19. {
  20. // Do something need the Return, This, Args... types..
  21. (obj->*std::forward<F>(f))(std::forward<Args>(args)...);
  22. }
  23. };
  24. int main() {
  25. CallMe call;
  26. Foo f;
  27. call.Invoke(&f, &Foo::Bar, 1);
  28. call.Invoke(&f, &Foo::BarConst, 1);
  29. // your code goes here
  30. return 0;
  31. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
non-const 1
const 1