Files
mpl/doc/ref/Reference/fold_backward.html
Aleksey Gurtovoy a69baa5eae update the docs
[SVN r17836]
2003-03-12 13:29:12 +00:00

75 lines
4.6 KiB
HTML

<!doctype html public "-//ietf//dtd html//en">
<html><head><title>boost::mpl::fold_backward</title>
<link rel="stylesheet" href="../mpl_wiki.css">
</head><body bgcolor="white">
<h1><a href="../Table_of_Contents.html"><img src="../mpl_logo.jpg" alt="[Home]" border=0 align="right"></a>fold_backward</h1><h3>Synopsis</h3>
<p>
<pre>
template&lt;
typename Sequence
, typename State
, typename BackwardOp
, typename ForwardOp = _1
&gt;
struct fold_backward
{
typedef <em>unspecified</em> type;
};
</pre>
<p>
<h3>Description</h3>
<p>
Returns the result of the successive application of binary <code>BackwardOp</code> to the result of the previous <code>BackwardOp</code> invocation (<code>State</code> if it's the first call) and every element in the range <code>[begin&lt;Sequence&gt;::type,end&lt;Sequence&gt;::type)</code> in the reverse order. If <code>ForwardOp</code> is provided, then it's applied on forward traversal to form the result which is passed to the first <code>BackwardOp</code> call.
<p>
<h3>Definition</h3>
<p>
<pre>
#include "<a href="../../../../../boost/mpl/fold_backward.hpp">boost/mpl/fold_backward.hpp</a>"
</pre>
<p>
<h3>Parameters</h3>
<table border="1">
<tr><th>&nbsp;Parameter&nbsp;</th><th>&nbsp;Requirement&nbsp;</th><th>&nbsp;Description&nbsp;</th><th>&nbsp;Default value &nbsp;</th></tr>
<tr><td><code>Sequence</code></td><td>A model of <a href="../Sequence.html">Sequence</a></td><td>A sequence to iterate.</td><td></td></tr>
<tr><td><code>State</code></td><td>A type</td><td>The initial state for the first <code>BackwardOp</code>/<code>ForwardOp</code> application.</td><td></td></tr>
<tr><td><code>BackwardOp</code></td><td>A model of [Lambda Function]</td><td>The operation to be executed on backward traversal.</td><td></td></tr>
<tr><td><code>ForwardOp</code></td><td>A model of [Lambda Function]</td><td>The operation to be executed on forward traversal.</td><td><code>arg&lt;1&gt;</code> </td></tr>
</table>
<p>
<h3>Expression semantics</h3>
<p>
<table border="1">
<tr><th>&nbsp;Expression&nbsp;</th><th>&nbsp;Expression&nbsp;type&nbsp;</th><th>&nbsp;Precondition&nbsp;</th><th>&nbsp;Semantics&nbsp;</th><th>&nbsp;Postcondition&nbsp;</th></tr>
<tr><td><code>typedef fold_backward&lt; Sequence,T,BackwardOp &gt;::type t;</code></td><td>A type</td><td></td><td>Equivalent to <code>typedef lambda&lt;BackwardOp&gt;::type bk_op; typedef begin&lt;Sequence&gt;::type i1; typedef i1::next i2; ...; typedef in::next last; typedef apply&lt;bk_op,T,in::type&gt;::type tn; typedef apply&lt;bk_op,tn,in-1::type&gt;::type tn-1; ...; typedef apply&lt;bk_op,t2,i1::type&gt;::type t1; typedef t1 t</code>, where <code>n == size&lt;Sequence&gt;::type::value</code> and <code>last</code> is identical to <code>end&lt;Sequence&gt;::type</code>; Equivalent to <code>typedef T t;</code> if the sequence is empty.</td><td></td></tr>
<tr><td><code>typedef fold_backward&lt; Sequence,T,BackwardOp,ForwardOp &gt;::type t;</code></td><td>A type</td><td></td><td>Equivalent to <code>typedef fold_backward&lt;Sequence, fold&lt;Sequence,State,ForwardOp&gt;::type, BackwardOp&gt;::type t;</code>.</td><td></td></tr>
</table>
<p>
<h3>Complexity</h3>
<p>
Linear. Exactly <code><a href="../Reference/size.html">size</a>&lt;Sequence&gt;::type::value</code> applications of <code>BackwardOp</code> and <code>ForwardOp</code>.
<p>
<h3>Example</h3>
<p>
Removes negative elements from a sequence [<a href="#1">1</a>].
<p>
<pre>
typedef <a href="../Reference/list_c.html">list_c</a>&lt;int,5,-1,0,-7,-2,0,-5,4&gt; numbers;
typedef <a href="../Reference/list_c.html">list_c</a>&lt;int,-1,-7,-2,-5&gt; negatives;
typedef fold_backward&lt;
numbers
, <a href="../Reference/list_c.html">list_c</a>&lt;int&gt;
, if_&lt; <a href="../Reference/less.html">less</a>&lt; _2,int_&lt;0&gt; &gt;, push_front&lt;_1,_2,&gt;, _1 &gt;
&gt;::type result;
<p>
BOOST_STATIC_ASSERT(<a href="../Reference/equal.html">equal</a>&lt; negatives,result &gt;::type::value);
</pre>
<p>
<h3>Notes</h3>
<p>
[<a name="1">1</a>] See <code><a href="../Reference/remove_if.html">remove_if</a></code> for a more compact way to do this.<br>
<p>
<h3>See also</h3>
<p>
<a href="../Algorithms.html">Algorithms</a>, <code><a href="../Reference/fold.html">fold</a></code>, <code><a href="../Reference/iter_fold_backward.html">iter_fold_backward</a></code>, <code><a href="../Reference/iter_fold.html">iter_fold</a></code>, <code><a href="../Reference/copy.html">copy</a></code>, <code><a href="../Reference/copy_backward.html">copy_backward</a></code>
<p><hr>
<a href="../Table_of_Contents.html">Table of Contents</a><br>Last edited March 12, 2003 6:30 am</body></html>