sequences.html 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <html>
  2. <head>
  3. <meta content="text/html; charset=windows-1252" http-equiv="content-type">
  4. <title>sequences.html</title>
  5. <link rel="stylesheet" type="text/css" href="../styles.css">
  6. </head>
  7. <body>
  8. <h4> Sequences </h4>
  9. <div> A <i>sequence</i> (abbreviated to <i>seq</i>) is a group of adjacent
  10. parenthesized elements. For example, </div>
  11. <div class="code"> (<i>a</i>)(<i>b</i>)(<i>c</i>) </div>
  12. <div> ...is a <i>seq</i> of <i>3</i> elements--<i>a</i>, <i>b</i>, and <i>c</i>.
  13. </div>
  14. <div> <i>Sequences</i> are data structures that merge the properties of
  15. both <i>lists</i> and <i>tuples</i> with the exception that a <i>seq, </i>like
  16. a <i>tuple, </i>cannot be empty.&nbsp; Therefore, an "empty" <i>seq</i>
  17. is considered a special case scenario that must be handled separately in
  18. C++. </div>
  19. <div class="code">
  20. <pre>#define SEQ (x)(y)(z)
  21. #define REVERSE(s, state, elem) (elem) state
  22. // append to head ^
  23. BOOST_PP_SEQ_FOLD_LEFT(REVERSE, BOOST_PP_EMPTY, SEQ)()
  24. // #1 #2
  25. // 1) placeholder for "empty" seq
  26. // 2) remove placeholder
  27. #define SEQ_B (1)(2)(3)
  28. #define INC(s, state, elem) state (BOOST_PP_INC(elem))
  29. // append to tail ^
  30. BOOST_PP_SEQ_FOLD_RIGHT(INC, BOOST_PP_SEQ_NIL, SEQ)
  31. // ^
  32. // special placeholder that will be "eaten"
  33. // by appending to the tail
  34. </pre> </div>
  35. <div> <i>Sequences</i> are extremely efficient.&nbsp; Element access speed
  36. approaches random access--even with <i>seqs</i> of up to <i>256</i>
  37. elements.&nbsp; This is because element access (among other things) is
  38. implemented iteratively rather than recursively.&nbsp; Therefore, elements
  39. can be accessed at extremely high indices even on preprocessors with low
  40. maximum expansion depths. </div>
  41. <div> Elements of a <i>seq</i> can be extracted with <b>BOOST_PP_SEQ_ELEM</b>.
  42. </div>
  43. <h4> Primitives </h4>
  44. <ul>
  45. <li> <a href="../ref/seq_elem.html">BOOST_PP_SEQ_ELEM</a></li>
  46. </ul>
  47. <hr size="1">
  48. <div style="margin-left: 0px;"> <i>© Copyright <a href="http://www.housemarque.com"
  49. target="_top">Housemarque Oy</a> 2002</i> <br>
  50. <i>© Copyright Paul Mensonides 2002</i> </div>
  51. <div style="margin-left: 0px;">
  52. <p><small>Distributed under the Boost Software License, Version 1.0. (See
  53. accompanying file <a href="../../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a>
  54. or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</small></p>
  55. </div>
  56. </body>
  57. </html>