Debian Codegraph @

cc/cpp/tests/test20

raw
1 #ifndef FOREACH_H
2 #define FOREACH_H
3
4 #define _CONCAT(a, b) a##b
5 #define CONCAT(a, b) _CONCAT(a, b)
6 #define CONCAT2(a, b) _CONCAT(a, b)
7
8 #define _CONCAT3(a, b, c) a##b##c
9 #define CONCAT3(a, b, c) _CONCAT3(a, b, c)
10
11 #define _CONCAT4(a, b, c, d) a##b##c##d
12 #define CONCAT4(a, b, c, d) _CONCAT4(a, b, c, d)
13
14 #define EXPAND(x) x
15
16 #define _COUNT_ARGS( _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, \
17 _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \
18 _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \
19 _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, \
20 _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, \
21 _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, \
22 _61, _62, _63, _64, N, ...) N
23 #define COUNT_ARGS(...) \
24 _COUNT_ARGS(__VA_ARGS__, 64, 63, 62, 61, 60, \
25 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, \
26 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, \
27 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, \
28 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, \
29 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, \
30 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
31
32 #define FOR_EACH_1(func, x) \
33 func(x)
34 #define FOR_EACH_2(func, x, ...) \
35 func(x), EXPAND(FOR_EACH_1(func, __VA_ARGS__))
36 #define FOR_EACH_3(func, x, ...) \
37 func(x), EXPAND(FOR_EACH_2(func, __VA_ARGS__))
38 #define FOR_EACH_4(func, x, ...) \
39 func(x), EXPAND(FOR_EACH_3(func, __VA_ARGS__))
40 #define FOR_EACH_5(func, x, ...) \
41 func(x), EXPAND(FOR_EACH_4(func, __VA_ARGS__))
42 #define FOR_EACH_6(func, x, ...) \
43 func(x), EXPAND(FOR_EACH_5(func, __VA_ARGS__))
44 #define FOR_EACH_7(func, x, ...) \
45 func(x), EXPAND(FOR_EACH_6(func, __VA_ARGS__))
46 #define FOR_EACH_8(func, x, ...) \
47 func(x), EXPAND(FOR_EACH_7(func, __VA_ARGS__))
48 #define FOR_EACH_9(func, x, ...) \
49 func(x), EXPAND(FOR_EACH_8(func, __VA_ARGS__))
50 #define FOR_EACH_10(func, x, ...) \
51 func(x), EXPAND(FOR_EACH_9(func, __VA_ARGS__))
52 #define FOR_EACH_11(func, x, ...) \
53 func(x), EXPAND(FOR_EACH_10(func, __VA_ARGS__))
54 #define FOR_EACH_12(func, x, ...) \
55 func(x), EXPAND(FOR_EACH_11(func, __VA_ARGS__))
56 #define FOR_EACH_13(func, x, ...) \
57 func(x), EXPAND(FOR_EACH_12(func, __VA_ARGS__))
58 #define FOR_EACH_14(func, x, ...) \
59 func(x), EXPAND(FOR_EACH_13(func, __VA_ARGS__))
60 #define FOR_EACH_15(func, x, ...) \
61 func(x), EXPAND(FOR_EACH_14(func, __VA_ARGS__))
62 #define FOR_EACH_16(func, x, ...) \
63 func(x), EXPAND(FOR_EACH_15(func, __VA_ARGS__))
64 #define FOR_EACH_17(func, x, ...) \
65 func(x), EXPAND(FOR_EACH_16(func, __VA_ARGS__))
66 #define FOR_EACH_18(func, x, ...) \
67 func(x), EXPAND(FOR_EACH_17(func, __VA_ARGS__))
68 #define FOR_EACH_19(func, x, ...) \
69 func(x), EXPAND(FOR_EACH_18(func, __VA_ARGS__))
70 #define FOR_EACH_20(func, x, ...) \
71 func(x), EXPAND(FOR_EACH_19(func, __VA_ARGS__))
72 #define FOR_EACH_21(func, x, ...) \
73 func(x), EXPAND(FOR_EACH_20(func, __VA_ARGS__))
74 #define FOR_EACH_22(func, x, ...) \
75 func(x), EXPAND(FOR_EACH_21(func, __VA_ARGS__))
76 #define FOR_EACH_23(func, x, ...) \
77 func(x), EXPAND(FOR_EACH_22(func, __VA_ARGS__))
78 #define FOR_EACH_24(func, x, ...) \
79 func(x), EXPAND(FOR_EACH_23(func, __VA_ARGS__))
80 #define FOR_EACH_25(func, x, ...) \
81 func(x), EXPAND(FOR_EACH_24(func, __VA_ARGS__))
82 #define FOR_EACH_26(func, x, ...) \
83 func(x), EXPAND(FOR_EACH_25(func, __VA_ARGS__))
84 #define FOR_EACH_27(func, x, ...) \
85 func(x), EXPAND(FOR_EACH_26(func, __VA_ARGS__))
86 #define FOR_EACH_28(func, x, ...) \
87 func(x), EXPAND(FOR_EACH_27(func, __VA_ARGS__))
88 #define FOR_EACH_29(func, x, ...) \
89 func(x), EXPAND(FOR_EACH_28(func, __VA_ARGS__))
90 #define FOR_EACH_30(func, x, ...) \
91 func(x), EXPAND(FOR_EACH_29(func, __VA_ARGS__))
92 #define FOR_EACH_31(func, x, ...) \
93 func(x), EXPAND(FOR_EACH_30(func, __VA_ARGS__))
94 #define FOR_EACH_32(func, x, ...) \
95 func(x), EXPAND(FOR_EACH_31(func, __VA_ARGS__))
96 #define FOR_EACH_33(func, x, ...) \
97 func(x), EXPAND(FOR_EACH_32(func, __VA_ARGS__))
98 #define FOR_EACH_34(func, x, ...) \
99 func(x), EXPAND(FOR_EACH_33(func, __VA_ARGS__))
100 #define FOR_EACH_35(func, x, ...) \
101 func(x), EXPAND(FOR_EACH_34(func, __VA_ARGS__))
102 #define FOR_EACH_36(func, x, ...) \
103 func(x), EXPAND(FOR_EACH_35(func, __VA_ARGS__))
104 #define FOR_EACH_37(func, x, ...) \
105 func(x), EXPAND(FOR_EACH_36(func, __VA_ARGS__))
106 #define FOR_EACH_38(func, x, ...) \
107 func(x), EXPAND(FOR_EACH_37(func, __VA_ARGS__))
108 #define FOR_EACH_39(func, x, ...) \
109 func(x), EXPAND(FOR_EACH_38(func, __VA_ARGS__))
110 #define FOR_EACH_40(func, x, ...) \
111 func(x), EXPAND(FOR_EACH_39(func, __VA_ARGS__))
112 #define FOR_EACH_41(func, x, ...) \
113 func(x), EXPAND(FOR_EACH_40(func, __VA_ARGS__))
114 #define FOR_EACH_42(func, x, ...) \
115 func(x), EXPAND(FOR_EACH_41(func, __VA_ARGS__))
116 #define FOR_EACH_43(func, x, ...) \
117 func(x), EXPAND(FOR_EACH_42(func, __VA_ARGS__))
118 #define FOR_EACH_44(func, x, ...) \
119 func(x), EXPAND(FOR_EACH_43(func, __VA_ARGS__))
120 #define FOR_EACH_45(func, x, ...) \
121 func(x), EXPAND(FOR_EACH_44(func, __VA_ARGS__))
122 #define FOR_EACH_46(func, x, ...) \
123 func(x), EXPAND(FOR_EACH_45(func, __VA_ARGS__))
124 #define FOR_EACH_47(func, x, ...) \
125 func(x), EXPAND(FOR_EACH_46(func, __VA_ARGS__))
126 #define FOR_EACH_48(func, x, ...) \
127 func(x), EXPAND(FOR_EACH_47(func, __VA_ARGS__))
128 #define FOR_EACH_49(func, x, ...) \
129 func(x), EXPAND(FOR_EACH_48(func, __VA_ARGS__))
130 #define FOR_EACH_50(func, x, ...) \
131 func(x), EXPAND(FOR_EACH_49(func, __VA_ARGS__))
132 #define FOR_EACH_51(func, x, ...) \
133 func(x), EXPAND(FOR_EACH_50(func, __VA_ARGS__))
134 #define FOR_EACH_52(func, x, ...) \
135 func(x), EXPAND(FOR_EACH_51(func, __VA_ARGS__))
136 #define FOR_EACH_53(func, x, ...) \
137 func(x), EXPAND(FOR_EACH_52(func, __VA_ARGS__))
138 #define FOR_EACH_54(func, x, ...) \
139 func(x), EXPAND(FOR_EACH_53(func, __VA_ARGS__))
140 #define FOR_EACH_55(func, x, ...) \
141 func(x), EXPAND(FOR_EACH_54(func, __VA_ARGS__))
142 #define FOR_EACH_56(func, x, ...) \
143 func(x), EXPAND(FOR_EACH_55(func, __VA_ARGS__))
144 #define FOR_EACH_57(func, x, ...) \
145 func(x), EXPAND(FOR_EACH_56(func, __VA_ARGS__))
146 #define FOR_EACH_58(func, x, ...) \
147 func(x), EXPAND(FOR_EACH_57(func, __VA_ARGS__))
148 #define FOR_EACH_59(func, x, ...) \
149 func(x), EXPAND(FOR_EACH_58(func, __VA_ARGS__))
150 #define FOR_EACH_60(func, x, ...) \
151 func(x), EXPAND(FOR_EACH_59(func, __VA_ARGS__))
152 #define FOR_EACH_61(func, x, ...) \
153 func(x), EXPAND(FOR_EACH_60(func, __VA_ARGS__))
154 #define FOR_EACH_62(func, x, ...) \
155 func(x), EXPAND(FOR_EACH_61(func, __VA_ARGS__))
156 #define FOR_EACH_63(func, x, ...) \
157 func(x), EXPAND(FOR_EACH_62(func, __VA_ARGS__))
158 #define FOR_EACH_64(func, x, ...) \
159 func(x), EXPAND(FOR_EACH_63(func, __VA_ARGS__))
160 #define FOR_EACH(func, ...) \
161 EXPAND(CONCAT(FOR_EACH_, COUNT_ARGS(__VA_ARGS__))(func, __VA_ARGS__))
162
163 #endif
164
165 #define SQ(x) (x * x)
166
167 int squares[] = FOR_EACH(SQ, 1, 2, 3, 4, 5, 6, 7, 8);