I have a class depending on an integer template parameter. At one point in my program I want to use one instantiation of this template, depending on a value of this paramet
You could use a variadic template, maybe like this:
#include
#include
int main(int argc, char * argv[])
{
if (argc != 2) { return EXIT_FAILURE; }
handle_cases<1, 3, 4, 9, 11>(std::stoi(argv[1]));
}
Implementation:
template struct IntList {};
void handle_cases(int, IntList<>) { /* "default case" */ }
template void handle_cases(int i, IntList)
{
if (I != i) { return handle_cases(i, IntList()); }
Wrapper w;
w.foo();
}
template void handle_cases(int i)
{
handle_cases(i, IntList());
}