Say I have:
struct Foo { void a(); void b(const int& ); int c(); };
I can create a function that takes an arbitrary pointer-to- Foo method as an argument:
template <typename R, typename... Formal, typename... Args> R call(Foo* f, R (Foo::*method)(Formal...), Args&&... args) { return (f->*method)(std::forward<Args>(args)...); } int gratuitous = call(&some_foo, &Foo::c);
And I can create a function that takes a specific type of pointer-to- Foo method as a template:
template <void (Foo::*method)()> void only_for_a(Foo *f) { (f->*method)(); } only_for_a<&Foo::a>(&some_foo);
But is there a way to create a function in which I can create a template for any pointer to a class method? I want to be able to:
works_for_anything<&Foo::a>(&some_foo); works_for_anything<&Foo::b>(&some_foo, 42); int result = works_for_anything<&Foo::c>(&some_foo);
Barry source share