Boost logo

Boost Users :

From: Istvan Buki (istvan.buki_at_[hidden])
Date: 2003-08-17 11:55:25

Hello Boost experts,

I'm starting learning about template metaprogramming and I discovered that
Boost provide several libraries in that area.
I tried to see if those libraries could be used for a piece of code I have in
my mind but I have a hard time figuring out how to start with it.
I don't know if it is because I try to apply metaprogramming techniques in a
use case where they doesn't fit or because of my lack of experience with
these tools. I'm posting my use case here to get some help and advice about

In a library I provide two classes:

1) An abstract base class (let's call it Base) from which user will derive
their own classes.
2) A manager class responsible for manipulating instances of classes derived
from Base.

The user, in his application, create an an arbitrary number of classes derived
from Base. Let's call them A, B and C for example.
He create a typelist containing all those classes and passes it as a parameter
to the manager class:

typedef boost::mpl::list< A, B, C > my_types ;
typedef Manager< my_types> my_manager ;

When an instance of my_manager is created I would like to automatically create
one instance of each type present in the typelist and these instances should
be stored in a container where I could access them later. Something like the

template < class Typelist >
class Manager
        Manager( void ) ;

        // .....

        std::vector< Base * > container_ ;

        // ....
} ;

template < class Typelist >
Manager< Typelist >::Manager( void )
        // This is not C++, it is pseudo-code that shows what I would
        // like to achieve.

        FOR EACH Typelist item i
                Base *b = new Typelist[i]
                container_.push_back( b ) ;

So, at compile-time, some code should be generated to do what I wrote in
pseudo-code in the constructor of Manager.
Does this make any sense ? And if it is, could someone help me transform
transform the pseudo-code in the constructor of manager to real code ?

Thanks for any help you could provide,

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at