title: c++ accumulate how to apply specific function to last element
body: <p>I have a question regarding std::accumulate.</p>
  
  <p>Typically, accumulate will take a <code>std::vector&lt;U&gt; vect</code>, a seed of type <code>T</code> and will (left) fold the function <code>f</code> <code>TxU-&gt;U</code> for that range:</p>
  
  <pre><code>T result = accumulate( vect.begin(), vect.end(), seed, f);
  </code></pre>
  
  <p>Is there a natural way to apply a specific version of <code>f</code> for the last element?
  This is for a PDE, I have a special condition for the final step.</p>
  
  <p>We can do something like:</p>
  
  <pre><code>T result1 = accumulate( vect.begin(), vect.end()-1, seed, f1);
  T result2 = f2( result1, vect.back() );
  </code></pre>
  
  <p>But I'm wondering if there is a more natural way since f2 is actually a special case of f1.</p>
  
  <p>Thanks</p>