Sequences

A sequence is zero or more comma separated items enclosed by parentheses. Since they are enclosed by parentheses, sequences can be passed to macros as single arguments making them an important unit of encapsulation in this domain.

Warning

Some sequence macros may be limited to 30 items.

CORE_PP_IS_SEQ(...)

Expands to 1 if the arguments are a sequence, otherwise 0.

CORE_PP_IS_SEQ()      // 0
CORE_PP_IS_SEQ(a)     // 0
CORE_PP_IS_SEQ(a,b)   // 0
CORE_PP_IS_SEQ(())    // 1
CORE_PP_IS_SEQ((a,b)) // 1

CORE_PP_HEAD_SEQ(seq)

Expands to the first element of the given sequence.

CORE_PP_HEAD_SEQ((a,b,c))     // a

CORE_PP_REST_SEQ(seq)

Expands to a seeuence of the remaining elements of the given sequence.

CORE_PP_REST_SEQ((a,b,c))     // (b,c)

CORE_PP_SECOND_SEQ(seq)

Expands to the second element of the given sequence.

CORE_PP_SECOND_SEQ((a,b,c))   // b

CORE_PP_THIRD_SEQ(seq)

Expands to the third element of the given sequence.

CORE_PP_THIRD_SEQ((a,b,c))    // c

CORE_PP_COUNT_SEQ(seq)

Expands to the number of elements in the given sequence.

CORE_PP_COUNT_SEQ(())          // 0
CORE_PP_COUNT_SEQ((a))         // 1
CORE_PP_COUNT_SEQ((a,b))       // 2
CORE_PP_COUNT_SEQ((a,b,c))     // 3
CORE_PP_COUNT_SEQ((a,b),(c,d)) // 2

CORE_PP_HEAD_LIST_OR_SEQ(seq_or_value, ...)

Expands to the first element of the given list or sequence.

CORE_PP_HEAD_LIST_OR_SEQ(a)     == a
CORE_PP_HEAD_LIST_OR_SEQ(a,b)   == a
CORE_PP_HEAD_LIST_OR_SEQ((a))   == a
CORE_PP_HEAD_LIST_OR_SEQ((a,b)) == a