Metalang99 1.13.3
Full-blown preprocessor metaprogramming
Loading...
Searching...
No Matches
tuple.h
Go to the documentation of this file.
1
16#ifndef ML99_TUPLE_H
17#define ML99_TUPLE_H
18
19#include <metalang99/priv/bool.h>
20#include <metalang99/priv/tuple.h>
21#include <metalang99/priv/util.h>
22
23#include <metalang99/lang.h>
25
38#define ML99_tuple(...) ML99_call(ML99_tuple, __VA_ARGS__)
39
55#define ML99_tupleEval(...) ML99_call(ML99_tupleEval, __VA_ARGS__)
56
71#define ML99_untuple(x) ML99_call(ML99_untuple, x)
72
78#define ML99_untupleChecked(x) ML99_call(ML99_untupleChecked, x)
79
94#define ML99_untupleEval(x) ML99_call(ML99_untupleEval, x)
95
113#define ML99_isTuple(x) ML99_call(ML99_isTuple, x)
114
143#define ML99_isUntuple(x) ML99_call(ML99_isUntuple, x)
144
162#define ML99_tupleCount(x) ML99_call(ML99_tupleCount, x)
163
179#define ML99_tupleIsSingle(x) ML99_call(ML99_tupleIsSingle, x)
180
195#define ML99_tupleGet(i) ML99_PRIV_CAT(ML99_PRIV_tupleGet_, i)
196
211#define ML99_tupleTail(x) ML99_call(ML99_tupleTail, x)
212
225#define ML99_tupleAppend(x, ...) ML99_call(ML99_tupleAppend, x, __VA_ARGS__)
226
239#define ML99_tuplePrepend(x, ...) ML99_call(ML99_tuplePrepend, x, __VA_ARGS__)
240
244#define ML99_tupleForEach(f, x) ML99_call(ML99_tupleForEach, f, x)
245
249#define ML99_tupleForEachI(f, x) ML99_call(ML99_tupleForEachI, f, x)
250
268#define ML99_assertIsTuple(x) ML99_call(ML99_assertIsTuple, x)
269
270#define ML99_TUPLE(...) (__VA_ARGS__)
271#define ML99_UNTUPLE(x) ML99_PRIV_EXPAND x
272#define ML99_IS_TUPLE(x) ML99_PRIV_IS_TUPLE(x)
273#define ML99_IS_UNTUPLE(x) ML99_PRIV_IS_UNTUPLE(x)
274#define ML99_TUPLE_COUNT(x) ML99_VARIADICS_COUNT(ML99_UNTUPLE(x))
275#define ML99_TUPLE_IS_SINGLE(x) ML99_VARIADICS_IS_SINGLE(ML99_UNTUPLE(x))
276#define ML99_TUPLE_GET(i) ML99_PRIV_CAT(ML99_PRIV_TUPLE_GET_, i)
277#define ML99_TUPLE_TAIL(x) ML99_VARIADICS_TAIL(ML99_UNTUPLE(x))
278#define ML99_TUPLE_APPEND(x, ...) (ML99_UNTUPLE(x), __VA_ARGS__)
279#define ML99_TUPLE_PREPEND(x, ...) (__VA_ARGS__, ML99_UNTUPLE(x))
280
281#ifndef DOXYGEN_IGNORE
282
283#define ML99_tuple_IMPL(...) v(ML99_TUPLE(__VA_ARGS__))
284#define ML99_tupleEval_IMPL(...) v((v(__VA_ARGS__)))
285#define ML99_untuple_IMPL(x) \
286 ML99_PRIV_IF(ML99_IS_TUPLE(x), ML99_PRIV_UNTUPLE_TERM, ML99_PRIV_NOT_TUPLE_ERROR)(x)
287#define ML99_untupleChecked_IMPL(x) ML99_untuple_IMPL(x)
288#define ML99_untupleEval_IMPL(x) ML99_PRIV_EXPAND x
289#define ML99_isTuple_IMPL(x) v(ML99_IS_TUPLE(x))
290#define ML99_isUntuple_IMPL(x) v(ML99_IS_UNTUPLE(x))
291#define ML99_tupleCount_IMPL(x) v(ML99_TUPLE_COUNT(x))
292#define ML99_tupleIsSingle_IMPL(x) v(ML99_TUPLE_IS_SINGLE(x))
293
294#define ML99_PRIV_UNTUPLE_TERM(x) v(ML99_UNTUPLE(x))
295
296#define ML99_PRIV_tupleGet_0(x) ML99_call(ML99_PRIV_tupleGet_0, x)
297#define ML99_PRIV_tupleGet_1(x) ML99_call(ML99_PRIV_tupleGet_1, x)
298#define ML99_PRIV_tupleGet_2(x) ML99_call(ML99_PRIV_tupleGet_2, x)
299#define ML99_PRIV_tupleGet_3(x) ML99_call(ML99_PRIV_tupleGet_3, x)
300#define ML99_PRIV_tupleGet_4(x) ML99_call(ML99_PRIV_tupleGet_4, x)
301#define ML99_PRIV_tupleGet_5(x) ML99_call(ML99_PRIV_tupleGet_5, x)
302#define ML99_PRIV_tupleGet_6(x) ML99_call(ML99_PRIV_tupleGet_6, x)
303#define ML99_PRIV_tupleGet_7(x) ML99_call(ML99_PRIV_tupleGet_7, x)
304
305#define ML99_PRIV_tupleGet_0_IMPL(x) v(ML99_TUPLE_GET(0)(x))
306#define ML99_PRIV_tupleGet_1_IMPL(x) v(ML99_TUPLE_GET(1)(x))
307#define ML99_PRIV_tupleGet_2_IMPL(x) v(ML99_TUPLE_GET(2)(x))
308#define ML99_PRIV_tupleGet_3_IMPL(x) v(ML99_TUPLE_GET(3)(x))
309#define ML99_PRIV_tupleGet_4_IMPL(x) v(ML99_TUPLE_GET(4)(x))
310#define ML99_PRIV_tupleGet_5_IMPL(x) v(ML99_TUPLE_GET(5)(x))
311#define ML99_PRIV_tupleGet_6_IMPL(x) v(ML99_TUPLE_GET(6)(x))
312#define ML99_PRIV_tupleGet_7_IMPL(x) v(ML99_TUPLE_GET(7)(x))
313
314#define ML99_PRIV_TUPLE_GET_0(x) ML99_VARIADICS_GET(0)(ML99_UNTUPLE(x))
315#define ML99_PRIV_TUPLE_GET_1(x) ML99_VARIADICS_GET(1)(ML99_UNTUPLE(x))
316#define ML99_PRIV_TUPLE_GET_2(x) ML99_VARIADICS_GET(2)(ML99_UNTUPLE(x))
317#define ML99_PRIV_TUPLE_GET_3(x) ML99_VARIADICS_GET(3)(ML99_UNTUPLE(x))
318#define ML99_PRIV_TUPLE_GET_4(x) ML99_VARIADICS_GET(4)(ML99_UNTUPLE(x))
319#define ML99_PRIV_TUPLE_GET_5(x) ML99_VARIADICS_GET(5)(ML99_UNTUPLE(x))
320#define ML99_PRIV_TUPLE_GET_6(x) ML99_VARIADICS_GET(6)(ML99_UNTUPLE(x))
321#define ML99_PRIV_TUPLE_GET_7(x) ML99_VARIADICS_GET(7)(ML99_UNTUPLE(x))
322
323#define ML99_tupleTail_IMPL(x) v(ML99_TUPLE_TAIL(x))
324
325#define ML99_tupleAppend_IMPL(x, ...) v(ML99_TUPLE_APPEND(x, __VA_ARGS__))
326#define ML99_tuplePrepend_IMPL(x, ...) v(ML99_TUPLE_PREPEND(x, __VA_ARGS__))
327#define ML99_tupleForEach_IMPL(f, x) ML99_variadicsForEach_IMPL(f, ML99_UNTUPLE(x))
328#define ML99_tupleForEachI_IMPL(f, x) ML99_variadicsForEachI_IMPL(f, ML99_UNTUPLE(x))
329
330#define ML99_assertIsTuple_IMPL(x) \
331 ML99_PRIV_IF(ML99_IS_UNTUPLE(x), ML99_PRIV_NOT_TUPLE_ERROR(x), v(ML99_PRIV_EMPTY()))
332
333// clang-format off
334#define ML99_PRIV_NOT_TUPLE_ERROR(x) \
335 ML99_PRIV_IF( \
336 ML99_PRIV_IS_DOUBLE_TUPLE_BEGINNING(x), \
337 ML99_fatal(ML99_assertIsTuple, x must be (x1, ..., xN), did you miss a comma?), \
338 ML99_fatal(ML99_assertIsTuple, x must be (x1, ..., xN)))
339// clang-format on
340
341// Arity specifiers {
342
343#define ML99_tuple_ARITY 1
344#define ML99_tupleEval_ARITY 1
345#define ML99_untuple_ARITY 1
346#define ML99_untupleChecked_ARITY 1
347#define ML99_untupleEval_ARITY 1
348#define ML99_isTuple_ARITY 1
349#define ML99_isUntuple_ARITY 1
350#define ML99_tupleCount_ARITY 1
351#define ML99_tupleIsSingle_ARITY 1
352#define ML99_tupleTail_ARITY 1
353#define ML99_tupleAppend_ARITY 2
354#define ML99_tuplePrepend_ARITY 2
355#define ML99_tupleForEach_ARITY 2
356#define ML99_tupleForEachI_ARITY 2
357#define ML99_assertIsTuple_ARITY 1
358
359#define ML99_PRIV_tupleGet_0_ARITY 1
360#define ML99_PRIV_tupleGet_1_ARITY 1
361#define ML99_PRIV_tupleGet_2_ARITY 1
362#define ML99_PRIV_tupleGet_3_ARITY 1
363#define ML99_PRIV_tupleGet_4_ARITY 1
364#define ML99_PRIV_tupleGet_5_ARITY 1
365#define ML99_PRIV_tupleGet_6_ARITY 1
366#define ML99_PRIV_tupleGet_7_ARITY 1
367// } (Arity specifiers)
368
369#endif // DOXYGEN_IGNORE
370
371#endif // ML99_TUPLE_H
The core metalanguage.
Variadic arguments: x, y, z.