-
Notifications
You must be signed in to change notification settings - Fork 1
/
macro-args-iter.h
66 lines (62 loc) · 2.38 KB
/
macro-args-iter.h
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
#define STRINGIZE(arg) STRINGIZE1(arg)
#define STRINGIZE1(arg) STRINGIZE2(arg)
#define STRINGIZE2(arg) #arg
#define CONCATENATE(arg1, arg2) CONCATENATE1(arg1, arg2)
#define CONCATENATE1(arg1, arg2) CONCATENATE2(arg1, arg2)
#define CONCATENATE2(arg1, arg2) arg1##arg2
#define FOR_EACH_1(what, ...) what(__VA_ARGS__);
#define FOR_EACH_2(what, x, ...) \
what(x); \
FOR_EACH_1(what, __VA_ARGS__);
#define FOR_EACH_3(what, x, ...) \
what(x); \
FOR_EACH_2(what, __VA_ARGS__);
#define FOR_EACH_4(what, x, ...) \
what(x); \
FOR_EACH_3(what, __VA_ARGS__);
#define FOR_EACH_5(what, x, ...) \
what(x); \
FOR_EACH_4(what, __VA_ARGS__);
#define FOR_EACH_6(what, x, ...) \
what(x); \
FOR_EACH_5(what, __VA_ARGS__);
#define FOR_EACH_7(what, x, ...) \
what(x); \
FOR_EACH_6(what, __VA_ARGS__);
#define FOR_EACH_8(what, x, ...) \
what(x); \
FOR_EACH_7(what, __VA_ARGS__);
#define FOR_EACH_9(what, x, ...) \
what(x); \
FOR_EACH_8(what, __VA_ARGS__);
#define FOR_EACH_10(what, x, ...) \
what(x); \
FOR_EACH_9(what, __VA_ARGS__);
#define FOR_EACH_11(what, x, ...) \
what(x); \
FOR_EACH_10(what, __VA_ARGS__);
#define FOR_EACH_12(what, x, ...) \
what(x); \
FOR_EACH_11(what, __VA_ARGS__);
#define FOR_EACH_13(what, x, ...) \
what(x); \
FOR_EACH_12(what, __VA_ARGS__);
#define FOR_EACH_14(what, x, ...) \
what(x); \
FOR_EACH_13(what, __VA_ARGS__);
#define FOR_EACH_15(what, x, ...) \
what(x); \
FOR_EACH_14(what, __VA_ARGS__);
#define FOR_EACH_16(what, x, ...) \
what(x); \
FOR_EACH_15(what, __VA_ARGS__);
#define FOR_EACH_NARG(...) FOR_EACH_NARG_(__VA_ARGS__, FOR_EACH_RSEQ_N())
#define FOR_EACH_NARG_(...) FOR_EACH_ARG_N(__VA_ARGS__)
#define FOR_EACH_ARG_N(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, \
_14, _15, _16, N, ...) \
N
#define FOR_EACH_RSEQ_N() \
16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
#define FOR_EACH_(N, what, ...) CONCATENATE(FOR_EACH_, N)(what, __VA_ARGS__)
#define FOR_EACH(what, ...) \
FOR_EACH_(FOR_EACH_NARG(__VA_ARGS__), what, __VA_ARGS__)