-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFor.cpp
82 lines (67 loc) · 1.31 KB
/
For.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
* \file For.cpp
* \brief
*
* \review
*/
#include <StdStream/StdStream.h>
#include <StdTest/StdTest.h>
#include <Stl.h>
//-------------------------------------------------------------------------------------------------
enum Type
{
a = 1,
b = 2,
c = 3,
Last = c + 1
};
static const Type All[] {a, b, c};
void trace(const Type e)
{
std::cout << e << ",";
}
//-------------------------------------------------------------------------------------------------
int main(int, char **)
{
// all
for (const auto e : All) {
trace(e);
}
std::cout << std::endl;
// some
for (const auto e : {a, c}) {
trace(e);
}
std::cout << std::endl;
// all
std::for_each(std::begin(All), std::end(All), trace);
std::cout << std::endl;
// for
for (Type e = a; e != Last; e = Type(e + 1)) {
trace(e);
}
std::cout << std::endl;
// TODO: for (bits)
enum BitType
{
First,
None = First,
Green = 0x1,
White = 0x2,
Blue = 0x4,
Last = 0x8
};
// std::cout << BitType(Green << 1) << std::endl;
// for (BitType e = First; e != Last; e = BitType(e << 1)) {
// std::cout << (int)e << ",";
// }
// std::cout << std::endl;
return EXIT_SUCCESS;
}
//--------------------------------------------------------------------------------------------------
#if OUTPUT
1,2,3,
1,3,
1,2,3,
1,2,3,
#endif