Loading...
Searching...
No Matches
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.
#define | ML99_variadicsIsSingle(...) ML99_call(ML99_variadicsIsSingle, __VA_ARGS__)
| Tells if it received only one argument or not.
#define | ML99_variadicsGet(i) ML99_PRIV_CAT(ML99_PRIV_variadicsGet_, i)
| Expands to a metafunction extracting the `i` -indexed argument.
#define | ML99_variadicsTail(...) ML99_call(ML99_variadicsTail, __VA_ARGS__)
| Extracts the tail of its arguments.
#define | ML99_variadicsForEach(f, ...) ML99_call(ML99_variadicsForEach, f, __VA_ARGS__)
| Applies `f` to each argument.
#define | ML99_variadicsForEachI(f, ...) ML99_call(ML99_variadicsForEachI, f, __VA_ARGS__)
| Applies `f` to each argument with an index.
#define | ML99_OVERLOAD(f, ...) ML99_PRIV_CAT(f, ML99_PRIV_VARIADICS_COUNT(__VA_ARGS__))(__VA_ARGS__)
| Overloads `f` on a number of arguments.
#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

#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)
variadics.h
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

#include <metalang99/variadics.h>
// 3
ML99_variadicsCount(v(~, ~, ~))
// 1
ML99_variadicsCount()
v
#define v(...)
A value that is pasted as-is; no evaluation occurs on provided arguments.
Definition lang.h:145
ML99_variadicsCount
#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

#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_variadicsForEach
#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)`.

#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_variadicsForEachI
#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

#include <metalang99/variadics.h>
// 2
ML99_variadicsGet(1)(v(1, 2, 3))
ML99_variadicsGet
#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

#include <metalang99/variadics.h>
// 1
ML99_variadicsIsSingle(v(~))
// 0
ML99_variadicsIsSingle(v(~, ~, ~))
ML99_variadicsIsSingle
#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

#include <metalang99/variadics.h>
// 2, 3
ML99_variadicsTail(v(1, 2, 3))
ML99_variadicsTail
#define ML99_variadicsTail(...)
Extracts the tail of its arguments.
Definition variadics.h:84