M
Michael Andersson
Given a set of classes
class A { enum [ ID = 0x0001} };
class B { enum [ ID = 0x0002} };
class B { enum [ ID = 0x0004} };
I wish to generate a composite class, perhaps using something like
Alexandrescu's typelists
(pseudo-code
template<class TList>
class Composite : TList
{
enum {ID = SumID<TList>::result}
};
typedef composite<TYPELIST(A,B,C)> CompABC; // ID == 0x0007
Of course, the trivial A, B and C classes above would have data members
to make Composite meaningful, but the really important issue is
Composite's ID member, the value of which must be unique to the
combinations of components.
Thus, there are two parts to this. One, generating a linear inheritance
hierarchy from the typelist; and two, summing up the components' ID
values as the ID value of the generated composite.
Though I know exactly what I need I've so far (due to my inexperience
with metaprogramming) failed to implement this. I've tried using
Alexandrescu's Loki and BoostMPL, but am stymied. Any help would be
deeply appreciated!
class A { enum [ ID = 0x0001} };
class B { enum [ ID = 0x0002} };
class B { enum [ ID = 0x0004} };
I wish to generate a composite class, perhaps using something like
Alexandrescu's typelists
(pseudo-code
template<class TList>
class Composite : TList
{
enum {ID = SumID<TList>::result}
};
typedef composite<TYPELIST(A,B,C)> CompABC; // ID == 0x0007
Of course, the trivial A, B and C classes above would have data members
to make Composite meaningful, but the really important issue is
Composite's ID member, the value of which must be unique to the
combinations of components.
Thus, there are two parts to this. One, generating a linear inheritance
hierarchy from the typelist; and two, summing up the components' ID
values as the ID value of the generated composite.
Though I know exactly what I need I've so far (due to my inexperience
with metaprogramming) failed to implement this. I've tried using
Alexandrescu's Loki and BoostMPL, but am stymied. Any help would be
deeply appreciated!