Scott Meyers wrote:
Given some base class,
class Base { virtual ~Base(){} };
I want to be able to implement this:
template<typename Seq> const Base& createObject() { // return an object that inherits from Base and every type in Seq }
The problem is how to create the type of object I want.
mpl::inherit is almost what I need, but it takes as template parameters each type to inherit from, and I don't have discrete types, I have a sequence of types. mpl::inherit_linearly takes a sequence and would work for my purposes (which is to create an object that I can later check via dynamic_cast to see if it inherits from a given type), but it works only with forward sequences, and I'll typically have an mpl::set. I could copy the contents of Seq into an mpl::vector and go from there, but that seems kind of gross.
Is there a good way to solve this problem that I am overlooking?
An Associative Sequence is a Forward Sequence, so 'inherit_linearly< a_set, inherit<_1,_2> >::type' works. Regards, Tobias