Function template parameter pack not at the end of the parameter list
<p>The following code compiles and runs ok.</p>

<pre><code>void foo() {

}

template &lt;typename T, typename... Args&gt;
void foo(T x, Args... args) {
  cout &lt;&lt; x &lt;&lt; endl;
  foo(args...);
}

// inside main()
foo(1,1,1);
</code></pre>

<p>This other code does not compile:</p>

<pre><code>void foo() {

}

template &lt;typename... Args, typename T&gt;
void foo(Args... args, T x) {
  foo(args...);
  cout &lt;&lt; x &lt;&lt; endl;
}

// inside main()
foo(1,1,1);
</code></pre>

<p>The compiler says that there is no matching function for call to <code>foo(1,1,1)</code> and says that <code>foo(Args... args, T x)</code> is a candidate, but template argument deduction/substitution failed, because candidate expects 1 argument, but 3 were provided.</p>

<p>Is there any ambiguity with this situation that no compiler can handle? This compile error just seems illogical to me. Maybe this is not in accordance, on purpose, with the C++ standard?</p>