VA_ARGS List Metaprogramming module
This module provides various macros for metaprogramming with VA_ARGS lists
Defines
- #define PP_REVERSE_SEQUENCE_N()
- Creates a comma separated reverse sequence from 127 to 0.
- #define PP_NUM_ARGS(...)
- Returns the number of arguments passed in the
__VA_ARGS__
parameter pack. - #define PP_NTH_ARG(N, ...)
- Returns the Nth argument from the
__VA_ARGS__
parameter pack. - #define APPEND_TO_LIST(what, ...)
- Appends a space followed by
what
to each element of the__VA_ARGS__
parameter pack. - #define DELIMIT_LIST(what, ...)
- Applies a different delimiter to the list elements of the
__VA_ARGS__
parameter pack. - #define APPLY_TO_LIST(what, ...)
- Calls
what
on the arguments in the parameter pack. - #define APPEND_EACH_TO_LIST(what, ...)
- Appends the Nth element in
what
to the Nth element in the__VA_ARGS__
parameter pack. - #define SELECTOR_LIST(N)
- Returns a numeric token (number prefixed by underscore, eg
_1
) representing the given number. - #define EMPTY(...)
- Converts any list of arguments into an empty list.
- #define DEFER(...)
- Defers the preprocessing of the list of arguments one step.
- #define EXPAND(...)
- Expands the list of arguments.
- #define COMMA(...)
- Converts the list of arguments into a single comma.
- #define CONTAINS_COMMA(...)
- Determines if the list of arguments contains a comma (contains more than one element)
- #define FIRST(...)
- Returns the first element from the list.
- #define SECOND(...)
- Returns the second element from the list.
- #define SECOND_IMPL(first, second, ...)
- Returns the second element from the list.
- #define REMOVE_FIRST(...)
- Removes the first element from the list, and returns the remaining elements.
Define documentation
#define PP_REVERSE_SEQUENCE_N()
#include <include/Cnx/mpl/ArgLists.h>
Creates a comma separated reverse sequence from 127 to 0.
Useful for macro meta-programming that requires determining the number of arguments passed in a __VA_ARGS__
pack
#define PP_NUM_ARGS(...)
#include <include/Cnx/mpl/ArgLists.h>
Returns the number of arguments passed in the __VA_ARGS__
parameter pack.
Parameters | |
---|---|
... | - The __VA_ARGS__ parameter pack to get the length of |
Returns | The number of args in the parameter pack |
Useful for macro meta-programming that requires determining the number of arguments passed in a parameter pack
#define PP_NTH_ARG(N,
...)
#include <include/Cnx/mpl/ArgLists.h>
Returns the Nth argument from the __VA_ARGS__
parameter pack.
Parameters | |
---|---|
N | - The 1-indexed index of the argument to get |
... | - The __VA_ARGS__ parameter pack to index into |
Returns | The Nth argument |
#define APPEND_TO_LIST(what,
...)
#include <include/Cnx/mpl/ArgLists.h>
Appends a space followed by what
to each element of the __VA_ARGS__
parameter pack.
Parameters | |
---|---|
what | - The text/token/etc to append to each element of the __VA_ARGS__ parameter pack |
... | - The __VA_ARGS__ parameter pack to modify |
Returns | The modified __VA_ARGS__ parameter pack |
#define DELIMIT_LIST(what,
...)
#include <include/Cnx/mpl/ArgLists.h>
Applies a different delimiter to the list elements of the __VA_ARGS__
parameter pack.
Parameters | |
---|---|
what | - The text/token/etc to delimit each element of the __VA_ARGS__ parameter pack |
... | - The __VA_ARGS__ parameter pack to modify |
Returns | The resulting text from changing the list delimiter |
#define APPLY_TO_LIST(what,
...)
#include <include/Cnx/mpl/ArgLists.h>
Calls what
on the arguments in the parameter pack.
Parameters | |
---|---|
what | - The function or function-like macro to apply to the arguments in the pack |
... | - The parameter pack to apply what to |
Returns | The parameter pack, with what applied |
Supports up to 12 arguments in the parameter pack. For every argument, what
is called/applied on it in place in the pack, eg., what(x), what(y)
, where x
and y
are arguments in the pack. Example:
i32* add_one(i32* i) { ++(*i); return i; } i32 zero = 0, one = 1, two = 2; // prints "1, 2, 3" to `stdout` println("{}, {}, {}", APPLY_TO_LIST(&, APPLY_TO_LIST(add_one, &zero, &one, &two)));
This is most useful for applying a macro or function to a list of values before passing them into another macro or variadic function.
#define APPEND_EACH_TO_LIST(what,
...)
#include <include/Cnx/mpl/ArgLists.h>
Appends the Nth element in what
to the Nth element in the __VA_ARGS__
parameter pack.
Parameters | |
---|---|
what | - The 1-indexible macro generating the token(s) to append to the element in the __VA_ARGS__ parameter pack with the associated index |
... | - The __VA_ARGS__ parameter pack to modify |
Returns | The modified __VA_ARGS__ parameter pack |
#define SELECTOR_LIST(N)
#include <include/Cnx/mpl/ArgLists.h>
Returns a numeric token (number prefixed by underscore, eg _1
) representing the given number.
Parameters | |
---|---|
N | - The number to get the token for |
Returns | N as a numeric token |
#define EMPTY(...)
#include <include/Cnx/mpl/ArgLists.h>
Converts any list of arguments into an empty list.
#define DEFER(...)
#include <include/Cnx/mpl/ArgLists.h>
Defers the preprocessing of the list of arguments one step.
#define EXPAND(...)
#include <include/Cnx/mpl/ArgLists.h>
Expands the list of arguments.
#define COMMA(...)
#include <include/Cnx/mpl/ArgLists.h>
Converts the list of arguments into a single comma.
#define CONTAINS_COMMA(...)
#include <include/Cnx/mpl/ArgLists.h>
Determines if the list of arguments contains a comma (contains more than one element)
#define FIRST(...)
#include <include/Cnx/mpl/ArgLists.h>
Returns the first element from the list.
#define SECOND(...)
#include <include/Cnx/mpl/ArgLists.h>
Returns the second element from the list.
#define SECOND_IMPL(first,
second,
...)
#include <include/Cnx/mpl/ArgLists.h>
Returns the second element from the list.
#define REMOVE_FIRST(...)
#include <include/Cnx/mpl/ArgLists.h>
Removes the first element from the list, and returns the remaining elements.