#include <functional>

template<class T>
class Ptr {
public:
  Ptr(T* ptr) : p(ptr) {}
  ~Ptr() { if(p) delete p; }

  template<class Ret, class... Args>
  auto operator ->* (Ret (T::*method)(Args...)) -> std::function<Ret(Args...)>
  {
    return [this, method](Args&&... args) -> Ret { return (this->p->*method)(std::forward<Args>(args)...); };
  }

private:
  T *p;
};

class Foo {
public:
  void foo(int) {}
  int bar() { return 3; }
};

int main() {
  Ptr<Foo> p(new Foo());

  void (Foo::*method)(int) = &Foo::foo;
  int (Foo::*method2)() = &Foo::bar;

  (p->*method)(5);
  (p->*method2)();

  return 0;
}
