I have the following C++ code with a fairly big switch statement (I am using a C++11 compiler):
void funtion(std::size_t i, other_args)
{
switch(i)
{
case 0:
templatedfunction<0>(other_args);
case 1:
templatedfunction<1>(other_args);
case 2:
templatedfunction<2>(other_args);
...............
//lots of other cases here
...............
case 100:
templatedfunction<100>(other_args);
}
}
where templatedfunction
is defined as
template<std::size_t T>
void templatedfunction(other_args){
//some code here
}
This is a lot of lines of code for describing a simple concept (i.e., call templatedfunction
with the same value as variable i
passed in its templated parameter). Is there a way in C++ to write this code more compactly? There should be a way to implement this long switch statement more compactly....Using templatedfunction<i>(other_args)
will not compile since i
is a variable and not a compile time constant. Thanks.
Aucun commentaire:
Enregistrer un commentaire