CWG Issue 692 (original) (raw)

This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 118e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2025-11-05


692. Partial ordering of variadic class template partial specializations

Section: 13.10.3.6 [temp.deduct.type]Status: C++11Submitter: Doug GregorDate: 16 April, 2008

[Voted into the WP at the March, 2011 meeting as paper N3281.]

13.10.3.6 [temp.deduct.type] paragraph 22 describes how we cope with partial ordering between two function templates that differ because one has a function parameter pack while the other has a normal function parameter. However, this paragraph was meant to apply to template parameter packs as well, e.g., to help with partial ordering of class template partial specializations:

template <class T1, class ...Z> class S; // #1 template <class T1, class ...Z> class S<T1, const Z&...> {}; // #2 template <class T1, class T2> class S<T1, const T2&> {};; // #3 S<int, const int&> s; // both #2 and #3 match; #3 is more specialized

(See also issue 818.)

Proposed resolution (March, 2009):

Change 13.10.3.6 [temp.deduct.type] paragraphs 9-10 as follows (and add the example above to paragraph 9):

If P has a form that contains <T> or <i>, then each argumentP_i_ of the respective template argument list of P is compared with the corresponding argumentA_i_ of the corresponding template argument list of A. If the template argument list ofP contains a pack expansion that is not the last template argument, the entire template argument list is a non-deduced context. If P_i_ is a pack expansion, then the pattern of P_i_ is compared with each remaining argument in the template argument list of A. Each comparison deduces template arguments for subsequent positions in the template parameter packs expanded by P_i_. During partial ordering (13.10.3.5 [temp.deduct.partial]), if A_i_was originally a pack expansion and P_i_is not a pack expansion, or if P does not contain a template argument corresponding to A_i_, argument deduction fails.

Similarly, if P has a form that contains(T), then each parameter typeP_i_ of the respective_parameter-type-list_ of P is compared with the corresponding parameter type A_i_ of the corresponding parameter-type-list of A. If the_parameter-declaration_ corresponding toP_i_ is a function parameter pack, then the type of its declarator-id is compared with each remaining parameter type in the parameter-type-list ofA. Each comparison deduces template arguments for subsequent positions in the template parameter packs expanded by the function parameter pack. During partial ordering (13.10.3.5 [temp.deduct.partial]), if A_i_was originally a function parameter pack andP_i_ is not a function parameter pack, or if P does not contain a function parameter type corresponding to A_i_, argument deduction fails. [_Note:_ A function parameter pack can only occur at the end of a _parameter-declaration-list_(9.3.4.6 [dcl.fct]). —_end note_]