]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | <html> |
2 | <head> | |
3 | <title>BOOST_PP_LIST_FOLD_LEFT</title> | |
4 | <link rel="stylesheet" type="text/css" href="../styles.css"> | |
5 | </head> | |
6 | <body> | |
7 | <div style="margin-left: 0px;"> | |
8 | The <b>BOOST_PP_LIST_FOLD_LEFT</b> macro folds (or accumulates) the elements of a <i>list</i> left-to-right. | |
9 | </div> | |
10 | <h4>Usage</h4> | |
11 | <div class="code"> | |
12 | <b>BOOST_PP_LIST_FOLD_LEFT</b>(<i>op</i>, <i>state</i>, <i>list</i>) | |
13 | </div> | |
14 | <h4>Arguments</h4> | |
15 | <dl> | |
16 | <dt>op</dt> | |
17 | <dd> | |
18 | A ternary operation of the form <i>op</i>(<i>d</i>, <i>state</i>, <i>elem</i>). | |
19 | This macro is called for each element in <i>list</i>--each time returning a new <i>state</i>. | |
20 | This operation is expanded by <b>BOOST_PP_LIST_FOLD_LEFT</b> with the next available <b>BOOST_PP_WHILE</b> iteration, | |
21 | the current <i>state</i>, and the current element. | |
22 | </dd> | |
23 | <dt>state</dt> | |
24 | <dd> | |
25 | The initial state of the fold. | |
26 | </dd> | |
27 | <dt>list</dt> | |
28 | <dd> | |
29 | The <i>list</i> to be folded. | |
30 | </dd> | |
31 | </dl> | |
32 | <h4>Remarks</h4> | |
33 | <div> | |
34 | For the <i>list</i>, (<i>0</i>, (<i>1</i>, (<i>2</i>, <b>BOOST_PP_NIL</b>))), this macro expands to: | |
35 | <div> | |
36 | <i>op</i>(<i>d</i>, <i>op</i>(<i>d</i>, <i>op</i>(<i>d</i>, <i>state</i>, <i>0</i>), <i>1</i>), <i>2</i>) | |
37 | </div> | |
38 | </div> | |
39 | <div> | |
40 | Previously, this macro could not be used inside <b>BOOST_PP_WHILE</b>. | |
41 | There is no longer any such restriction. | |
42 | It is more efficient, however, to use <b>BOOST_PP_LIST_FOLD_LEFT_<i>d</i></b> in such a situation. | |
43 | </div> | |
44 | <h4>See Also</h4> | |
45 | <ul> | |
46 | <li><a href="list_fold_left_d.html">BOOST_PP_LIST_FOLD_LEFT_<i>d</i></a></li> | |
47 | </ul> | |
48 | <h4>Requirements</h4> | |
49 | <div> | |
50 | <b>Header:</b> <a href="../headers/list/fold_left.html"><boost/preprocessor/list/fold_left.hpp></a> | |
51 | </div> | |
52 | <h4>Sample Code</h4> | |
53 | <div><pre> | |
54 | #include <<a href="../headers/cat.html">boost/preprocessor/cat.hpp</a>> | |
55 | #include <<a href="../headers/list/fold_left.html">boost/preprocessor/list/fold_left.hpp</a>> | |
56 | ||
57 | #define LIST (a, (b, (c, <a href="nil.html">BOOST_PP_NIL</a>))) | |
58 | ||
59 | #define OP(d, state, x) <a href="cat.html">BOOST_PP_CAT</a>(state, x) | |
60 | ||
61 | <a href="list_fold_left.html">BOOST_PP_LIST_FOLD_LEFT</a>(OP, _, LIST) // expands to _abc | |
62 | </pre></div> | |
63 | <hr size="1"> | |
64 | <div style="margin-left: 0px;"> | |
65 |