That sucks. Switch needs an integer type, not a bool. It would be much more flexible if it evaluated a bool.
There are ways I can think of to hammer this into a shape I would like, but it isn't nearly as clean as in other languages.
The need to return either an integer or a conditional that evaluates to an integer is bugnuts. This is probably to keep people from making switch statements that have multiple possible cases that would fire though.
Still, one can "batshit-fake-it", and make "ranges" using something like the integer divide operator.
Something a bit like this?
int main()
{
int i = rng(10,100);
int iRange = i /10;
switch (iRange) {
case 1: std::cout << "i is between 10 and 20";
case 2: std::cout << "i is between 20 and 30";
case 3: std::cout << "i is between 30 and 40";
case 4: std::cout << "i is between 40 and 50";
case 5: std::cout << "i is between 50 and 60";
case 6: std::cout << "i is between 60 and 70";
case default: std::cout << "Catchall for when none of the above hit";
}
}
It relies on the fact that integer division discards the remainder, and just tells you how many times i is divisible by 10, as an integer expression.
eg, 10, 11, 12,13,14,15,16,17,18, and 19 all evaluate as "1" when integer divided by 10.
Still bullshit though. I would much rather that it evaluate a boolean true condition, rather than needing an implicit integer expression.