Files
boost_preprocessor/doc/data/sequences.html

76 lines
2.4 KiB
HTML
Raw Normal View History

2002-10-13 05:47:23 +00:00
<html>
2002-11-07 23:39:29 +00:00
<head>
2002-11-08 02:12:35 +00:00
<title>sequences.html</title>
2002-11-07 23:39:29 +00:00
<link rel="stylesheet" type="text/css" href="../styles.css">
</head>
<body>
<h4>
2002-11-08 02:12:35 +00:00
Sequences
2002-11-07 23:39:29 +00:00
</h4>
<div>
2002-11-08 02:12:35 +00:00
A <i>sequence</i> (abbreviated to <i>seq</i>) is a group of adjacent parenthesized elements. For example,
2002-11-07 23:39:29 +00:00
</div>
<div class="code">
(<i>a</i>)(<i>b</i>)(<i>c</i>)
</div>
<div>
...is a <i>seq</i> of <i>3</i> elements--<i>a</i>, <i>b</i>, and <i>c</i>.
</div>
<div>
2002-11-08 02:12:35 +00:00
<i>Sequences</i> are data structures that merge the properties of both <i>lists</i> and
<i>tuples</i> with the exception that a <i>seq</i> cannot be empty.&nbsp;
2002-11-07 23:39:29 +00:00
Therefore, an "empty" <i>seq</i> is considered a special case scenario that
must be handled separately in C++.
</div>
<div class="code">
<pre>
#define SEQ (x)(y)(z)
2002-10-13 05:47:23 +00:00
#define REVERSE(s, state, elem) (elem) state
// append to head ^
2002-11-07 23:39:29 +00:00
BOOST_PP_SEQ_FOLD_LEFT(REVERSE, BOOST_PP_EMPTY, SEQ)()
2002-10-13 05:47:23 +00:00
// #1 #2
2002-11-07 23:39:29 +00:00
// 1) placeholder for "empty" seq
2002-10-13 05:47:23 +00:00
// 2) remove placeholder
2002-11-07 23:39:29 +00:00
#define SEQ_B (1)(2)(3)
2002-10-13 05:47:23 +00:00
#define INC(s, state, elem) state (BOOST_PP_INC(elem))
// append to tail ^
2002-11-07 23:39:29 +00:00
BOOST_PP_SEQ_FOLD_RIGHT(INC, BOOST_PP_SEQ_NIL, SEQ)
2002-10-13 05:47:23 +00:00
// ^
// special placeholder that will be "eaten"
// by appending to the tail
2002-11-07 23:39:29 +00:00
</pre>
</div>
<div>
2002-11-08 02:12:35 +00:00
<i>Sequences</i> are extremely efficient.&nbsp; Element access speed approaches
2002-11-07 23:39:29 +00:00
random access--even with <i>seqs</i> of up to <i>256</i> elements.&nbsp; This
is because element access (among other things) is implemented iteratively
rather than recursively.&nbsp; Therefore, elements can be accessed at extremely
high indices even on preprocessors with low maximum expansion depths.
</div>
<div>
Elements of a <i>seq</i> can be extracted with <b>BOOST_PP_SEQ_ELEM</b>.
</div>
<h4>
Primitives
</h4>
2002-10-13 05:47:23 +00:00
<ul>
2002-11-07 23:39:29 +00:00
<li>
<a href="../ref/seq_elem.html">BOOST_PP_SEQ_ELEM</a></li>
2002-10-13 05:47:23 +00:00
</ul>
<hr size="1">
<div style="margin-left: 0px;">
<i><EFBFBD> Copyright <a href="http://www.housemarque.com" target="_top">Housemarque Oy</a> 2002</i>
</br><i><EFBFBD> Copyright Paul Mensonides 2002</i>
</div>
<div style="margin-left: 0px;">
<p><small>Distributed under the Boost Software License, Version 1.0. (See
accompanying file <a href="../../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or
copy at <a href=
"http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</small></p>
</div>
2002-11-07 23:39:29 +00:00
</body>
2002-10-13 05:47:23 +00:00
</html>