I have have a factory class, which needs to instantiate several templates with consecutive template parameters which are simple integers. How can I instantiate such template functions without unrolling the entire loop?
The only thing that can think of is using boost pre-processor. Can you recommend something else, which does not depend on the preprocessor?
thanks
Template parameters have to be compile-time constant. Currently no compiler considers a loop counter variable to be a constant, even after it is unrolled. This is probably because the constness has to be known during template instantation, which happens far before loop unrolling.
But it is possible to construct a “recursive” template and with a specialization as end condition. But even then the loop boundary needs to be compile time constant.
will create ten template classes from loop<10> to loop<1>.