if( auto id:{k_b0,k_b1}){
auto baseIndex = 0;
auto count = false;
if(!rmt){
switch(src){
case a: {if(slow) {count = Getconfig(); baseindex =0;}
else {count = GetslowConfig(); baseindex =4;}}break;
case b: {if(slow) {count = Getconfig(); baseindex =0;}
else {count = GetslowConfig(); baseindex =4;}}break;
case c: {if(slow) {count = Getconfig(); baseindex =0;}
else {count = GetslowConfig(); baseindex =4;}}break;
default : count = GetdefaultConfigone(); break;
}}
else{
switch(src){
case a: {if(slow) {count = Getconfigrmt(); baseindex =1;}
else {count = GetslowConfigrmt(); baseindex =5;}}break;
case b: {if(slow) {count = Getconfigrmt(); baseindex =1;}
else {count = GetslowConfigrmt(); baseindex =5;}}break;
case c: {if(slow) {count = Getconfigrmt(); baseindex =1;}
else {count = GetslowConfigrmt(); baseindex =5;}}break;
default : count = GetdefaultConfigtwo(); break;
}}
sample(baseindex, count, id);
}
Note: need to call two different default cases here I have so far tried to use the fall-through switch statement to make this better. Still, this looks terrible. Open to any ideas on how to make this better. P:S I didn't write this code.
Without seeing or modifying any of the other code, assuming what you had works, you could do something like:
Switch statements are great, but they don't seem appropriate here. There is a lot of duplication for which function to call and what to set the baseindex to when it really came down to a few conditions.
The default case is if src is not a, b, or c, and just sets count depending on rmt. You can separate the default at the top.
Then, the case a, b, or c are within the first else. The differences between these were rmt and then slow.
The next improvement I could suggest would be to combine some of these 6 config functions, as I'm sure they have a lot of overlapping similarity. You could then just pass the rmt/slow values in as arguments. To get multiple return values, you can pass baseIndex/count by reference, or use a class/struct.
Finally, I don't see why you use the
autotype for something so simple as an int or bool, I think you should explicitly use the actual type. Also, I'm not sure the outer if,if (auto id: {k_b0,k_b1})is correct.