It is known that template arguments can be pointers to member functions.
So I can write:
struct Bar
{
int fun(float x);
};
template <int (Bar::*FUN)(float)>
struct Foo
{ /*...*/ };
typedef Foo<&Bar::fun> FooBar;
But what if I want the the Bar
type itself to be a template argument:
template <typename B, int (B::*FUN)(float)>
struct Foo
{ /*...*/ };
typedef Foo<Bar, &Bar::fun> FooBar;
Now, when I use it, I have to write Bar
twice!
My question is: Is there a way to force the compiler to deduce the class type automatically?
The objective is for this to just work:
typedef Foo<&Bar::fun> FooBar;
typedef Foo<&Moo::fun> FooMoo;