mirror of
https://github.com/boostorg/mpl.git
synced 2026-01-26 17:02:20 +01:00
75 lines
4.6 KiB
HTML
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<
|
|
typename Sequence
|
|
, typename State
|
|
, typename BackwardOp
|
|
, typename ForwardOp = _1
|
|
>
|
|
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<Sequence>::type,end<Sequence>::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> Parameter </th><th> Requirement </th><th> Description </th><th> Default value </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<1></code> </td></tr>
|
|
</table>
|
|
<p>
|
|
<h3>Expression semantics</h3>
|
|
<p>
|
|
<table border="1">
|
|
<tr><th> Expression </th><th> Expression type </th><th> Precondition </th><th> Semantics </th><th> Postcondition </th></tr>
|
|
<tr><td><code>typedef fold_backward< Sequence,T,BackwardOp >::type t;</code></td><td>A type</td><td></td><td>Equivalent to <code>typedef lambda<BackwardOp>::type bk_op; typedef begin<Sequence>::type i1; typedef i1::next i2; ...; typedef in::next last; typedef apply<bk_op,T,in::type>::type tn; typedef apply<bk_op,tn,in-1::type>::type tn-1; ...; typedef apply<bk_op,t2,i1::type>::type t1; typedef t1 t</code>, where <code>n == size<Sequence>::type::value</code> and <code>last</code> is identical to <code>end<Sequence>::type</code>; Equivalent to <code>typedef T t;</code> if the sequence is empty.</td><td></td></tr>
|
|
<tr><td><code>typedef fold_backward< Sequence,T,BackwardOp,ForwardOp >::type t;</code></td><td>A type</td><td></td><td>Equivalent to <code>typedef fold_backward<Sequence, fold<Sequence,State,ForwardOp>::type, BackwardOp>::type t;</code>.</td><td></td></tr>
|
|
</table>
|
|
<p>
|
|
<h3>Complexity</h3>
|
|
<p>
|
|
Linear. Exactly <code><a href="../Reference/size.html">size</a><Sequence>::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><int,5,-1,0,-7,-2,0,-5,4> numbers;
|
|
typedef <a href="../Reference/list_c.html">list_c</a><int,-1,-7,-2,-5> negatives;
|
|
typedef fold_backward<
|
|
numbers
|
|
, <a href="../Reference/list_c.html">list_c</a><int>
|
|
, if_< <a href="../Reference/less.html">less</a>< _2,int_<0> >, push_front<_1,_2,>, _1 >
|
|
>::type result;
|
|
<p>
|
|
BOOST_STATIC_ASSERT(<a href="../Reference/equal.html">equal</a>< negatives,result >::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> |