-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathtyped_enum1.cxx
More file actions
39 lines (32 loc) · 818 Bytes
/
typed_enum1.cxx
File metadata and controls
39 lines (32 loc) · 818 Bytes
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
#include <cstdio>
enum typename my_types_t {
double,
int,
char*,
int[5],
char,
};
template<typename type_t>
void print_enum_types1() {
printf("%s (for loop):\n", @type_string(type_t));
// Use a for loop.
@meta for(int i = 0; i < @enum_count(type_t); ++i)
printf(" %s\n", @enum_type_string(type_t, i));
}
template<typename type_t>
void print_enum_types2() {
printf("%s (for-enum):\n", @type_string(type_t));
// Use a for-enum loop.
@meta for enum(type_t e : type_t)
printf(" %s\n", @enum_type_string(e));
}
template<typename type_t>
void print_enum_types3() {
printf("%s (pack):\n", @type_string(type_t));
printf(" %s\n", @enum_type_strings(type_t))...;
}
int main() {
print_enum_types1<my_types_t>();
print_enum_types2<my_types_t>();
print_enum_types3<my_types_t>();
}