Sets
A set is a group of adjacent parenthesized elements.
For example,
(a)(b)(c)
...is a set of 3 elements--a, b, and c.
Sets are data structures that merge the properties of both lists and tuples
with the exception that sets cannot be empty.
Therefore, an "empty" set is considered a special case scenario that must be handled separately in C++.
#define SET (x)(y)(z)
#define REVERSE(s, state, elem) (elem) state
// append to head ^
BOOST_PP_SET_FOLD_LEFT(REVERSE, BOOST_PP_EMPTY, SET)()
// #1 #2
// 1) placeholder for "empty" set
// 2) remove placeholder
#define SET_B (1)(2)(3)
#define INC(s, state, elem) state (BOOST_PP_INC(elem))
// append to tail ^
BOOST_PP_SET_FOLD_RIGHT(INC, BOOST_PP_SET_NIL, SET)
// ^
// special placeholder that will be "eaten"
// by appending to the tail
Sets are extremely efficient.
Element access speed approaches random access--even with sets of up to 256 elements.
This is because element access (among other things) is implemented iteratively rather than recursively.
Therefore, elements can be accessed at extremely high indices even on preprocessors with low maximum expansion depths.
Elements of a set can be extracted with
BOOST_PP_SET_ELEM.
Primitives