template<typename O, void (O::* f)()>
struct NonConstFunc
{
static void call(O* o)
{
(o->*f)();
}
};
template<typename O, void (O::* f)() const>
struct ConstFunc
{
static void call(O* o)
{
(o->*f)();
}
};
template<typename Obj, typename Function>
void call(Obj* o)
{
Function::call(o);
}
struct foo
{
void bar()
{
cout << "hey" << endl;
}
void constbar() const
{
cout << "ho" << endl;
}
};
int main()
{
foo f;
call<foo,NonConstFunc<foo,&foo::bar> >(&f);
call<foo,ConstFunc<foo,&foo::constbar> >(&f);
}