fork download
  1. #include <iostream>
  2. #include <utility>
  3. using namespace std;
  4.  
  5. template<typename T, typename M, M Method>
  6. class ProxyObject
  7. {
  8. public:
  9.  
  10. template<typename... Args>
  11. void Invoke (T& Object, Args&&... A)
  12. {
  13. (void)(Object.*Method)(std::forward<Args>(A)...);
  14. }
  15. };
  16.  
  17. class Object
  18. {
  19. public:
  20.  
  21. int MyMethod (int Val)
  22. {
  23. cout << "Hello!" << endl;
  24. return Val;
  25. }
  26. };
  27.  
  28. template<typename T, typename M, typename... Args>
  29. void invoke (T& Object, M Method, Args&&... A)
  30. {
  31. (void)(Object.*Method)(std::forward<Args>(A)...);
  32. }
  33.  
  34. int main ()
  35. {
  36. Object myObj;
  37. ProxyObject<Object, decltype(&Object::MyMethod), &Object::MyMethod> obj;
  38.  
  39. obj.Invoke(myObj, 10);
  40.  
  41. invoke(myObj, &Object::MyMethod, 10);
  42.  
  43. return 0;
  44. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
Hello!
Hello!