You cannot. Template arguments have to be defined at compile-time.
To work around this, you can look at this post and answer: Specify template parameters at runtime
The idea is to use if
statements to check the runtime value:
template<class Engine, class UIntType>
independent_bits_engine CreateEngine(std::size_t w) {
if (w == 0) {
return independent_bits_engine<Engine, 0, UIntType>();
} else if (w == 1) {
return independent_bits_engine<Engine, 1, UIntType>();
}
Etc;
}
If W
can be a big value, you may want to use boost::preprocessor
to generate the ifs (example given in the link).
Note that, the more the maximum value of W
is big, the more independent_bits_engine
classes will be instantiated, and the more the compilation will be slow, so you may want to switch to a full runtime solution instead.