-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathtest3.cxx
40 lines (32 loc) · 951 Bytes
/
test3.cxx
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
#include "format.hxx"
enum class shape_t {
circle,
square,
octagon,
triangle,
};
int main() {
shape_t shapes[] {
shape_t::square,
shape_t::octagon,
shape_t::triangle,
(shape_t)27
};
// Print the enums in the array with default settings. The enumerator names
// are printed when available.
"shapes = {shapes}\n"_print;
// Center the enum names and use '~' to fill.
"shapes = {shapes:~^15}\n"_print;
// Use reflection to print all enum names in a loop.
"Your enum names are:\n"_print;
int counter = 0;
@meta for enum(shape_t e : shape_t)
"{counter++}: {@enum_name(e)}\n"_print;
// Print all enum names using format pack expansion. This puts them
// all in a collection.
"enum names = {...@enum_names(shape_t)}\n"_print;
// Use 12-character width and center. This applies to
// each element in the pack expansion.
"enum names = {...@enum_names(shape_t):^12}\n"_print;
return 0;
}