I am trying to provide users with a class (MyGizmo below) that derives from the variational hierarchy (ObjGetter below) with a simple, uncluttered way to uniquely call a member function that takes no arguments (check () below). I can do this work with functions that take arguments (e.g. tune () below), but I have not found a way to make it work for functions that take no arguments.
struct Base { };
struct ObjA : public Base { };
struct ObjB : public Base { };
struct ObjC : public Base { };
template <class ... Obj> struct ObjGetter;
template <class Obj, class ... Tail>
struct ObjGetter<Obj, Tail ...> : public ObjGetter<Tail ...>
{
using ObjGetter<Tail ...>::tune;
void tune(Obj * obj) { }
Obj * check() const { return 0; }
};
template <> struct ObjGetter<> {
void tune(void);
};
struct MyGizmo : public ObjGetter<ObjA, ObjC>
{
void testit() {
ObjA * a = 0; ObjB *b = 0; ObjC *c = 0;
a = ObjGetter<ObjA, ObjC>::check();
c = ObjGetter<ObjC>::check();
tune(a);
tune(c);
}
};
I tried the following, but not completely guessed:
At first, I can use a secondary, just a template class that wraps around the hierarchy to reduce the ugly call, to have only one arg template; gives something like:
a = ObjGetterHelper<ObjA>::check();
c = ObjGetterHelper<ObjC>::check();
Type2Type check() , , :
a = check(Type2Type<ObjA>());
c = check(Type2Type<ObjC>());
, ...
#define CHECK(X) check(Type2Type<X>())
, , g++, . - ? !