fork(2) 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 Return, class... Args>
  18. void Invoke(This *obj, Return(This::*MFPTR)(Args...), Args&&... args) const
  19. {
  20. // Do something need the Return, This, Args... types..
  21. (obj->*MFPTR)(std::forward<Args>(args)...);
  22. }
  23.  
  24. template<class This, class Return, class... Args>
  25. void Invoke(This *obj, Return(This::*MFPTR)(Args...) const, Args&&... args) const
  26. {
  27. (obj->*MFPTR)(std::forward<Args>(args)...);
  28. }
  29. };
  30. int main() {
  31. CallMe call;
  32. Foo f;
  33. call.Invoke(&f, &Foo::Bar, 1);
  34. call.Invoke(&f, &Foo::BarConst, 1);
  35. // your code goes here
  36. return 0;
  37. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
non-const 1
const 1