I have a set of five boolean values. If more than one of these are true I want to excecute a particular function. What is the most elegant way you can think of that would al
Casting to ints and summing should work, but it's a bit ugly and in some languages may not be possible.
How about something like
int count = (bool1? 1:0) + (bool2? 1:0) + (bool3? 1:0) + (bool4? 1:0) + (bool5? 1:0);
Or if you don't care about space, you could just precompute the truth table and use the bools as indices:
if (morethanone[bool1][bool2][bool3][bool4][bool5]) {
... do something ...
}