P99

◆ P99_UNROLL

#define P99_UNROLL (   MACRO,
 
)    P99_FOR(MACRO, N, P00_SEP, P00_REPEAT, P99_DUPL(N,))

Apply the macro MACRO N times.

The macro is called with the numbers 0, ..., N-1 and the N results are separated by a semicolon.

In the following example we define an adhoc macro that copies an array element of an array A to the elements of another array B.

#define ASIZE 3
double A[] = { P99_DUPL(ASIZE, 1.7) };
double B[] = { P99_DUPL(ASIZE, 371) };
#define COPY_A2B(I) B[I] = A[I]
P99_UNROLL(COPY_A2B, ASIZE);

This will expand to

B[0] = A[0]; B[1] = A[1]; B[2] = A[2];

Observe that the first two ; are inserted automatically as separators by the P99_UNROLL macro. The final one is inserted directly in the program, right after the macro invocation.

See also
P99_REPEAT for a macro that separates the parts by ,
P99_SEQ for a similar macro that applies MACRO to a list of items
P99_FOR for a more Generic type expressions and Flexible array members utility
Remarks
argument 0 should correspond to a macro name
argument 1 must expand to a decimal number

Definition at line 223 of file p99_for.h.

P99_DUPL
#define P99_DUPL(...)
Construct a list that repeats the argument list N times.
Definition: p99_list.h:90