eĿlipsis
a language independent preprocessor
 
Loading...
Searching...
No Matches
ellipsis-foreach.dirs File Reference

An eĿlipsis extension to process a list in the preprocessor. More...

Macros

#define ARGS
 The argument list that must be set before entering this source.
 
#define BODY(…)
 The body that will be invoked for each iteration value.
 
#define RESULT
 The name of the macro that will hold the result of the iteration.
 
#define SEPARATOR
 A separator that is inserted between each iteration.
 

Detailed Description

An eĿlipsis extension to process a list in the preprocessor.

Use this such as in

#include_directives 〈ellipsis-foreach.dirs〉 \
__prefix__(bind ARGS() a, b, c) \
__prefix__(bind RESULT MY_STRINGS) \
__prefix__(bind BODY(…) __EXPAND_STRINGIFY__(__VA_ARGS__))

This assigns the token sequence "a" "b" "c" to the macro MY_STRINGS. If that macro had been set before, the old value is overwritten without producing an error.

The macros ARGS, RESULT and BODY contain the information for the loop and should be set prior to the inclusion. To avoid pollution they are best set as indicated by bind directives, such that they are undefined after the execution of the include_directives directive.

Both ARGS and BODY should either themselves be functional macros, or expand to the name of such a functional macro, where the one for ARGS receives no arguments, and the one for BODY has a ... parameter.

For example ARGS could directly be defined as

#bind ARGS() a, b, d

or another macro could be called indirectly

#define LANGUAGES() c, d, e
#bind ARGS LANGUAGES

Similar for BODY

#bind BODY(…) __EXPAND_STRINGIFY__(__VA_ARGS__)

or

#bind BODY __EXPAND_STRINGIFY__

A fourth optional macro SEPARATOR macro may hold a separator that is spliced between the output items. For example

#include_directives 〈ellipsis-foreach.dirs〉 \
__prefix__(bind ARGS a, b, c) \
__prefix__(bind RESULT MY_ORS) \
__prefix__(bind SEPARATOR ∨) \
__prefix__(bind BODY(…) __VA_ARGS__)

results in a macro MY_ORS that is set to a ∨ b ∨ c.

Remarks
The complexity of this process is linear in the sum of the length of the input and output lists.
This uses recursive inclusion, but only of a depth of 4.
The permitted length of the list is currently 2¹⁶-1, which should be a reasonable bound for things that you want to do with the preprocessor.

Macro Definition Documentation

◆ ARGS

#define ARGS

The argument list that must be set before entering this source.

Arguments are separated by commas, each argument may consist of several tokens or be empty.

◆ BODY

#define BODY (   )

The body that will be invoked for each iteration value.

The easiest is to have that given has here, that is with a list of parameters.

◆ RESULT

#define RESULT

The name of the macro that will hold the result of the iteration.

◆ SEPARATOR

#define SEPARATOR

A separator that is inserted between each iteration.