3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>accumulate</title>
5 <link rel="stylesheet" href="../../../../../../../../doc/src/boostbook.css" type="text/css">
6 <meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
7 <link rel="home" href="../../../../index.html" title="Chapter 1. Range 2.0">
8 <link rel="up" href="../numeric.html" title="Numeric algorithms">
9 <link rel="prev" href="../numeric.html" title="Numeric algorithms">
10 <link rel="next" href="adjacent_difference.html" title="adjacent_difference">
12 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13 <table cellpadding="2" width="100%"><tr>
14 <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../../boost.png"></td>
15 <td align="center"><a href="../../../../../../../../index.html">Home</a></td>
16 <td align="center"><a href="../../../../../../../../libs/libraries.htm">Libraries</a></td>
17 <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18 <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19 <td align="center"><a href="../../../../../../../../more/index.htm">More</a></td>
22 <div class="spirit-nav">
23 <a accesskey="p" href="../numeric.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../numeric.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="adjacent_difference.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
26 <div class="titlepage"><div><div><h5 class="title">
27 <a name="range.reference.algorithms.numeric.accumulate"></a><a class="link" href="accumulate.html" title="accumulate">accumulate</a>
28 </h5></div></div></div>
30 <a name="range.reference.algorithms.numeric.accumulate.h0"></a>
31 <span class="phrase"><a name="range.reference.algorithms.numeric.accumulate.prototype"></a></span><a class="link" href="accumulate.html#range.reference.algorithms.numeric.accumulate.prototype">Prototype</a>
35 <pre class="programlisting"><span class="keyword">template</span><span class="special"><</span>
36 <span class="keyword">class</span> <span class="identifier">SinglePassRange</span><span class="special">,</span>
37 <span class="keyword">class</span> <span class="identifier">Value</span>
38 <span class="special">></span>
39 <span class="identifier">Value</span> <span class="identifier">accumulate</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">SinglePassRange</span><span class="special">&</span> <span class="identifier">source_rng</span><span class="special">,</span>
40 <span class="identifier">Value</span> <span class="identifier">init</span><span class="special">);</span>
42 <span class="keyword">template</span><span class="special"><</span>
43 <span class="keyword">class</span> <span class="identifier">SinglePassRange</span><span class="special">,</span>
44 <span class="keyword">class</span> <span class="identifier">Value</span><span class="special">,</span>
45 <span class="keyword">class</span> <span class="identifier">BinaryOperation</span>
46 <span class="special">></span>
47 <span class="identifier">Value</span> <span class="identifier">accumulate</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">SinglePassRange</span><span class="special">&</span> <span class="identifier">source_rng</span><span class="special">,</span>
48 <span class="identifier">Value</span> <span class="identifier">init</span><span class="special">,</span>
49 <span class="identifier">BinaryOperation</span> <span class="identifier">op</span><span class="special">);</span>
54 <a name="range.reference.algorithms.numeric.accumulate.h1"></a>
55 <span class="phrase"><a name="range.reference.algorithms.numeric.accumulate.description"></a></span><a class="link" href="accumulate.html#range.reference.algorithms.numeric.accumulate.description">Description</a>
58 <code class="computeroutput"><span class="identifier">accumulate</span></code> is a generalisation
59 of summation. It computes a binary operation (<code class="computeroutput"><span class="keyword">operator</span><span class="special">+</span></code> in the non-predicate version) of <code class="computeroutput"><span class="identifier">init</span></code> and all of the elements in <code class="computeroutput"><span class="identifier">rng</span></code>.
62 The return value is the resultant value of the above algorithm.
65 <a name="range.reference.algorithms.numeric.accumulate.h2"></a>
66 <span class="phrase"><a name="range.reference.algorithms.numeric.accumulate.definition"></a></span><a class="link" href="accumulate.html#range.reference.algorithms.numeric.accumulate.definition">Definition</a>
69 Defined in the header file <code class="computeroutput"><span class="identifier">boost</span><span class="special">/</span><span class="identifier">range</span><span class="special">/</span><span class="identifier">numeric</span><span class="special">.</span><span class="identifier">hpp</span></code>
72 <a name="range.reference.algorithms.numeric.accumulate.h3"></a>
73 <span class="phrase"><a name="range.reference.algorithms.numeric.accumulate.requirements"></a></span><a class="link" href="accumulate.html#range.reference.algorithms.numeric.accumulate.requirements">Requirements</a>
76 <a name="range.reference.algorithms.numeric.accumulate.h4"></a>
77 <span class="phrase"><a name="range.reference.algorithms.numeric.accumulate.for_the_first_version"></a></span><a class="link" href="accumulate.html#range.reference.algorithms.numeric.accumulate.for_the_first_version">For
80 <div class="orderedlist"><ol class="orderedlist" type="1">
82 <code class="computeroutput"><span class="identifier">SinglePassRange</span></code> is
83 a model of the <a class="link" href="../../../concepts/single_pass_range.html" title="Single Pass Range">Single
84 Pass Range</a> Concept.
87 <code class="computeroutput"><span class="identifier">Value</span></code> is a model
88 of the <code class="computeroutput"><span class="identifier">AssignableConcept</span></code>.
91 An <code class="computeroutput"><span class="keyword">operator</span><span class="special">+</span></code>
92 is defined for a left-hand operand of type <code class="computeroutput"><span class="identifier">Value</span></code>
93 and a right-hand operand of the <code class="computeroutput"><span class="identifier">SinglePassRange</span></code>
97 The return type of the above operator is convertible to <code class="computeroutput"><span class="identifier">Value</span></code>.
101 <a name="range.reference.algorithms.numeric.accumulate.h5"></a>
102 <span class="phrase"><a name="range.reference.algorithms.numeric.accumulate.for_the_second_version"></a></span><a class="link" href="accumulate.html#range.reference.algorithms.numeric.accumulate.for_the_second_version">For
103 the second version</a>
105 <div class="orderedlist"><ol class="orderedlist" type="1">
106 <li class="listitem">
107 <code class="computeroutput"><span class="identifier">SinglePassRange</span></code> is
108 a model of the <a class="link" href="../../../concepts/single_pass_range.html" title="Single Pass Range">Single
109 Pass Range</a> Concept.
111 <li class="listitem">
112 <code class="computeroutput"><span class="identifier">Value</span></code> is a model
113 of the <code class="computeroutput"><span class="identifier">AssignableConcept</span></code>.
115 <li class="listitem">
116 <code class="computeroutput"><span class="identifier">BinaryOperation</span></code> is
117 a model of the <code class="computeroutput"><span class="identifier">BinaryFunctionConcept</span></code>.
119 <li class="listitem">
120 <code class="computeroutput"><span class="identifier">Value</span></code> is convertible
121 to <code class="computeroutput"><span class="identifier">BinaryOperation</span></code>'s
124 <li class="listitem">
125 <code class="computeroutput"><span class="identifier">SinglePassRange</span></code>'s
126 value type is convertible to <code class="computeroutput"><span class="identifier">BinaryOperation</span></code>'s
127 second argument type.
129 <li class="listitem">
130 The return type of <code class="computeroutput"><span class="identifier">BinaryOperation</span></code>
131 is convertible to <code class="computeroutput"><span class="identifier">Value</span></code>.
135 <a name="range.reference.algorithms.numeric.accumulate.h6"></a>
136 <span class="phrase"><a name="range.reference.algorithms.numeric.accumulate.complexity"></a></span><a class="link" href="accumulate.html#range.reference.algorithms.numeric.accumulate.complexity">Complexity</a>
139 Linear. Exactly <code class="computeroutput"><span class="identifier">distance</span><span class="special">(</span><span class="identifier">source_rng</span><span class="special">)</span></code>.
142 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
143 <td align="left"></td>
144 <td align="right"><div class="copyright-footer">Copyright © 2003-2010 Thorsten Ottosen,
146 Distributed under the Boost Software License, Version 1.0. (See accompanying
147 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
152 <div class="spirit-nav">
153 <a accesskey="p" href="../numeric.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../numeric.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="adjacent_difference.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>