I need to write the same code depending on the compile-time constant parameter, something like:
map["text 0"] = vec[0];
map["text 1"] = vec[1];
...
map["text n"] = vec[n];
The problem is that I don’t know nwhen I write the code, I get it as a template parameter. The obvious solution is to use one loop and generate "text k"within the loop and use vec[k], but this is the overhead of the run time when it needs to be done at compile time. Another solution would be to specialize the function for different values n, but in this way I will have to write the same code manually several times, and there is no reason to create it.
I know that there are several smart macros that can repeat such things N times (for example, a BOOST_PP_REPEATmacro family), but I can not find one solution for my specific problem.
Do you have a solution to this problem?
source
share