|Date:||September 9, 2002|
|Author:||John Spicer, Edison Design Group|
|Author:||John Wiegley, Borland|
The description of partial ordering as described in the standard suffers from a number of problems:
The current (understood) rules do not correctly deal with comparison of templates where one of the parameter types is a cv-qualified reference. I say "understood" because it could be argued that the current rules are not complete enough to know for sure how such cases are to be handled. But the generally accepted understanding of the current rules does not produce the desired results.
With respect to #3 above, consider this case:
The original proposal for partial ordering removed top-level references and then top-level cv-qualifiers. This had the property that the call of f produced the desired result but the call of g was ambiguous. The current (understood) rules are that top-level cv-qualifiers are removed before top-level references. This makes the call of g work but breaks f. The rules proposed by this paper provide a mechanism that makes both f and g work without breaking any cases that worked previously.
Change 184.108.40.206 paragraph 2 to read:
Partial ordering selects which of two function templates is more specialized than the other by transforming each template in turn (see next paragraph) and performing template argument deduction using the function parameter types, or in the case of a conversion function the return type. If the deduction succeeds, the transformed function is said to be at least as specialized as the other. If one function is at least as specialized as the other, and the other is not at least as specialized as the first, then the first is more specialized.
Change 220.127.116.11 paragraph 3 to read:
To produce the transformed template, for each type, non-type, or template template parameter synthesize a unique type, value, or class template respectively and substitute that for each occurrence of that parameter in the function type of the template.
Change 18.104.22.168 paragraph 4 to read (note: the section reference should refer to the section added to 14.8.2 below):
Using the transformed function template's function parameter list, or in the case of a conversion function its transformed return type, perform type deduction against the function parameter list (or return type) of the other function. The transformed function is at least as specialized as the other if, and only if, the deduction succeeds and the deduced parameter types (or return type) match the other function's parameter types (or return type) in such a way that no implicit type conversions are required. The mechanism for performing these deductions is given in 14.8.2.x.
Insert the following section before 22.214.171.124 (temp.deduct.type): (Note that this would either be a new 126.96.36.199, or would be given a number like 188.8.131.52a. If neither of these is possible from a troff point of view, this could be made 184.108.40.206)
Deducing template arguments when determining the partial ordering of function templates (temp.deduct.partial)
Template argument deduction is done by comparing certain types associated with the parameter template with the corresponding types from the argument template.
Two sets of types are used to determine the partial ordering. For each of the templates involved there is the original function type and the transformed function type (the creation of the transformed type is described in 220.127.116.11). The deduction process uses the transformed type as the argument template and the original type of the other template as the parameter template. This process is done twice for each type involved in the partial ordering comparison: once using template-1 as the argument template and template-2 as the parameter template and again using template-2 as the argument template and template-1 as the parameter template.
The types used to determine the ordering depend on the context in which the partial ordering is done:
- In the context of a function call, the function template parameter types are used.
- In the context of a call to a conversion operator, the return types of the conversion function templates are used.
- In other contexts (temp.func.order), the function template's function type is used.
Each type from the parameter template and the corresponding type from the argument template are used as the types of P and A.
Before the partial ordering is done, certain transformations are performed on the types used for partial ordering:
- If P is a reference type, P is replaced by the type referred to.
- If A is a reference type, A is replaced by the type referred to.
If both P and A were reference types (before being replaced with the type referred to above), determine which of the two types (if any) is more cv-qualified than the other; otherwise the types are considered to be equally cv-qualified for partial ordering purposes. The result of this determination will be used later.
Remove any top-level cv-qualifiers:
- If P is a cv-qualified type, P is replaced by the cv-unqualified version of P.
- If A is a cv-qualified type, A is replaced by the cv-unqualified version of A.
Using the resulting types P and A the deduction is then done as described in (temp.deduct.type).
If, for a given type, deduction succeeds in both directions (i.e., the types are identical after the transformations above) the more cv-qualified type is considered to be more specialized.
In most cases, all template parameters must have values in order for deduction to succeed, but for partial ordering purposes a template parameter may remain without a value provided it is not used in the types being used for partial ordering. [Note: A template parameter used in a non-deduced context is considered used.]