Boost logo

Boost Users :

Subject: Re: [Boost-users] [mpl] register types in a mpl sequence type
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-04-09 10:29:41


AMDG

Thomas Lemm wrote:
> I am trying to accomplish a compile time type registry by trying to register a specific subset of my classes into an mpl sequence type. So during compilation that sequence type should hold a sequence of my classes for subsequent processing (e.g. by mpl::for_each).
>
> An example:
> --- code start --------------
> class Super {
> tyedef mpl::list<> SubTypesList;
>
> // usage of SubTypesList:
> printSubtypes() { mpl::for_each< SubTypesList >( ... )};
> };
>
> class A : public RegisterWith< A, Super > {};
>
> class B : public RegisterWith< B, Super > {};
> --- code end --------------
>
> now Super::SubTypesList should be equivalent to mpl::list< A, B >.
>
> I have the feeling that this approach is not achievable with templates alone due to the C++ template mechanism not being able to redefine a type.
>
> Still I would be happy being proven wrong. Any pointers to similiar problems and solutions, alternative approaches (maybe using the boost_pp?) are welcome, too.
>

It is possible to implement such a feature on some compilers, but it
isn't really
legal. Also, any automatic solutions will cause ODR violation unless
every derived class is registered in the same order in every translation
unit.
You'll need to make a global list of derived classes somewhere.

In Christ,
Steven Watanabe


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net