while_d.html 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <html>
  2. <head>
  3. <meta content="text/html; charset=windows-1252" http-equiv="content-type">
  4. <title>BOOST_PP_WHILE_d</title>
  5. <link rel="stylesheet" type="text/css" href="../styles.css">
  6. </head>
  7. <body>
  8. <div style="margin-left: 0px;"> The <b>BOOST_PP_WHILE_<i>d</i></b> macro
  9. represents a reentry into the <b>BOOST_PP_WHILE</b> looping construct. </div>
  10. <h4>Usage</h4>
  11. <div class="code"> <b>BOOST_PP_WHILE_</b> ## <i>d</i>(<i>pred</i>, <i>op</i>,
  12. <i>state</i>) </div>
  13. <h4>Arguments</h4>
  14. <dl>
  15. <dt>d</dt>
  16. <dd> The next available <b>BOOST_PP_WHILE</b> iteration. </dd>
  17. <dt>pred</dt>
  18. <dd> A binary predicate of the form <i>pred</i>(<i>d</i>, <i>state</i>).&nbsp;
  19. This predicate is expanded by <b>BOOST_PP_WHILE</b> with the next
  20. available iteration <i>d</i> and the current <i>state</i>.&nbsp; This
  21. predicate must expand to value in the range of <i>0</i> to <b>BOOST_PP_LIMIT_MAG</b>.
  22. The construct continues to loop until this predicate returns <i>0</i>.&nbsp;
  23. When this predicate returns <i>0</i>, <b>BOOST_PP_WHILE</b> returns
  24. the current <i>state</i>. </dd>
  25. <dt>op</dt>
  26. <dd> A binary operation of the form <i>op</i>(<i>d</i>, <i>state</i>).&nbsp;
  27. This operation is expanded by <b>BOOST_PP_WHILE</b> with the next
  28. available iteration <i>d</i> and the current <i>state</i>.&nbsp; This
  29. macro is repeatedly applied to the <i>state</i>, each time producing a
  30. new <i>state</i>, until <i>pred</i> returns <i>0</i>. </dd>
  31. <dt>state</dt>
  32. <dd> The initial state.&nbsp; Often this argument is a <i>tuple</i>. </dd>
  33. </dl>
  34. <h4>Remarks</h4>
  35. <div> This macro iterates <i>op</i>(<i>d</i>, <i>state</i>) while <i>pred</i>(<i>d</i>,
  36. <i>state</i>) is non-zero.&nbsp; In other words expands to:
  37. <div> <i>op</i>(<i>d</i>, ... <i>op</i>(<i>d</i>, <i>op</i>(<i>d</i>, <i>state</i>))
  38. ... ). </div>
  39. </div>
  40. <div> At certain times, it may be necessary to perform the concatenation
  41. with <b>BOOST_PP_CAT</b> rather than the preprocessor token-pasting
  42. operator.&nbsp; This happens when the <i>d</i> value is a macro
  43. invocation itself.&nbsp; It needs a delay to allow it to expand.&nbsp; The
  44. syntax in such a scenario becomes:
  45. <div> <b>BOOST_PP_CAT</b>(<b>BOOST_PP_WHILE_</b>, <i>d</i>)(<i>pred</i>,
  46. <i>op</i>, <i>state</i>). </div>
  47. </div>
  48. <div> Previously, it was possible to concatenate <i>d</i> directly to <b>BOOST_PP_WHILE</b>
  49. (without the trailing underscore).&nbsp; This is no longer supported. </div>
  50. <h4>See Also</h4>
  51. <ul>
  52. <li><a href="cat.html">BOOST_PP_CAT</a></li>
  53. <li><a href="limit_mag.html">BOOST_PP_LIMIT_MAG</a></li>
  54. <li><a href="while.html">BOOST_PP_WHILE</a></li>
  55. <li><a href="while_d_macros.html"><span style="color: gray;">Macros with D
  56. re-entrancy forms</span></a></li>
  57. </ul>
  58. <h4>Requirements</h4>
  59. <div> <b>Header:</b> &nbsp;<a href="../headers/control/while.html">&lt;boost/preprocessor/control/while.hpp&gt;</a>
  60. </div>
  61. <h4>Sample Code</h4>
  62. <div>
  63. <pre>#include &lt;<a href="../headers/arithmetic/add.html">boost/preprocessor/arithmetic/add.hpp</a>&gt;
  64. #include &lt;<a href="../headers/arithmetic/dec.html">boost/preprocessor/arithmetic/dec.hpp</a>&gt;
  65. #include &lt;<a href="../headers/array/elem.html">boost/preprocessor/array/elem.hpp</a>&gt;
  66. #include &lt;<a href="../headers/array/size.html">boost/preprocessor/array/size.hpp</a>&gt;
  67. #include &lt;<a href="../headers/control/while.html">boost/preprocessor/control/while.hpp</a>&gt;
  68. #include &lt;<a href="../headers/tuple/elem.html">boost/preprocessor/tuple/elem.hpp</a>&gt;
  69. #define PRED(d, data) <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(3, 1, data)
  70. #define OP(d, data) \
  71. OP_D( \
  72. d, \
  73. <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(3, 0, data), \
  74. <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(3, 1, data), \
  75. <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(3, 2, data) \
  76. ) \
  77. /**/
  78. #define OP_D(d, res, i, array) \
  79. ( \
  80. <a href="add_d.html">BOOST_PP_ADD_D</a>( \
  81. d, res, \
  82. <a href="array_elem.html">BOOST_PP_ARRAY_ELEM</a>(<a href="dec.html">BOOST_PP_DEC</a>(i), array)), \
  83. <a href="dec.html">BOOST_PP_DEC</a>(i), \
  84. array \
  85. ) \
  86. /**/
  87. #define ACCUMULATE_D(d, array) \
  88. <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>( \
  89. 3, 0, \
  90. <a href="while_d.html">BOOST_PP_WHILE_</a> ## d( \
  91. PRED, OP, \
  92. (0, <a href="array_size.html">BOOST_PP_ARRAY_SIZE</a>(array), array) \
  93. ) \
  94. ) \
  95. /**/
  96. #define ARRAY (4, (1, 2, 3, 4))
  97. ACCUMULATE_D(1, ARRAY)// expands to 10
  98. </pre></div>
  99. <hr size="1">
  100. <div style="margin-left: 0px;"> <i>© Copyright <a href="http://www.housemarque.com"
  101. target="_top">Housemarque Oy</a> 2002</i> <br>
  102. <i>© Copyright Paul Mensonides 2002<br>
  103. </i><i>© Copyright Edward Diener 2014</i><br>
  104. </div>
  105. <div style="margin-left: 0px;">
  106. <p><small>Distributed under the Boost Software License, Version 1.0. (See
  107. accompanying file <a href="../../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a>
  108. or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</small></p>
  109. </div>
  110. </body>
  111. </html>