Metalang99 1.13.3
Full-blown preprocessor metaprogramming
variadics.h File Reference

Variadic arguments: x, y, z. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ML99_variadicsCount(...)   ML99_call(ML99_variadicsCount, __VA_ARGS__)
 Computes a count of its arguments. More...
 
#define ML99_variadicsIsSingle(...)   ML99_call(ML99_variadicsIsSingle, __VA_ARGS__)
 Tells if it received only one argument or not. More...
 
#define ML99_variadicsGet(i)   ML99_PRIV_CAT(ML99_PRIV_variadicsGet_, i)
 Expands to a metafunction extracting the i -indexed argument. More...
 
#define ML99_variadicsTail(...)   ML99_call(ML99_variadicsTail, __VA_ARGS__)
 Extracts the tail of its arguments. More...
 
#define ML99_variadicsForEach(f, ...)   ML99_call(ML99_variadicsForEach, f, __VA_ARGS__)
 Applies f to each argument. More...
 
#define ML99_variadicsForEachI(f, ...)   ML99_call(ML99_variadicsForEachI, f, __VA_ARGS__)
 Applies f to each argument with an index. More...
 
#define ML99_OVERLOAD(f, ...)   ML99_PRIV_CAT(f, ML99_PRIV_VARIADICS_COUNT(__VA_ARGS__))(__VA_ARGS__)
 Overloads f on a number of arguments. More...
 
#define ML99_VARIADICS_COUNT(...)   ML99_PRIV_VARIADICS_COUNT(__VA_ARGS__)
 
#define ML99_VARIADICS_IS_SINGLE(...)   ML99_PRIV_NOT(ML99_PRIV_CONTAINS_COMMA(__VA_ARGS__))
 
#define ML99_VARIADICS_GET(i)   ML99_PRIV_CAT(ML99_PRIV_VARIADICS_GET_, i)
 
#define ML99_VARIADICS_TAIL(...)   ML99_PRIV_TAIL(__VA_ARGS__)
 

Detailed Description

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.

Macro Definition Documentation

◆ ML99_OVERLOAD

#define ML99_OVERLOAD (   f,
  ... 
)    ML99_PRIV_CAT(f, ML99_PRIV_VARIADICS_COUNT(__VA_ARGS__))(__VA_ARGS__)

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

#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)
Variadic arguments: x, y, z.
Note
f need not be postfixed with _IMPL. It is literally invoked as ML99_CAT(f, ML99_VARIADICS_COUNT(...))(...).

◆ ML99_variadicsCount

#define ML99_variadicsCount (   ...)    ML99_call(ML99_variadicsCount, __VA_ARGS__)

Computes a count of its arguments.

At most 63 arguments are acceptable.

Examples

// 3
// 1
#define v(...)
A value that is pasted as-is; no evaluation occurs on provided arguments.
Definition: lang.h:145
#define ML99_variadicsCount(...)
Computes a count of its arguments.
Definition: variadics.h:35

◆ ML99_variadicsForEach

#define ML99_variadicsForEach (   f,
  ... 
)    ML99_call(ML99_variadicsForEach, f, __VA_ARGS__)

Applies f to each argument.

The result is ML99_appl(f, x1) ... ML99_appl(f, xN).

Examples

#define F_IMPL(x) v(@x)
#define F_ARITY 1
// @x @y @z
ML99_variadicsForEach(v(F), v(x, y, z))
#define ML99_variadicsForEach(f,...)
Applies f to each argument.
Definition: variadics.h:103

◆ ML99_variadicsForEachI

#define ML99_variadicsForEachI (   f,
  ... 
)    ML99_call(ML99_variadicsForEachI, f, __VA_ARGS__)

Applies f to each argument with an index.

The result is ML99_appl2(f, x1, 0) ... ML99_appl2(f, xN, N - 1).

#define F_IMPL(x, i) v(@x##i)
#define F_ARITY 2
// @x0 @y1 @z2
ML99_variadicsForEachI(v(F), v(x, y, z))
#define ML99_variadicsForEachI(f,...)
Applies f to each argument with an index.
Definition: variadics.h:120

◆ ML99_variadicsGet

#define ML99_variadicsGet (   i)    ML99_PRIV_CAT(ML99_PRIV_variadicsGet_, i)

Expands to a metafunction extracting the i -indexed argument.

i can range from 0 to 7, inclusively.

Examples

// 2
ML99_variadicsGet(1)(v(1, 2, 3))
#define ML99_variadicsGet(i)
Expands to a metafunction extracting the i -indexed argument.
Definition: variadics.h:68

◆ ML99_variadicsIsSingle

#define ML99_variadicsIsSingle (   ...)    ML99_call(ML99_variadicsIsSingle, __VA_ARGS__)

Tells if it received only one argument or not.

Examples

// 1
// 0
#define ML99_variadicsIsSingle(...)
Tells if it received only one argument or not.
Definition: variadics.h:52

◆ ML99_variadicsTail

#define ML99_variadicsTail (   ...)    ML99_call(ML99_variadicsTail, __VA_ARGS__)

Extracts the tail of its arguments.

At least two arguments must be specified.

Examples

// 2, 3
#define ML99_variadicsTail(...)
Extracts the tail of its arguments.
Definition: variadics.h:84