Suppose you have something like this:
template<class D>
class HasDef {
public:
typedef D Def;
};
class A : public HasDef<class B> {};
class B : public HasDef<class C> {};
class C {};
So it is like a "metaprogramming linked list", with type links, via the included typedef Def
. Now I want to make a template "Leaf" that, when applied to A
, follows the links to yield C
:
void f() {
Leaf<A>::type v; // has type C
}
Is it even possible at all to do this? I've tried some methods with std::compare
and similar, but none are valid code: everything seems to run into issues with either that C
has no Def
typedef, or else that the type Leaf<>
itself is incomplete when the inner recursive "call" is made so it (or its internal type type
) cannot be referenced.
FWIW, the reason I want this is for making a "hierarchical state machine" where that Def
represents the default state for each state in the hierarchy, and something a bit more elaborate that this seems to provide a fairly neat and clean "user interface syntax" for it.