I have a piece of c++11 code similar like below:
switch(var) {
case 1: dosomething(std::get<1>(tuple));
case 2: dosomething(std::get<2>(tuple));
...
}
Is there any way to remove this large switch ? Note that get<var>
does not work because var is not constant, but I know var is in small range i.e. (0-20).
Note that the point here is to avoid using an array that causes an array lookup...
EDIT:
well on the issue of performance, there is a discussion Performance of array of functions over if and switch statements
For my own purpose, I do not argue which one is better.
See Question&Answers more detail:os