By using c++ 14 or c++11, do we have an elegant approach to do the following task? Number of members and type of operations are determined by the template input value 'count'
template<int count>
class show{
public:
run(){
if (count == 1){
int x;
} else if(count ==2){
int x, y;
}else if(count ==3){
int x, y, z;
}
if (count == 1){
printf("res: %d \n", x);
} else if(count ==2){
printf("res: %d \n", x+y);
}else if(count ==3){
printf("res: %d \n", x+y+z);
}
}
};
Update: can we use partial specialization or something related to the template in this case?