|
45 | 45 | #define fm__xor_11 0 |
46 | 46 |
|
47 | 47 | #define fm_if(x, y, ...) fm_cat(fm__if_, x)(y, __VA_ARGS__) |
48 | | -#define fm_iif(x) fm_cat(fm__if_, x) |
49 | 48 | #define fm__if_1(y, ...) y |
50 | 49 | #define fm__if_0(y, ...) __VA_ARGS__ |
51 | 50 | #define fm_when(x) fm_cat(fm__when_, x) |
52 | 51 | #define fm__when_1(...) __VA_ARGS__ |
53 | 52 | #define fm__when_0(...) |
| 53 | +#define fm_iif(x) fm_cat(fm__iif_, x) |
| 54 | +#define fm__iif_1(...) __VA_ARGS__ fm_empty |
| 55 | +#define fm__iif_0(...) fm_expand |
54 | 56 |
|
55 | 57 | #define fm_va_comma(...) \ |
56 | 58 | fm_cat(fm__va_comma_, fm_va_01(__VA_ARGS__))() |
57 | 59 | #define fm__va_comma_0() |
58 | 60 | #define fm__va_comma_1() , |
59 | 61 |
|
60 | 62 | #define fm_or_default(...) \ |
61 | | - fm_cat(fm__or_default_, fm_va_01(__VA_ARGS__))(__VA_ARGS__) |
62 | | -#define fm__or_default_0(...) fm_expand |
63 | | -#define fm__or_default_1(...) __VA_ARGS__ fm_empty |
| 63 | + fm_iif(fm_va_01(__VA_ARGS__))(__VA_ARGS__) |
64 | 64 |
|
65 | 65 | #define fm__primitive_compare(x, y) fm_is_tuple(COMPARE_##x(COMPARE_##y)(())) |
66 | 66 | #define fm__is_comparable(x) fm_is_tuple(fm_cat(COMPARE_,x)(())) |
67 | 67 | #define fm_not_equal(x, y) \ |
68 | | - fm_iif(fm_and(fm__is_comparable(x),fm__is_comparable(y))) \ |
69 | | - (fm__primitive_compare, 1 fm_empty)(x, y) |
| 68 | + fm_if(fm_and(fm__is_comparable(x),fm__is_comparable(y)), fm__primitive_compare, 1 fm_empty)(x, y) |
70 | 69 | #define fm_equal(x, y) \ |
71 | 70 | fm_compl(fm_not_equal(x, y)) |
72 | 71 |
|
|
133 | 132 |
|
134 | 133 | // recursion handle |
135 | 134 | #define fm_defer(id) id fm_empty() |
136 | | -#define fm_recurs(id) id fm_defer(fm_empty)() |
| 135 | +#define fm_recurs(id) id fm_empty fm_empty() () |
| 136 | +#define fm_recurs2(a,b) fm_cat fm_empty fm_empty() () (a,b) |
137 | 137 |
|
138 | 138 | #if __STRICT_ANSI__ |
139 | | -#define fm__is_emptyfirst(x, ...) fm_iif(fm_is_tuple(x))(0, fm__is_emptyfirst_impl(x)) |
| 139 | +#define fm__is_emptyfirst(x, ...) fm_if(fm_is_tuple(x), 0, fm__is_emptyfirst_impl(x)) |
140 | 140 | #define fm__is_emptyfirst_impl(x,...) fm_tuple_2((\ |
141 | 141 | fm__is_emptyfirst_do1 x (fm__is_emptyfirst_do2), 1, 0)) |
142 | 142 | #define fm__is_emptyfirst_do1(F) F() |
|
161 | 161 | #define fm_foreach(macro, ...) \ |
162 | 162 | fm_when(fm_va_01(__VA_ARGS__))( \ |
163 | 163 | fm_apply_1(macro, __VA_ARGS__) \ |
164 | | - fm_recurs(fm_cat) (fm_, foreach) (\ |
| 164 | + fm_recurs2(fm_, foreach) (\ |
165 | 165 | macro, fm_tail(__VA_ARGS__) \ |
166 | 166 | ) \ |
167 | 167 | ) |
168 | 168 |
|
169 | 169 | #define fm_foreach_arg(macro, arg, ...) \ |
170 | 170 | fm_when(fm_va_01(__VA_ARGS__))( \ |
171 | 171 | fm_apply_2(macro, arg, __VA_ARGS__) \ |
172 | | - fm_recurs(fm_cat) (fm_, foreach_arg) (\ |
| 172 | + fm_recurs2(fm_, foreach_arg) (\ |
173 | 173 | macro, arg, fm_tail(__VA_ARGS__) \ |
174 | 174 | ) \ |
175 | 175 | ) |
176 | 176 |
|
177 | | -#define fm_catx(x, y) fm_cat_impl(x, y) |
178 | 177 | #define fm_foreach_comma(macro, ...) \ |
179 | 178 | fm_when(fm_va_01(__VA_ARGS__))( \ |
180 | 179 | fm_apply_1(macro, __VA_ARGS__\ |
181 | 180 | )fm_if(fm_va_single(__VA_ARGS__), , fm__comma)\ |
182 | | - fm_recurs(fm_catx) (fm_, foreach_comma) (\ |
| 181 | + fm_recurs2(fm_, foreach_comma) (\ |
183 | 182 | macro, fm_tail(__VA_ARGS__) \ |
184 | 183 | ) \ |
185 | 184 | ) |
|
188 | 187 | #define fm_foreach_tuple(macro, ...) \ |
189 | 188 | fm_when(fm_va_01(__VA_ARGS__))( \ |
190 | 189 | fm_apply_tuple_1(macro, __VA_ARGS__) \ |
191 | | - fm_recurs(fm_cat) (fm_, foreach_tuple) (\ |
| 190 | + fm_recurs2(fm_, foreach_tuple) (\ |
192 | 191 | macro, fm_tail(__VA_ARGS__) \ |
193 | 192 | ) \ |
194 | 193 | ) |
195 | 194 |
|
196 | 195 | #define fm_foreach_tuple_arg(macro, arg, ...) \ |
197 | 196 | fm_when(fm_va_01(__VA_ARGS__))( \ |
198 | 197 | fm_apply_tuple_2(macro, arg, __VA_ARGS__) \ |
199 | | - fm_recurs(fm_cat) (fm_, foreach_tuple_arg) (\ |
| 198 | + fm_recurs2(fm_, foreach_tuple_arg) (\ |
200 | 199 | macro, arg, fm_tail(__VA_ARGS__) \ |
201 | 200 | ) \ |
202 | 201 | ) |
|
205 | 204 | fm_when(fm_va_01(__VA_ARGS__))( \ |
206 | 205 | fm_apply_tuple_1(macro, __VA_ARGS__\ |
207 | 206 | )fm_if(fm_va_single(__VA_ARGS__), fm_empty(), fm__comma)\ |
208 | | - fm_recurs(fm_cat) (fm_, foreach_tuple_comma) (\ |
| 207 | + fm_recurs2(fm_, foreach_tuple_comma) (\ |
209 | 208 | macro, fm_tail(__VA_ARGS__) \ |
210 | 209 | ) \ |
211 | 210 | ) |
|
214 | 213 | #define fm_eval_foreach(macro, ...) \ |
215 | 214 | fm_eval(fm_foreach(macro, __VA_ARGS__)) |
216 | 215 |
|
| 216 | +#define fm_eval_foreach_comma(macro, ...) \ |
| 217 | + fm_eval(fm_foreach_comma(macro, __VA_ARGS__)) |
| 218 | + |
217 | 219 | #define fm_eval_foreach_arg(macro, arg, ...) \ |
218 | 220 | fm_eval(fm_foreach_arg(macro, arg, __VA_ARGS__)) |
219 | 221 |
|
|
0 commit comments