title: variadic templates sum operation left associative
body: <p>The code below works for the: goal for the left associative sum operation: <code>sum(1,2,3,4);</code></p>
  
  <p>However, it won't work correctly for  <code>sum(1,2,3,4,5)</code> or <code>sum(1,2,3,4,5,...)</code>. Anything with more than 4 arguments gives the error:</p>
  
  <blockquote>
    <p>error: no matching function for call to sum(int, int, int, int, int)</p>
  </blockquote>
  
  <p>=================================</p>
  
  <pre><code>template &lt;typename T&gt;
  T sum(const T&amp; v) {
  return v;
  }
  
  template &lt;typename T1, typename T2&gt;
  auto sum(const T1&amp; v1, const T2&amp; v2) -&gt; decltype( v1 + v2) {
  return v1 + v2;
  }
  
  template &lt;typename T1, typename T2, typename... Ts&gt;
  auto sum(const T1&amp; v1, const T2&amp; v2, const Ts&amp;... rest) -&gt; decltype( v1 + v2 +      sum(rest...) ) {
  return v1 + v2 + sum(rest... );
  }
  
  int main() {
      cout &lt;&lt; sum(1,2,3,4); //works correctly
      //cout &lt;&lt; sum(1,2,3,4,5); //compile error
  
  }
  </code></pre>