title: How can I use std::accumulate and a lambda to calculate a mean?
body: <p>I have a standard library container of large numbers, so large that they may cause overflow if I add them together. Let's pretend it's this container:</p>
  
  <pre><code>std::vector&lt;int&gt; v = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
  </code></pre>
  
  <p>I want to calculate the mean of this container, using std::accumulate, but I can't add all the numbers together. I'll just calculate it with <code>v[0]/v.size() + v[1]/v.size() + ...</code>. So I set:</p>
  
  <pre><code>auto lambda = ...;
  std::cout &lt;&lt; std::accumulate(v.begin(), v.end(), 0, lambda) &lt;&lt; std::endl;
  </code></pre>
  
  <p>Here is what I have tried so far, where <code>-&gt;</code> indicates the output:</p>
  
  <pre><code>lambda = [&amp;](int a, int b){return (a + b)/v.size();};  -&gt;  1
  lambda = [&amp;](int a, int b){return a/v.size() + b/v.size();};  -&gt;  1
  lambda = [&amp;](int a, int b){return a/v.size() + b;};  -&gt;  10
  </code></pre>
  
  <p>How can I produce the correct mean such that the output will be <code>5</code>?</p>