1 | <html> |
---|
2 | <head> |
---|
3 | <title>sequences.html</title> |
---|
4 | <link rel="stylesheet" type="text/css" href="../styles.css"> |
---|
5 | </head> |
---|
6 | <body> |
---|
7 | <h4> |
---|
8 | Sequences |
---|
9 | </h4> |
---|
10 | <div> |
---|
11 | A <i>sequence</i> (abbreviated to <i>seq</i>) is a group of adjacent parenthesized elements. For example, |
---|
12 | </div> |
---|
13 | <div class="code"> |
---|
14 | (<i>a</i>)(<i>b</i>)(<i>c</i>) |
---|
15 | </div> |
---|
16 | <div> |
---|
17 | ...is a <i>seq</i> of <i>3</i> elements--<i>a</i>, <i>b</i>, and <i>c</i>. |
---|
18 | </div> |
---|
19 | <div> |
---|
20 | <i>Sequences</i> are data structures that merge the properties of both <i>lists</i> and |
---|
21 | <i>tuples</i> with the exception that a <i>seq</i> cannot be empty. |
---|
22 | Therefore, an "empty" <i>seq</i> is considered a special case scenario that |
---|
23 | must be handled separately in C++. |
---|
24 | </div> |
---|
25 | <div class="code"> |
---|
26 | <pre> |
---|
27 | #define SEQ (x)(y)(z) |
---|
28 | #define REVERSE(s, state, elem) (elem) state |
---|
29 | // append to head ^ |
---|
30 | |
---|
31 | BOOST_PP_SEQ_FOLD_LEFT(REVERSE, BOOST_PP_EMPTY, SEQ)() |
---|
32 | // #1 #2 |
---|
33 | // 1) placeholder for "empty" seq |
---|
34 | // 2) remove placeholder |
---|
35 | |
---|
36 | #define SEQ_B (1)(2)(3) |
---|
37 | #define INC(s, state, elem) state (BOOST_PP_INC(elem)) |
---|
38 | // append to tail ^ |
---|
39 | |
---|
40 | BOOST_PP_SEQ_FOLD_RIGHT(INC, BOOST_PP_SEQ_NIL, SEQ) |
---|
41 | // ^ |
---|
42 | // special placeholder that will be "eaten" |
---|
43 | // by appending to the tail |
---|
44 | </pre> |
---|
45 | </div> |
---|
46 | <div> |
---|
47 | <i>Sequences</i> are extremely efficient. Element access speed approaches |
---|
48 | random access--even with <i>seqs</i> of up to <i>256</i> elements. This |
---|
49 | is because element access (among other things) is implemented iteratively |
---|
50 | rather than recursively. Therefore, elements can be accessed at extremely |
---|
51 | high indices even on preprocessors with low maximum expansion depths. |
---|
52 | </div> |
---|
53 | <div> |
---|
54 | Elements of a <i>seq</i> can be extracted with <b>BOOST_PP_SEQ_ELEM</b>. |
---|
55 | </div> |
---|
56 | <h4> |
---|
57 | Primitives |
---|
58 | </h4> |
---|
59 | <ul> |
---|
60 | <li> |
---|
61 | <a href="../ref/seq_elem.html">BOOST_PP_SEQ_ELEM</a></li> |
---|
62 | </ul> |
---|
63 | </body> |
---|
64 | </html> |
---|