Answer the question
In order to leave comments, you need to log in
How to save a list of class types, which then (at runtime) should be called in a template parameter?
There is some hierarchy of abstract base classes with a set of concrete classes;
Foo1Base:
Foo1Concrete1; Foo1Concrete2; ...
Foo2Base:
Foo2Concrete1; Foo2Concrete2; ...
template <class T> FooFactory {
void Register(int id);
T* Create(int),
vector<int> GetAvaliable();
}
Factory<Foo1Base>.Create(...)
BarBase:
BarConcrete1;BarConcrete2;...
for( foo_type : vector<FooTypeHolder>) {
auto foos_ = FooFactory <foo_type >.GetAvaliable()
}
Answer the question
In order to leave comments, you need to log in
www.boost.org/doc/libs/1_59_0/libs/mpl/doc/refmanu... perhaps something from boost mpl will help you. But it is highly discouraged to do this in pruduction code. Such code is usually very expensive to maintain.
Templates are instantiated at compilation. Those. you cannot do anything with templates in runtime, because there are no templates in runtime.
Dig towards variadic template + loop
stackoverflow.com/questions/7230621/how-can-i-iter...
It smacks of dependency injection. Look at https://github.com/boost-experimental/di or https://github.com/google/fruit
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question