I am running simulations that require that I use templates for an int
parameter (D = the dimension of my systems). A typical simulation function is
template <int D> void simulation();
And when I want to specialize this template, I use a switch
switch(d){
case 2:
simulation<2>();
break;
case 3:
simulation<3>();
break;
// etc.
}
As far as I have one simulation function, it is OK. But imagine I have 10 of then (simul1, simul2,… simul10), and d can go from 2 to 10. I have to write ten time the same switch!
I was wondering if it were possible to factorize it, and have something like:
template <void (*fun)()> runSimulation(int d){
switch(d){
case 2:
fun<2>();
}
}
Of course <void (*fun)()>
doesn't do what I want, since fun
is a template<int>
. Is there a way to do it?