-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSwitchCase.cpp
56 lines (48 loc) · 1.19 KB
/
SwitchCase.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* \file SwitchCase.cpp.cpp
* \brief Modern switch / case
*/
#include <StdStream/StdStream.h>
#include <StdTest/StdTest.h>
#include <Stl.h>
//---------------------------------------------------------------------------
int
main()
{
// error: range expressions in switch statements are non-standard [-Werror=pedantic]
#if 0
const int ints[] {-1, 0, 2, 3, 4, 6, 7, 200};
for (const auto it_int : ints) {
std::cout << it_int << " -> ";
switch (it_int) {
case 0 ... 3:
std::cout << "[0 ... 3]" << std::endl;
break;
case 4 ... 5:
std::cout << "[4 ... 5]" << std::endl;
break;
case 6:
std::cout << "[6]" << std::endl;
break;
case 7 ... INT_MAX:
std::cout << "[7 ... INT_MAX]" << std::endl;
break;
default:
std::cout << "[default]" << std::endl;
break;
}
}
#endif
return EXIT_SUCCESS;
}
//---------------------------------------------------------------------------
#if 0
-1 -> [default]
0 -> [0 ... 3]
2 -> [0 ... 3]
3 -> [0 ... 3]
4 -> [4 ... 5]
6 -> [6]
7 -> [7 ... INT_MAX]
200 -> [7 ... INT_MAX]
#endif