1<?xml version="1.0" encoding="utf-8" ?> 2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 3<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 4<head> 5<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 6<meta name="generator" content="Docutils 0.7: http://docutils.sourceforge.net/" /> 7<title>The MPL Reference Manual: fold</title> 8<link rel="stylesheet" href="../style.css" type="text/css" /> 9</head> 10<body class="docframe refmanual"> 11<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./iteration-algorithms.html" class="navigation-link">Prev</a> <a href="./iter-fold.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group">Back <a href="./iter-fold.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./iteration-algorithms.html" class="navigation-link">Up</a> <a href="../refmanual.html" class="navigation-link">Home</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./refmanual_toc.html" class="navigation-link">Full TOC</a></span></td> 12<td class="header-group page-location"><a href="../refmanual.html" class="navigation-link">Front Page</a> / <a href="./algorithms.html" class="navigation-link">Algorithms</a> / <a href="./iteration-algorithms.html" class="navigation-link">Iteration Algorithms</a> / <a href="./fold.html" class="navigation-link">fold</a></td> 13</tr></table><div class="header-separator"></div> 14<div class="section" id="fold"> 15<h1><a class="toc-backref" href="./iteration-algorithms.html#id1469">fold</a></h1> 16<div class="section" id="id493"> 17<h3><a class="subsection-title" href="#synopsis" name="synopsis">Synopsis</a></h3> 18<pre class="literal-block"> 19template< 20 typename Sequence 21 , typename State 22 , typename ForwardOp 23 > 24struct <a href="./fold.html" class="identifier">fold</a> 25{ 26 typedef <em>unspecified</em> type; 27}; 28</pre> 29</div> 30<div class="section" id="id494"> 31<h3><a class="subsection-title" href="#description" name="description">Description</a></h3> 32<p>Returns the result of the successive application of binary <tt class="literal"><span class="pre">ForwardOp</span></tt> to the 33result of the previous <tt class="literal"><span class="pre">ForwardOp</span></tt> invocation (<tt class="literal"><span class="pre">State</span></tt> if it's the first call) 34and every element of the sequence in the range [<tt class="literal"><span class="pre"><a href="./begin.html" class="identifier">begin</a><Sequence>::type</span></tt>, <tt class="literal"><span class="pre"><a href="./end.html" class="identifier">end</a><Sequence>::type</span></tt>) in order.</p> 35</div> 36<div class="section" id="id495"> 37<h3><a class="subsection-title" href="#header" name="header">Header</a></h3> 38<pre class="literal-block"> 39#include <<a href="../../../../boost/mpl/fold.hpp" class="header">boost/mpl/fold.hpp</a>> 40</pre> 41</div> 42<div class="section" id="id496"> 43<h3><a class="subsection-title" href="#parameters" name="parameters">Parameters</a></h3> 44<table border="1" class="docutils table"> 45<colgroup> 46<col width="15%" /> 47<col width="32%" /> 48<col width="53%" /> 49</colgroup> 50<thead valign="bottom"> 51<tr><th class="head">Parameter</th> 52<th class="head">Requirement</th> 53<th class="head">Description</th> 54</tr> 55</thead> 56<tbody valign="top"> 57<tr><td><tt class="literal"><span class="pre">Sequence</span></tt></td> 58<td><a class="reference internal" href="./forward-sequence.html">Forward Sequence</a></td> 59<td>A sequence to iterate.</td> 60</tr> 61<tr><td><tt class="literal"><span class="pre">State</span></tt></td> 62<td>Any type</td> 63<td>The initial state for the first <tt class="literal"><span class="pre">ForwardOp</span></tt> 64application.</td> 65</tr> 66<tr><td><tt class="literal"><span class="pre">ForwardOp</span></tt></td> 67<td>Binary <a class="reference internal" href="./lambda-expression.html">Lambda Expression</a></td> 68<td>The operation to be executed on forward 69traversal.</td> 70</tr> 71</tbody> 72</table> 73</div> 74<div class="section" id="id497"> 75<h3><a class="subsection-title" href="#expression-semantics" name="expression-semantics">Expression semantics</a></h3> 76<p>For any <a class="reference internal" href="./forward-sequence.html">Forward Sequence</a> <tt class="literal"><span class="pre">s</span></tt>, binary <a class="reference internal" href="./lambda-expression.html">Lambda Expression</a> <tt class="literal"><span class="pre">op</span></tt>, and arbitrary type <tt class="literal"><span class="pre">state</span></tt>:</p> 77<pre class="literal-block"> 78typedef <a href="./fold.html" class="identifier">fold</a><s,state,op>::type t; 79</pre> 80<table class="docutils field-list" frame="void" rules="none"> 81<col class="field-name" /> 82<col class="field-body" /> 83<tbody valign="top"> 84<tr class="field"><th class="field-name">Return type:</th><td class="field-body"><p class="first">A type.</p> 85</td> 86</tr> 87<tr class="field"><th class="field-name">Semantics:</th><td class="field-body"><p class="first">Equivalent to</p> 88<pre class="last literal-block"> 89typedef <a href="./iter-fold.html" class="identifier">iter_fold</a>< 90 s 91 , state 92 , apply_wrap2< <a href="./lambda.html" class="identifier">lambda</a><op>::type, <a href="./placeholders.html" class="identifier">_1</a>, <a href="./deref.html" class="identifier">deref</a><<a href="./placeholders.html" class="identifier">_2</a>> > 93 >::type t; 94</pre> 95</td> 96</tr> 97</tbody> 98</table> 99</div> 100<div class="section" id="id498"> 101<h3><a class="subsection-title" href="#complexity" name="complexity">Complexity</a></h3> 102<p>Linear. Exactly <tt class="literal"><span class="pre"><a href="./size.html" class="identifier">size</a><s>::value</span></tt> applications of <tt class="literal"><span class="pre">op</span></tt>.</p> 103</div> 104<div class="section" id="id499"> 105<h3><a class="subsection-title" href="#example" name="example">Example</a></h3> 106<pre class="literal-block"> 107typedef <a href="./vector.html" class="identifier">vector</a><long,float,short,double,float,long,long double> types; 108typedef <a href="./fold.html" class="identifier">fold</a>< 109 types 110 , <a href="./int.html" class="identifier">int_</a><0> 111 , <a href="./if.html" class="identifier">if_</a>< is_float<<a href="./placeholders.html" class="identifier">_2</a>>,<a href="./next.html" class="identifier">next</a><<a href="./placeholders.html" class="identifier">_1</a>>,<a href="./placeholders.html" class="identifier">_1</a> > 112 >::type number_of_floats; 113 114<a href="./assert-relation.html" class="identifier">BOOST_MPL_ASSERT_RELATION</a>( number_of_floats::value, ==, 4 ); 115</pre> 116</div> 117<div class="section" id="id500"> 118<h3><a class="subsection-title" href="#see-also" name="see-also">See also</a></h3> 119<p><a class="reference internal" href="./algorithms.html">Algorithms</a>, <a class="reference internal" href="./accumulate.html">accumulate</a>, <a class="reference internal" href="./reverse-fold.html">reverse_fold</a>, <a class="reference internal" href="./iter-fold.html">iter_fold</a>, <a class="reference internal" href="./reverse-iter-fold.html">reverse_iter_fold</a>, <a class="reference internal" href="./copy.html">copy</a>, <a class="reference internal" href="./copy-if.html">copy_if</a></p> 120<!-- Algorithms/Iteration Algorithms//iter_fold --> 121</div> 122</div> 123 124<div class="footer-separator"></div> 125<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./iteration-algorithms.html" class="navigation-link">Prev</a> <a href="./iter-fold.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group">Back <a href="./iter-fold.html" class="navigation-link">Along</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./iteration-algorithms.html" class="navigation-link">Up</a> <a href="../refmanual.html" class="navigation-link">Home</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./refmanual_toc.html" class="navigation-link">Full TOC</a></span></td> 126<td><div class="copyright-footer"><div class="copyright">Copyright © 2001-2009 Aleksey Gurtovoy and David Abrahams</div> 127Distributed under the Boost Software License, Version 1.0. (See accompanying 128file LICENSE_1_0.txt or copy at <a class="reference external" href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)</div></td></tr></table></body> 129</html> 130