title: How can a template parameter pack have both explicit and deduced arguments?
body: <p>g++, clang++, and MSVC (pre 2018) all <a href="https://godbolt.org/g/dKHFmF" rel="nofollow noreferrer">accept</a> the following C++17 code, resulting in the output &quot;unsigned int&quot; then &quot;int&quot;:</p>
  <pre><code>#include &lt;iostream&gt;
  
  void print_type(int) { std::cout &lt;&lt; &quot;int\n&quot;; }
  void print_type(unsigned int) { std::cout &lt;&lt; &quot;unsigned int\n&quot;; }
  
  template &lt;typename ...T&gt;
  void print_types(T ...args)
  {
      (print_type(args),...);
  }
  
  int main()
  {
      print_types&lt;unsigned int&gt;(1, 1);
  }
  </code></pre>
  <p>I agree that this ought to work this way, but I'm having trouble finding a description of why and exactly how in the Standard.</p>
  <p>First there's [temp.deduct]/2 describing the processing of explicit template arguments before doing the rest of template argument deduction:</p>
  <blockquote>
  <p>[T]he following steps are performed when evaluating an explicitly specified template argument list with respect to a given function template:</p>
  <ul>
  <li><p>... There must not be more arguments than there are parameters unless at least one parameter is a template parameter pack, and there shall be an argument for each non-pack parameter....</p>
  </li>
  <li><p>The specified template argument values are substituted for the corresponding template parameters as specified below.</p>
  </li>
  </ul>
  </blockquote>
  <p>In the example, <code>unsigned int</code> is certainly a &quot;specified template argument value&quot;. But if its &quot;corresponding template parameter&quot; <code>T</code> gets substituted now, it's difficult to see how it could become a longer list of types later.</p>
  <p>For the template argument deduction process, there's [temp.deduct.call]/1:</p>
  <blockquote>
  <p>For a function parameter pack that occurs at the end of the <em>parameter-declaration-list</em>, deduction is performed for each remaining argument of the call, taking the type <code>P</code> of the <em>declarator-id</em> of the function parameter pack as the corresponding function template parameter type. Each deduction deduces template arguments for subsequent positions in the template parameter packs expanded by the function parameter pack.</p>
  </blockquote>
  <p>I take &quot;remaining argument of the call&quot; here to mean arguments after the ones that correspond to function parameters that are not the final function parameter pack.  But that would mean that in my example, the first function argument <code>1</code> is used to deduce <code>T=int</code>.  Does this deduction actually happen, but then get discarded/overridden by the <code>T=unsigned int</code> from the explicit template argument?</p>
  <p>Or maybe &quot;remaining argument of the call&quot; is supposed to mean function arguments after the ones that do not correspond to the final function parameter pack AND after any that correspond to parameter types generated from explicit template arguments; and &quot;subsequent positions in the template parameter packs expanded by the function parameter pack&quot; is supposed to mean sequential positions after any filled by explicit template arguments, but this would be far from clear.  And if so, it's also confusing that there is a list of parameter types associated with the function parameter pack but it's still a function parameter pack.</p>
  <p>[Another possible implementation giving the expected behavior would be: when one or more explicit template arguments <code>A_1</code>, ..., <code>A_k</code> correspond to a template parameter pack <code>P</code>, invent another template parameter pack <code>More_P</code> of the same kind, and substitute each expansion of <code>P</code> with the template argument list {<code>A_1</code>, ..., <code>A_k</code>, <code>More_P...</code>}.  Then <code>More_P</code> can be deduced like any other template parameter pack.  If <code>More_P</code> is never deduced, substitute an empty list for all its expansions before evaluating semantics as for all other deduced substitutions. But there's even less justification for this interpretation in the Standard.]</p>
  <p>Have I missed something in the Standard that better describes how explicit template arguments and deduced template arguments can work together to form a single list for one template parameter pack?</p>