Brian Silverman | f27e085 | 2018-08-04 23:56:45 -0700 | [diff] [blame^] | 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>). |
| 21 | This macro must expand to an integer in the range of <i>0</i> to <b>BOOST_PP_LIMIT_MAG</b>. |
| 22 | <b>BOOST_PP_FOR</b> repeatedly expands <i>macro</i> while this |
| 23 | predicate returns non-zero. 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>). |
| 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>. |
| 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>). |
| 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>. 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. This happens when the <i>r</i> value is a macro |
| 47 | invocation itself. It needs a delay to allow it to expand. 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> <a href="../headers/repetition/for.html"><boost/preprocessor/repetition/for.hpp></a> |
| 62 | </div> |
| 63 | <h4>Sample Code</h4> |
| 64 | <div> |
| 65 | <pre>#include <<a href="../headers/arithmetic/dec.html">boost/preprocessor/arithmetic/dec.hpp</a>> |
| 66 | #include <<a href="../headers/arithmetic/inc.html">boost/preprocessor/arithmetic/inc.hpp</a>> |
| 67 | #include <<a href="../headers/comparison/not_equal.html">boost/preprocessor/comparison/not_equal.hpp</a>> |
| 68 | #include <<a href="../headers/punctuation/comma_if.html">boost/preprocessor/punctuation/comma_if.hpp</a>> |
| 69 | #include <<a href="../headers/repetition/for.html">boost/preprocessor/repetition/for.hpp</a>> |
| 70 | #include <<a href="../headers/tuple/elem.html">boost/preprocessor/tuple/elem.hpp</a>> |
| 71 | |
| 72 | #define PRED(r, state) \ |
| 73 | <a href="not_equal.html">BOOST_PP_NOT_EQUAL</a>( \ |
| 74 | <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(4, 0, state), \ |
| 75 | <a href="inc.html">BOOST_PP_INC</a>( \ |
| 76 | <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(4, 1, state) \ |
| 77 | ) \ |
| 78 | ) \ |
| 79 | /**/ |
| 80 | |
| 81 | #define OP(r, state) \ |
| 82 | ( \ |
| 83 | <a href="inc.html">BOOST_PP_INC</a>( \ |
| 84 | <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(4, 0, state) \ |
| 85 | ), \ |
| 86 | <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(4, 1, state), \ |
| 87 | <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(4, 2, state), \ |
| 88 | <a href="inc.html">BOOST_PP_INC</a>( \ |
| 89 | <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(4, 3, state) \ |
| 90 | ) \ |
| 91 | ) \ |
| 92 | /**/ |
| 93 | |
| 94 | #define MACRO(r, state) \ |
| 95 | <a href="comma_if.html">BOOST_PP_COMMA_IF</a>( \ |
| 96 | <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(4, 3, state) \ |
| 97 | ) template< \ |
| 98 | <a href="for_r.html">BOOST_PP_FOR_</a> ## r( \ |
| 99 | (0, <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(4, 0, state), _, 0), \ |
| 100 | PRED_2, OP, MACRO_2 \ |
| 101 | ) \ |
| 102 | > class <a href="cat.html">BOOST_PP_CAT</a>( \ |
| 103 | <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(4, 2, state), \ |
| 104 | <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(4, 0, state) \ |
| 105 | ) \ |
| 106 | /**/ |
| 107 | |
| 108 | #define PRED_2(r, state) \ |
| 109 | <a href="not_equal.html">BOOST_PP_NOT_EQUAL</a>( \ |
| 110 | <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(4, 0, state), \ |
| 111 | <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(4, 1, state) \ |
| 112 | ) \ |
| 113 | /**/ |
| 114 | |
| 115 | #define MACRO_2(r, state) \ |
| 116 | <a href="comma_if.html">BOOST_PP_COMMA_IF</a>( \ |
| 117 | <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(4, 0, state) \ |
| 118 | ) class \ |
| 119 | /**/ |
| 120 | |
| 121 | #define TEMPLATE_TEMPLATE(low, high, name) \ |
| 122 | <a href="for.html">BOOST_PP_FOR</a>( \ |
| 123 | (low, high, name, 0), \ |
| 124 | PRED, OP, MACRO \ |
| 125 | ) \ |
| 126 | /**/ |
| 127 | |
| 128 | TEMPLATE_TEMPLATE(2, 4, T) |
| 129 | /* |
| 130 | expands to... |
| 131 | template<class, class> class T2, |
| 132 | template<class, class, class> class T3, |
| 133 | template<class, class, class, class> class T4 |
| 134 | */ |
| 135 | </pre></div> |
| 136 | <hr size="1"> |
| 137 | <div style="margin-left: 0px;"> <i>© Copyright <a href="http://www.housemarque.com" |
| 138 | target="_top">Housemarque Oy</a> 2002</i> <br> |
| 139 | <i>© Copyright Paul Mensonides 2002<br> |
| 140 | </i><i>© Copyright Edward Diener 2014</i><br> |
| 141 | </div> |
| 142 | <div style="margin-left: 0px;"> |
| 143 | <p><small>Distributed under the Boost Software License, Version 1.0. (See |
| 144 | accompanying file <a href="../../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> |
| 145 | or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</small></p> |
| 146 | </div> |
| 147 | </body> |
| 148 | </html> |