Expands up to 2^16 repetitions (current 4 hex-digit index limit).
Headers IREPEAT.hpp
and VREPEAT.hpp
provide for horizontal
and vertical expansions.
Macro expansion is inherently 'horizontal', expanding to a single
long line.
'Vertical' repetition works by repeated file inclusion to expand
each repetition of a macro on its own line.
This header defines horizontal indexed repeat macros IREPEAT
and XREPEAT
:
IREPEAT(N,M,S)
->M((0)) S() M((1)) S() ... M(N-1) S() M(N)
XREPEAT(N,M,S)
->M((0)) S() ... M(N-2) S() M(N-1)
I
for Inclusive: M(H)
is repeated N+1
times for H
in range [0,N]
X
for eXclusive: M(H)
is repeated N
times for H
in range [0,N)
N
is the number ofXREPEAT
s. The number ofIREPEAT
s isN+1
.M
is a macro, or tokens, parameterized byHEXS
repeat-indexH
.S
is a separator-generator argument such thatS()
is a separator;
COMMA
,COLON
andNOSEP
generators are provided.
Both N
and the generated H...
indices are represented as HEXS
;
sequences of up to 4 hexadecimal digits, individually parenthesised
(with the alphabetic hex digits lowercase - a,b,c,d,e,f).
E.g. (0)
represents 0, (f)
represents 15, (2)(0)
represents 32.
(0)
generates a single repetition with IREPEAT
, nothing with XREPEAT
:
IREPEAT((0),X,COMMA) -> X(0)
XREPEAT((0),X,COMMA) ->
The generated H...
ordinals are of the same length as cardinal N
:
XREPEAT((0)(3),X,COLON);
->X((0)(0));X((0)(1));X((0)(2));
IREPEAT((f)(f),x0D,COMMA)
->x00,x01 ... x0f,x10 ... xfe,xff
256 comma separated ids, using the providedx0D
macro listed below.
Indexed access, for the first four SEQ
elements SEQ##N(SEQ)
:
SEQ0
,SEQ1
,SEQ2
,SEQ3
: N+1th SEQ elem or empty if off the end.LEN(SEQ)
: Length ofSEQ
up to 15 elems, as a single hex digit.RMLZ(HEXS)
: Remove a leading(0)
forHEXS
, preserve a sole(0)
.RMLZ3(HEXS)
: Remove up to 3 leading zeros, for 4-digitHEXS
.SEQCAT(SEQ)
: Concatenate up to 16 catableSEQ
elements.RMLZCAT(HEXS)
: Remove leading zeros fromHEXS
thenCAT
remains.
Add prefixes to concatenated digits:
HEXLIT(HEXS)
: adds0x
prefix toSEQCAT
to make a hex literal.xD(HEXS)
,XD(HEXS)
: addx
/X
prefix toRMLZCAT
for short ids.x0D(HEXS)
,X0D(HEXS)
: addx
/X
prefix toSEQCAT
to make ids.
Other common macro utils are provided with common short names.
Sequences are flexible and efficient for further preprocessing.
HEXS
increment and decrement is possible to arbitrary precision;
implementing arithemtic is out of scope here, see chaos-pp.
This header defines vertical indexed repeat macro VREPEAT
.
Here is a basic usage example:
#include "IREPEAT.hpp"
#define VREPEAT_COUNT (4)
#define VREPEAT_MACRO Iteration
#define VREPEAT_SEPARATOR() ,
#include "VREPEAT.hpp" //
#include "IREPEAT_UNDEF.hpp"
The "VREPEAT.hpp"
header depends on prior inclusion of "IREPEAT.hpp"
.
The VREPEAT
parameters are set to:
- An inclusive
VREPEAT_COUNT
of 4 - A
VREPEAT_MACRO
- here the symbolIteration
- A
VREPEAT_SEPARATOR
- here just the comma,
Preprocessing with cc -E -P "VREPEAT_example.hpp"
generates:
Iteration((0)),
Iteration((1)),
Iteration((2)),
Iteration((3)),
Iteration((4))
Normally, the macro will use its argument e.g. as the repetition count of an IREPEAT
.
For more examples see test_IREPEAT.cpp
and test_VREPEAT.cpp
.