Since the conditions are Boolean and apparently independent, consider them as bits in a word and switchon them:
#include <cstdio>
#define COMPOSE(a,b,c) ( ((!!(a)) << 2) | ((!!(b))<<1) | (!!(c)) )
int f(int i, int j, int k) {
switch(COMPOSE( i==j, i+j<k, k!=42)) {
case COMPOSE(true, true, true):
printf("yo\n");
break;
case COMPOSE(true, true, false):
printf("ye\n");
break;
case COMPOSE(true, false, true):
printf("ya\n");
break;
}
}
int main () {
f(1,1,1);
}
source
share