3 <title>BOOST_PP_WHILE_d</title>
4 <link rel="stylesheet" type="text/css" href="../styles.css">
7 <div style="margin-left: 0px;">
8 The <b>BOOST_PP_WHILE_<i>d</i></b> macro represents a reentry into the <b>BOOST_PP_WHILE</b> looping construct.
12 <b>BOOST_PP_WHILE_</b> ## <i>d</i>(<i>pred</i>, <i>op</i>, <i>state</i>)
18 The next available <b>BOOST_PP_WHILE</b> iteration.
22 A binary predicate of the form <i>pred</i>(<i>d</i>, <i>state</i>).
23 This predicate is expanded by <b>BOOST_PP_WHILE</b> with the next available
24 iteration <i>d</i> and the current <i>state</i>.
25 This predicate must expand to value in the range of <i>0</i> to <b>BOOST_PP_LIMIT_MAG</b>.
26 The construct continues to loop until this predicate returns <i>0</i>.
27 When this predicate returns <i>0</i>, <b>BOOST_PP_WHILE</b> returns the current <i>state</i>.
31 A binary operation of the form <i>op</i>(<i>d</i>, <i>state</i>).
32 This operation is expanded by <b>BOOST_PP_WHILE</b> with the next available
33 iteration <i>d</i> and the current <i>state</i>.
34 This macro is repeatedly applied to the <i>state</i>, each time producing a new <i>state</i>, until <i>pred</i> returns <i>0</i>.
38 The initial state.
39 Often this argument is a <i>tuple</i>.
44 This macro iterates <i>op</i>(<i>d</i>, <i>state</i>) while <i>pred</i>(<i>d</i>, <i>state</i>) is non-zero.
45 In other words expands to:
47 <i>op</i>(<i>d</i>, ... <i>op</i>(<i>d</i>, <i>op</i>(<i>d</i>, <i>state</i>)) ... ).
51 At certain times, it may be necessary to perform the concatenation with <b>BOOST_PP_CAT</b> rather than the preprocessor token-pasting operator.
52 This happens when the <i>d</i> value is a macro invocation itself.
53 It needs a delay to allow it to expand.
54 The syntax in such a scenario becomes:
56 <b>BOOST_PP_CAT</b>(<b>BOOST_PP_WHILE_</b>, <i>d</i>)(<i>pred</i>, <i>op</i>, <i>state</i>).
60 Previously, it was possible to concatenate <i>d</i> directly to <b>BOOST_PP_WHILE</b> (without the trailing underscore).
61 This is no longer supported.
65 <li><a href="cat.html">BOOST_PP_CAT</a></li>
66 <li><a href="limit_mag.html">BOOST_PP_LIMIT_MAG</a></li>
67 <li><a href="while.html">BOOST_PP_WHILE</a></li>
71 <b>Header:</b> <a href="../headers/control/while.html"><boost/preprocessor/control/while.hpp></a>
75 #include <<a href="../headers/arithmetic/add.html">boost/preprocessor/arithmetic/add.hpp</a>>
76 #include <<a href="../headers/arithmetic/dec.html">boost/preprocessor/arithmetic/dec.hpp</a>>
77 #include <<a href="../headers/array/elem.html">boost/preprocessor/array/elem.hpp</a>>
78 #include <<a href="../headers/array/size.html">boost/preprocessor/array/size.hpp</a>>
79 #include <<a href="../headers/control/while.html">boost/preprocessor/control/while.hpp</a>>
80 #include <<a href="../headers/tuple/elem.html">boost/preprocessor/tuple/elem.hpp</a>>
82 #define PRED(d, data) <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(3, 1, data)
87 <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(3, 0, data), \
88 <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(3, 1, data), \
89 <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(3, 2, data) \
93 #define OP_D(d, res, i, array) \
95 <a href="add_d.html">BOOST_PP_ADD_D</a>( \
97 <a href="array_elem.html">BOOST_PP_ARRAY_ELEM</a>(<a href="dec.html">BOOST_PP_DEC</a>(i), array)), \
98 <a href="dec.html">BOOST_PP_DEC</a>(i), \
103 #define ACCUMULATE_D(d, array) \
104 <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>( \
106 <a href="while_d.html">BOOST_PP_WHILE_</a> ## d( \
108 (0, <a href="array_size.html">BOOST_PP_ARRAY_SIZE</a>(array), array) \
113 #define ARRAY (4, (1, 2, 3, 4))
115 ACCUMULATE_D(1, ARRAY)// expands to 10
118 <div style="margin-left: 0px;">
119 <i>© Copyright <a href="http://www.housemarque.com" target="_top">Housemarque Oy</a> 2002</i>
120 </br><i>© Copyright Paul Mensonides 2002</i>
122 <div style="margin-left: 0px;">
123 <p><small>Distributed under the Boost Software License, Version 1.0. (See
124 accompanying file <a href="../../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or
126 "http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</small></p>