• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3	<title>BOOST_PP_LIST_FOLD_RIGHT</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_RIGHT</b> macro folds (or accumulates) the elements of a <i>list</i> right-to-left.
9	</div>
10	<h4>Usage</h4>
11		<div class="code">
12			<b>BOOST_PP_LIST_FOLD_RIGHT</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>).&nbsp;
19				This macro is called for each element in <i>list</i>--each time returning a new <i>state</i>.&nbsp;
20				This operation is expanded by <b>BOOST_PP_LIST_FOLD_RIGHT</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			This macro does not have the same signature as it previously did.&nbsp;
35			The arguments have been swapped to provide a uniform interface with <b>BOOST_PP_LIST_FOLD_LEFT</b>.
36		</div>
37		<div>
38			For the <i>list</i>, (<i>0</i>, (<i>1</i>, (<i>2</i>, <b>BOOST_PP_NIL</b>))), this macro expands to:
39			<div>
40				<i>op</i>(<i>d</i>, <i>op</i>(<i>d</i>, <i>op</i>(<i>d</i>, <i>state</i>, <i>2</i>), <i>1</i>), <i>0</i>)
41			</div>
42		</div>
43		<div>
44			Previously, this macro could not be used inside <b>BOOST_PP_WHILE</b>.&nbsp;
45			There is no longer any such restriction.&nbsp;
46			It is more efficient, however, to use <b>BOOST_PP_LIST_FOLD_RIGHT_<i>d</i></b> in such a situation.
47		</div>
48	<h4>See Also</h4>
49		<ul>
50			<li><a href="list_fold_right_d.html">BOOST_PP_LIST_FOLD_RIGHT_<i>d</i></a></li>
51		</ul>
52	<h4>Requirements</h4>
53		<div>
54			<b>Header:</b> &nbsp;<a href="../headers/list/fold_right.html">&lt;boost/preprocessor/list/fold_right.hpp&gt;</a>
55		</div>
56	<h4>Sample Code</h4>
57<div><pre>
58#include &lt;<a href="../headers/cat.html">boost/preprocessor/cat.hpp</a>&gt;
59#include &lt;<a href="../headers/list/fold_right.html">boost/preprocessor/list/fold_right.hpp</a>&gt;
60
61#define LIST (a, (b, (c, <a href="nil.html">BOOST_PP_NIL</a>)))
62
63#define OP(d, state, x) <a href="cat.html">BOOST_PP_CAT</a>(state, x)
64
65<a href="list_fold_right.html">BOOST_PP_LIST_FOLD_RIGHT</a>(OP, _, LIST) // expands to _cba
66</pre></div>
67	<hr size="1">
68	<div style="margin-left: 0px;">
69		<i>� Copyright <a href="http://www.housemarque.com" target="_top">Housemarque Oy</a> 2002</i>
70		</br><i>� Copyright Paul Mensonides 2002</i>
71	</div>
72	<div style="margin-left: 0px;">
73		<p><small>Distributed under the Boost Software License, Version 1.0. (See
74		accompanying file <a href="../../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or
75		copy at <a href=
76		"http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</small></p>
77	</div>
78</body>
79</html>
80