]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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>). | |
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>. 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>. | |
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>). | |
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>. 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. 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. 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. This happens when the <i>d</i> value is a macro | |
43 | invocation itself. It needs a delay to allow it to expand. 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). 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> <a href="../headers/control/while.html"><boost/preprocessor/control/while.hpp></a> | |
60 | </div> | |
61 | <h4>Sample Code</h4> | |
62 | <div> | |
63 | <pre>#include <<a href="../headers/arithmetic/add.html">boost/preprocessor/arithmetic/add.hpp</a>> | |
64 | #include <<a href="../headers/arithmetic/dec.html">boost/preprocessor/arithmetic/dec.hpp</a>> | |
65 | #include <<a href="../headers/array/elem.html">boost/preprocessor/array/elem.hpp</a>> | |
66 | #include <<a href="../headers/array/size.html">boost/preprocessor/array/size.hpp</a>> | |
67 | #include <<a href="../headers/control/while.html">boost/preprocessor/control/while.hpp</a>> | |
68 | #include <<a href="../headers/tuple/elem.html">boost/preprocessor/tuple/elem.hpp</a>> | |
69 | ||
70 | #define PRED(d, data) <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(3, 1, data) | |
71 | ||
72 | #define OP(d, data) \ | |
73 | OP_D( \ | |
74 | d, \ | |
75 | <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(3, 0, data), \ | |
76 | <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(3, 1, data), \ | |
77 | <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>(3, 2, data) \ | |
78 | ) \ | |
79 | /**/ | |
80 | ||
81 | #define OP_D(d, res, i, array) \ | |
82 | ( \ | |
83 | <a href="add_d.html">BOOST_PP_ADD_D</a>( \ | |
84 | d, res, \ | |
85 | <a href="array_elem.html">BOOST_PP_ARRAY_ELEM</a>(<a href="dec.html">BOOST_PP_DEC</a>(i), array)), \ | |
86 | <a href="dec.html">BOOST_PP_DEC</a>(i), \ | |
87 | array \ | |
88 | ) \ | |
89 | /**/ | |
90 | ||
91 | #define ACCUMULATE_D(d, array) \ | |
92 | <a href="tuple_elem.html">BOOST_PP_TUPLE_ELEM</a>( \ | |
93 | 3, 0, \ | |
94 | <a href="while_d.html">BOOST_PP_WHILE_</a> ## d( \ | |
95 | PRED, OP, \ | |
96 | (0, <a href="array_size.html">BOOST_PP_ARRAY_SIZE</a>(array), array) \ | |
97 | ) \ | |
98 | ) \ | |
99 | /**/ | |
100 | ||
101 | #define ARRAY (4, (1, 2, 3, 4)) | |
102 | ||
103 | ACCUMULATE_D(1, ARRAY)// expands to 10 | |
104 | </pre></div> | |
105 | <hr size="1"> | |
106 |