title: Understanding std::accumulate
body: <p>I want to know why <code>std::accumulate</code> (aka reduce) 3rd parameter is needed. For those who do not know what <code>accumulate</code> is, it's used like so:</p>
  
  <pre><code>vector&lt;int&gt; V{1,2,3};  
  int sum = accumulate(V.begin(), V.end(), 0);
  // sum == 6
  </code></pre>
  
  <p>Call to <code>accumulate</code> is equivalent to:</p>
  
  <pre><code>sum = 0;  // 0 - value of 3rd param
  for (auto x : V)  sum += x;
  </code></pre>
  
  <p>There is also optional 4th parameter, which allow to replace addition with any other operation. </p>
  
  <p>Rationale that I've heard is that if you need let say not to add up, but multiply elements of a vector, we need other (non-zero) initial value:</p>
  
  <pre><code>vector&lt;int&gt; V{1,2,3};
  int product = accumulate(V.begin(), V.end(), 1, multiplies&lt;int&gt;());
  </code></pre>
  
  <p>But why not do like Python - set initial value for <code>V.begin()</code>, and use range starting from <code>V.begin()+1</code>. Something like this: </p>
  
  <pre><code>int sum = accumulate(V.begin()+1, V.end(), V.begin());
  </code></pre>
  
  <p>This will work for any op. Why is 3rd parameter needed at all?</p>