I have a template class that get two template arguments.
template <class T,class A>
class Z{...};
Say I have four types of T, and same amount for A. So, there are 16 options!
If I want to choose one of them at runtime, I need to write a huge and disgusting case.
I know that C++ doesn’t support runtime templates.
Is there another way to do it?
A way to achieve something kind of similar is to add dependencies to
class Zand provide these at runtime — which is known as the Strategy pattern.Of course this means that
class Zis no longer templated with all that this entails. But there’s really no way to have your pie and eat it too: templates are a compile-time construct, while you are asking about ways to configure something at runtime. You cannot configure a type at runtime, only an object.