Some C ++ compilers still support the syntax today - 8 years after this question was originally asked. It surprises me.
I recognized Pascal in 2012, Pascal has a range designation. Then something prompted me to try a similar syntax with C ++, then it works unexpectedly fabulously.
The compiler on my laptop is g ++ (GCC) 6.4.0 (from the Cygwin project) std = C ++ 17
There is a working example that I wrote in a hurry. repl.it
In addition, the source code is attached as follows:
#include <iostream>
using namespace std;
#define ok(x) cout << "It works in range(" << x << ")" << endl
#define awry cout << "It does\'t work." << endl
int main() {
char ch1 = 'b';
switch(ch1) {
case 'a' ... 'f': ok("a..f"); break;
case 'g' ... 'z': ok("g..z"); break;
default: awry;
}
int int1 = 10;
switch(int1) {
case 1 ... 10: ok("1..10"); break;
case 11 ... 20: ok("11..20"); break;
default: awry;
}
return 0;
}
source
share