variadics.h¶
Variadic arguments: x, y, z
.
Note
Variadics are more time and space-efficient than lists, but export less functionality; if a needed function is missed, invoking ML99_list and then manipulating with the resulting Cons-list might be helpful.
Defines
-
ML99_variadicsCount(...)¶
Computes a count of its arguments.
At most 63 arguments are acceptable.
Examples
#include <metalang99/variadics.h> // 3 ML99_variadicsCount(v(~, ~, ~)) // 1 ML99_variadicsCount()
-
ML99_variadicsIsSingle(...)¶
Tells if it received only one argument or not.
Examples
#include <metalang99/variadics.h> // 1 ML99_variadicsIsSingle(v(~)) // 0 ML99_variadicsIsSingle(v(~, ~, ~))
-
ML99_variadicsGet(i)¶
Expands to a metafunction extracting the
i
-indexed argument.i
can range from 0 to 7, inclusively.Examples
#include <metalang99/variadics.h> // 2 ML99_variadicsGet(1)(v(1, 2, 3))
-
ML99_variadicsTail(...)¶
Extracts the tail of its arguments.
At least two arguments must be specified.
Examples
#include <metalang99/variadics.h> // 2, 3 ML99_variadicsTail(v(1, 2, 3))
-
ML99_variadicsForEach(f, ...)¶
Applies
f
to each argument.The result is
ML99_appl(f, x1) ... ML99_appl(f, xN)
.Examples
#include <metalang99/variadics.h> #define F_IMPL(x) v(@x) #define F_ARITY 1 // @x @y @z ML99_variadicsForEach(v(F), v(x, y, z))
-
ML99_variadicsForEachI(f, ...)¶
Applies
f
to each argument with an index.The result is
ML99_appl2(f, x1, 0) ... ML99_appl2(f, xN, N - 1)
.#include <metalang99/variadics.h> #define F_IMPL(x, i) v(@x##i) #define F_ARITY 2 // @x0 @y1 @z2 ML99_variadicsForEachI(v(F), v(x, y, z))
-
ML99_OVERLOAD(f, ...)¶
Overloads
f
on a number of arguments.This function counts the number of provided arguments, appends it to
f
and calls the resulting macro identifier with provided arguments.At most 63 variadic arguments are acceptable.
Examples
#include <metalang99/variadics.h> #define X(...) ML99_OVERLOAD(X_, __VA_ARGS__) #define X_1(a) Billie & a #define X_2(a, b) Jean & a & b // Billie & 4 X(4) // Jean & 5 & 6 X(5, 6)
Note
f
need not be postfixed with_IMPL
. It is literally invoked asML99_CAT(f, ML99_VARIADICS_COUNT(...))(...)
.
-
ML99_VARIADICS_COUNT(...)¶
-
ML99_VARIADICS_IS_SINGLE(...)¶
-
ML99_VARIADICS_GET(i)¶
-
ML99_VARIADICS_TAIL(...)¶