mirror of
https://github.com/boostorg/mpl.git
synced 2026-01-26 08:52:21 +01:00
65 lines
3.0 KiB
HTML
65 lines
3.0 KiB
HTML
<!doctype html public "-//ietf//dtd html//en">
|
|
<html><head><title>boost::mpl::fold</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</h1><h3>Synopsis</h3>
|
|
<p>
|
|
<pre>
|
|
template<
|
|
typename Sequence
|
|
, typename State
|
|
, typename ForwardOp
|
|
>
|
|
struct fold
|
|
{
|
|
typedef <em>unspecified</em> type;
|
|
};
|
|
</pre>
|
|
<p>
|
|
<h3>Description</h3>
|
|
<p>
|
|
Returns the result of the successive application of binary <code>ForwardOp</code> to the result of the previous <code>ForwardOp</code> invocation (<code>State</code> if it's the first call) and every element of the sequence in the range <code>[begin<Sequence>::type,end<Sequence>::type)</code> in the linear order.
|
|
<p>
|
|
<h3>Definition</h3>
|
|
<p>
|
|
<pre>
|
|
#include "<a href="../../../../../boost/mpl/fold.hpp">boost/mpl/fold.hpp</a>"
|
|
</pre>
|
|
<p>
|
|
<h3>Parameters</h3>
|
|
<table border="1">
|
|
<tr><th> Parameter </th><th> Requirement </th><th> Description </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></tr>
|
|
<tr><td><code>State</code></td><td>A type</td><td>The initial state for the first <code>ForwardOp</code> application. </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></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<Sequence,T,Op>::type t;</code></td><td>A type</td><td></td><td>Equivalent to <code>typedef lambda<Op>::type op; typedef iter_fold< Sequence,T,apply<op,_1,deref<_2> > >::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>ForwardOp</code>.
|
|
<p>
|
|
<h3>Example</h3>
|
|
<p>
|
|
<pre>
|
|
typedef <a href="../Reference/vector.html">vector</a><long,float,short,double,float,long,long double> types;
|
|
typedef typename fold<
|
|
types
|
|
, integral_c<long, 0>
|
|
, if_< is_float<_2>,next<_1>,_1 >
|
|
>::type number_of_floats;
|
|
<p>
|
|
BOOST_STATIC_ASSERT(number_of_floats::value == 4);
|
|
</pre>
|
|
<p>
|
|
<h3>See also</h3>
|
|
<p>
|
|
<a href="../Algorithms.html">Algorithms</a>, <code><a href="../Reference/fold_backward.html">fold_backward</a></code>, <code><a href="../Reference/iter_fold.html">iter_fold</a></code>, <code><a href="../Reference/iter_fold_backward.html">iter_fold_backward</a></code>, <code><a href="../Reference/copy.html">copy</a></code>, <code><a href="../Reference/copy_if.html">copy_if</a></code>
|
|
<p><hr>
|
|
<a href="../Table_of_Contents.html">Table of Contents</a><br>Last edited December 12, 2002 4:42 pm</body></html> |