*: Regenerate.
[gcc.git] / libstdc++-v3 / doc / html / manual / generalized_numeric_operations.html
1 <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Generalized Operations</title><meta name="generator" content="DocBook XSL-NS Stylesheets V1.76.1"><meta name="keywords" content="
2 ISO C++
3 ,
4 library
5 "><meta name="keywords" content="
6 ISO C++
7 ,
8 runtime
9 ,
10 library
11 "><link rel="home" href="../index.html" title="The GNU C++ Library"><link rel="up" href="numerics.html" title="Chapter 12.  Numerics"><link rel="prev" href="numerics.html" title="Chapter 12.  Numerics"><link rel="next" href="numerics_and_c.html" title="Interacting with C"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Generalized Operations</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="numerics.html">Prev</a> </td><th width="60%" align="center">Chapter 12
12 Numerics
13
14 </th><td width="20%" align="right"> <a accesskey="n" href="numerics_and_c.html">Next</a></td></tr></table><hr></div><div class="section" title="Generalized Operations"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="std.numerics.generalized_ops"></a>Generalized Operations</h2></div></div></div><p>
15 </p><p>There are four generalized functions in the &lt;numeric&gt; header
16 that follow the same conventions as those in &lt;algorithm&gt;. Each
17 of them is overloaded: one signature for common default operations,
18 and a second for fully general operations. Their names are
19 self-explanatory to anyone who works with numerics on a regular basis:
20 </p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p><code class="code">accumulate</code></p></li><li class="listitem"><p><code class="code">inner_product</code></p></li><li class="listitem"><p><code class="code">chapterial_sum</code></p></li><li class="listitem"><p><code class="code">adjacent_difference</code></p></li></ul></div><p>Here is a simple example of the two forms of <code class="code">accumulate</code>.
21 </p><pre class="programlisting">
22 int ar[50];
23 int someval = somefunction();
24
25 // ...initialize members of ar to something...
26
27 int sum = std::accumulate(ar,ar+50,0);
28 int sum_stuff = std::accumulate(ar,ar+50,someval);
29 int product = std::accumulate(ar,ar+50,1,std::multiplies&lt;int&gt;());
30 </pre><p>The first call adds all the members of the array, using zero as an
31 initial value for <code class="code">sum</code>. The second does the same, but uses
32 <code class="code">someval</code> as the starting value (thus, <code class="code">sum_stuff == sum +
33 someval</code>). The final call uses the second of the two signatures,
34 and multiplies all the members of the array; here we must obviously
35 use 1 as a starting value instead of 0.
36 </p><p>The other three functions have similar dual-signature forms.
37 </p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="numerics.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="numerics.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="numerics_and_c.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 12
38 Numerics
39
40  </td><td width="20%" align="center"><a accesskey="h" href="../index.html">Home</a></td><td width="40%" align="right" valign="top"> Interacting with C</td></tr></table></div></body></html>