title: Compute the sum of absolute values with stl algorithms
body: <p>I would like to use the algorithms of <code>std::numeric</code> to compute the sum of the absolute values of an array, in order to use the gnu parallel extensions (array size is > 500000).</p>
  
  <p>Here is my current code : </p>
  
  <pre><code>double ret = 0;
  for (auto i = 0U; i &lt; length; ++i)
  {
      ret += std::abs(tab[i]);
  }
  return ret;
  </code></pre>
  
  <p>So I thought about doing : </p>
  
  <pre><code>auto sumabs = [] (double a, double b) 
  {
      return std::abs(a) + std::abs(b);
  } 
  
  std::accumulate(tab, tab + length, 0, sumabs);
  </code></pre>
  
  <p>But it is inefficient because if a reduction algorithm is performed (which I sincerely hope for the sake of fast computation!), <code>std::abs</code> will be applied to values which are already >= 0.</p>
  
  <p>So is there any way to do this ? perhaps performing the first step of the reduction "by hand", and let <code>std::accumulate</code> do a simple addition between the rest ? But there will be a copy and a memory hit...</p>