|
Boost : |
From: Sebastian Faust (sfaust_at_[hidden])
Date: 2003-10-31 07:22:35
Hi,
I wanna develope an factory class template which takes as template argument
a typelist and creates me then iterative objects of the types in the
typelist. The different objects will be connected ( like in the chain of
responsibility pattern ), so that after the creation process I only will get
back one pointer to the beginning object of the chain.
I read about the boost::mpl -library and was very impressed, sadly I am
absolutly new to metaprogramming so I really have some problems to solve my
problem, so I really would be thankful for any help.
To show my problem I give a standard example about what I wanna do:
class vehicle
{
public:
vehicle(vehicle* successor) : m_successor(successor) {}
virtual vehicle* create(vehicle* successor) = 0;
vehicle* m_successor;
};
class car : public vehicle
{
public:
car(car* successor) : vehicle(successor) {}
virtual vehicle* create(vehicle* successor)
{
return new car(successor);
}
};
class bicycle : public vehicle
{
public:
bicycle (bicycle * successor) : vehicle(successor) {}
virtual vehicle* create(vehicle* successor)
{
return new bicycle (successor);
}
};
class train : public vehicle
{
public:
train (train * successor) : vehicle(successor) {}
virtual vehicle* create(vehicle* successor)
{
return new train (successor);
}
};
With the help of some from the ACCU mailinglist I could find out to use the
for_each template to iterate over a boost::mpl::list, but how can I get the
returned value from the method create?
Thanks a lot in advance
Sebastian
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk