for_r.html 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <html>
  2. <head>
  3. <meta content="text/html; charset=windows-1252" http-equiv="content-type">
  4. <title>BOOST_PP_FOR_r</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_FOR_<i>r</i></b> macro
  9. represents a reentry into the <b>BOOST_PP_FOR</b> repetition construct. </div>
  10. <h4>Usage</h4>
  11. <div class="code"> <b>BOOST_PP_FOR_</b> ## <i>r</i>(<i>state</i>, <i>pred</i>,
  12. <i>op</i>, <i>macro</i>) </div>
  13. <h4>Arguments</h4>
  14. <dl>
  15. <dt>r</dt>
  16. <dd> The next available <b>BOOST_PP_FOR</b> repetition. </dd>
  17. <dt>state</dt>
  18. <dd> The initial state. </dd>
  19. <dt>pred</dt>
  20. <dd> A binary predicate of the form <i>pred</i>(<i>r</i>, <i>state</i>).&nbsp;
  21. This macro must expand to an integer in the range of <i>0</i> to <b>BOOST_PP_LIMIT_MAG</b>.&nbsp;
  22. <b>BOOST_PP_FOR</b> repeatedly expands <i>macro</i> while this
  23. predicate returns non-zero.&nbsp; This macro is called with the next
  24. available <b>BOOST_PP_FOR</b> repetition and the current <i>state</i>.
  25. </dd>
  26. <dt>op</dt>
  27. <dd> A binary operation of the form <i>op</i>(<i>r</i>, <i>state</i>).&nbsp;
  28. This operation is expanded by <b>BOOST_PP_FOR</b> with the next
  29. available <b>BOOST_PP_FOR</b> repetition and the current <i>state</i>.&nbsp;
  30. This macro is repeatedly applied to the <i>state</i>, each time
  31. producing a new <i>state</i>, until <i>pred</i> returns <i>0</i>. </dd>
  32. <dt>macro</dt>
  33. <dd> A binary macro of the form <i>macro</i>(<i>r</i>, <i>state</i>).&nbsp;
  34. This macro is expanded by <b>BOOST_PP_FOR</b> with the next available <b>BOOST_PP_FOR</b>
  35. repetition and the current <i>state</i>.&nbsp; This macro is is
  36. repeated by <b>BOOST_PP_FOR</b> until <i>pred</i> returns <i>0</i>. </dd>
  37. </dl>
  38. <h4>Remarks</h4>
  39. <div> This macro expands to the sequence:
  40. <div> <i>macro</i>(<i>r</i>, <i>state</i>) <i>macro</i>(<i>r</i>, <i>op</i>(<i>r</i>,
  41. <i>state</i>)) ... <i>macro</i>(<i>r</i>, <i>op</i>(<i>r</i>, ... <i>op</i>(<i>r</i>,
  42. <i>state</i>) ... )) </div>
  43. </div>
  44. <div> At certain times, it may be necessary to perform the concatenation
  45. with <b>BOOST_PP_CAT</b> rather than the preprocessor token-pasting
  46. operator.&nbsp; This happens when the <i>r</i> value is a macro
  47. invocation itself.&nbsp; It needs a delay to allow it to expand.&nbsp; The
  48. syntax in such a scenario becomes:
  49. <div> <b>BOOST_PP_CAT</b>(<b>BOOST_PP_FOR_</b>, <i>r</i>)(<i>state</i>,
  50. <i>pred</i>, <i>op</i>, <i>macro</i>) </div>
  51. </div>
  52. <h4>See Also</h4>
  53. <ul>
  54. <li><a href="cat.html">BOOST_PP_CAT</a></li>
  55. <li><a href="for.html">BOOST_PP_FOR</a></li>
  56. <li><a href="limit_mag.html">BOOST_PP_LIMIT_MAG</a></li>
  57. <li><a href="for_r_macros.html"><span style="color: gray;">Macros with R
  58. re-entrancy forms</span></a></li>
  59. </ul>
  60. <h4>Requirements</h4>
  61. <div> <b>Header:</b> &nbsp;<a href="../headers/repetition/for.html">&lt;boost/preprocessor/repetition/for.hpp&gt;</a>
  62. </div>
  63. <h4>Sample Code</h4>
  64. <div>
  65. <pre>#include &lt;<a href="../headers/arithmetic/dec.html">boost/preprocessor/arithmetic/dec.hpp</a>&gt;
  66. #include &lt;<a href="../headers/arithmetic/inc.html">boost/preprocessor/arithmetic/inc.hpp</a>&gt;
  67. #include &lt;<a href="../headers/comparison/not_equal.html">boost/preprocessor/comparison/not_equal.hpp</a>&gt;
  68. #include &lt;<a href="../headers/punctuation/comma_if.html">boost/preprocessor/punctuation/comma_if.hpp</a>&gt;
  69. #include &lt;<a href="../headers/repetition/for.html">boost/preprocessor/repetition/for.hpp</a>&gt;
  70. #include &lt;<a href="../headers/tuple/elem.html">boost/preprocessor/tuple/elem.hpp</a>&gt;
  71. #define PRED(r, state) \
  72. <a href="not_equal.html">BOOST_PP_NOT_EQUAL</a>( \
  73. <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(4, 0, state), \
  74. <a href="inc.html">BOOST_PP_INC</a>( \
  75. <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(4, 1, state) \
  76. ) \
  77. ) \
  78. /**/
  79. #define OP(r, state) \
  80. ( \
  81. <a href="inc.html">BOOST_PP_INC</a>( \
  82. <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(4, 0, state) \
  83. ), \
  84. <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(4, 1, state), \
  85. <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(4, 2, state), \
  86. <a href="inc.html">BOOST_PP_INC</a>( \
  87. <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(4, 3, state) \
  88. ) \
  89. ) \
  90. /**/
  91. #define MACRO(r, state) \
  92. <a href="comma_if.html">BOOST_PP_COMMA_IF</a>( \
  93. <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(4, 3, state) \
  94. ) template&lt; \
  95. <a href="for_r.html">BOOST_PP_FOR_</a> ## r( \
  96. (0, <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(4, 0, state), _, 0), \
  97. PRED_2, OP, MACRO_2 \
  98. ) \
  99. &gt; class <a href="cat.html">BOOST_PP_CAT</a>( \
  100. <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(4, 2, state), \
  101. <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(4, 0, state) \
  102. ) \
  103. /**/
  104. #define PRED_2(r, state) \
  105. <a href="not_equal.html">BOOST_PP_NOT_EQUAL</a>( \
  106. <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(4, 0, state), \
  107. <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(4, 1, state) \
  108. ) \
  109. /**/
  110. #define MACRO_2(r, state) \
  111. <a href="comma_if.html">BOOST_PP_COMMA_IF</a>( \
  112. <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(4, 0, state) \
  113. ) class \
  114. /**/
  115. #define TEMPLATE_TEMPLATE(low, high, name) \
  116. <a href="for.html">BOOST_PP_FOR</a>( \
  117. (low, high, name, 0), \
  118. PRED, OP, MACRO \
  119. ) \
  120. /**/
  121. TEMPLATE_TEMPLATE(2, 4, T)
  122. /*
  123. expands to...
  124. template&lt;class, class&gt; class T2,
  125. template&lt;class, class, class&gt; class T3,
  126. template&lt;class, class, class, class&gt; class T4
  127. */
  128. </pre></div>
  129. <hr size="1">
  130. <div style="margin-left: 0px;"> <i>© Copyright <a href="http://www.housemarque.com"
  131. target="_top">Housemarque Oy</a> 2002</i> <br>
  132. <i>© Copyright Paul Mensonides 2002<br>
  133. </i><i>© Copyright Edward Diener 2014</i><br>
  134. </div>
  135. <div style="margin-left: 0px;">
  136. <p><small>Distributed under the Boost Software License, Version 1.0. (See
  137. accompanying file <a href="../../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a>
  138. or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</small></p>
  139. </div>
  140. </body>
  141. </html>