fork(1) download
  1. #include <functional>
  2.  
  3. class Foo
  4. {
  5. public:
  6. void bar1(int )
  7. {
  8. /// No-op.
  9. }
  10.  
  11. void bar2(const int &)
  12. {
  13. /// No-op.
  14. }
  15.  
  16. void foo(int x)
  17. {
  18. _wrapper_bar1(x); /// No problems to deduce type
  19. _wrapper_bar2(x); /// No problems to deduce type
  20.  
  21. _wrapper(&Foo::bar1, x);
  22. _wrapper(&Foo::bar2, x);
  23. }
  24.  
  25. private:
  26. template <typename ...Args, typename ...Arg2s>
  27. void _wrapper(void (Foo::*method) (Args ...), Arg2s&& ...args)
  28. {
  29. /// Do some common stuff here...
  30.  
  31. (this->*method)(std::forward<Arg2s>(args)...);
  32. }
  33.  
  34. template <typename ...Args>
  35. void _wrapper_bar1(Args && ...args)
  36. {
  37. bar1(std::forward<Args>(args)...);
  38. }
  39.  
  40. template <typename ...Args>
  41. void _wrapper_bar2(Args && ...args)
  42. {
  43. bar2(std::forward<Args>(args)...);
  44. }
  45. };
  46.  
  47. int main()
  48. {
  49. Foo().foo(123);
  50. }
  51.  
Success #stdin #stdout 0s 3136KB
stdin
Standard input is empty
stdout
Standard output is empty