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: accumulate</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="./reverse-iter-fold.html" class="navigation-link">Prev</a> <a href="./querying-algorithms.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./reverse-iter-fold.html" class="navigation-link">Back</a> Along</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="./accumulate.html" class="navigation-link">accumulate</a></td> 13</tr></table><div class="header-separator"></div> 14<div class="section" id="accumulate"> 15<h1><a class="toc-backref" href="./iteration-algorithms.html#id1473">accumulate</a></h1> 16<div class="section" id="id527"> 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="./accumulate.html" class="identifier">accumulate</a> 25{ 26 typedef <em>unspecified</em> type; 27}; 28</pre> 29</div> 30<div class="section" id="id528"> 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. 35[<em>Note:</em> <tt class="literal"><span class="pre"><a href="./accumulate.html" class="identifier">accumulate</a></span></tt> is a synonym for <a class="reference internal" href="./fold.html">fold</a> — <em>end note</em>]</p> 36</div> 37<div class="section" id="id529"> 38<h3><a class="subsection-title" href="#header" name="header">Header</a></h3> 39<pre class="literal-block"> 40#include <<a href="../../../../boost/mpl/accumulate.hpp" class="header">boost/mpl/accumulate.hpp</a>> 41</pre> 42</div> 43<div class="section" id="id530"> 44<h3><a class="subsection-title" href="#parameters" name="parameters">Parameters</a></h3> 45<table border="1" class="docutils table"> 46<colgroup> 47<col width="15%" /> 48<col width="32%" /> 49<col width="53%" /> 50</colgroup> 51<thead valign="bottom"> 52<tr><th class="head">Parameter</th> 53<th class="head">Requirement</th> 54<th class="head">Description</th> 55</tr> 56</thead> 57<tbody valign="top"> 58<tr><td><tt class="literal"><span class="pre">Sequence</span></tt></td> 59<td><a class="reference internal" href="./forward-sequence.html">Forward Sequence</a></td> 60<td>A sequence to iterate.</td> 61</tr> 62<tr><td><tt class="literal"><span class="pre">State</span></tt></td> 63<td>Any type</td> 64<td>The initial state for the first <tt class="literal"><span class="pre">ForwardOp</span></tt> 65application.</td> 66</tr> 67<tr><td><tt class="literal"><span class="pre">ForwardOp</span></tt></td> 68<td>Binary <a class="reference internal" href="./lambda-expression.html">Lambda Expression</a></td> 69<td>The operation to be executed on forward 70traversal.</td> 71</tr> 72</tbody> 73</table> 74</div> 75<div class="section" id="id531"> 76<h3><a class="subsection-title" href="#expression-semantics" name="expression-semantics">Expression semantics</a></h3> 77<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> 78<pre class="literal-block"> 79typedef <a href="./accumulate.html" class="identifier">accumulate</a><s,state,op>::type t; 80</pre> 81<table class="docutils field-list" frame="void" rules="none"> 82<col class="field-name" /> 83<col class="field-body" /> 84<tbody valign="top"> 85<tr class="field"><th class="field-name">Return type:</th><td class="field-body"><p class="first">A type.</p> 86</td> 87</tr> 88<tr class="field"><th class="field-name">Semantics:</th><td class="field-body"><p class="first">Equivalent to</p> 89<pre class="last literal-block"> 90typedef <a href="./fold.html" class="identifier">fold</a><s,state,op>::type t; 91</pre> 92</td> 93</tr> 94</tbody> 95</table> 96</div> 97<div class="section" id="id532"> 98<h3><a class="subsection-title" href="#complexity" name="complexity">Complexity</a></h3> 99<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> 100</div> 101<div class="section" id="id533"> 102<h3><a class="subsection-title" href="#example" name="example">Example</a></h3> 103<pre class="literal-block"> 104typedef <a href="./vector.html" class="identifier">vector</a><long,float,short,double,float,long,long double> types; 105typedef <a href="./accumulate.html" class="identifier">accumulate</a>< 106 types 107 , <a href="./int.html" class="identifier">int_</a><0> 108 , <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> > 109 >::type number_of_floats; 110 111<a href="./assert-relation.html" class="identifier">BOOST_MPL_ASSERT_RELATION</a>( number_of_floats::value, ==, 4 ); 112</pre> 113</div> 114<div class="section" id="id534"> 115<h3><a class="subsection-title" href="#see-also" name="see-also">See also</a></h3> 116<p><a class="reference internal" href="./algorithms.html">Algorithms</a>, <a class="reference internal" href="./fold.html">fold</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> 117</div> 118</div> 119 120<div class="footer-separator"></div> 121<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./reverse-iter-fold.html" class="navigation-link">Prev</a> <a href="./querying-algorithms.html" class="navigation-link">Next</a></span><span class="navigation-group-separator"> | </span><span class="navigation-group"><a href="./reverse-iter-fold.html" class="navigation-link">Back</a> Along</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> 122<td><div class="copyright-footer"><div class="copyright">Copyright © 2001-2009 Aleksey Gurtovoy and David Abrahams</div> 123Distributed under the Boost Software License, Version 1.0. (See accompanying 124file 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> 125</html> 126