Allowable Argument Conversions



Allowable Argument Conversions

Normally, template deduction attempts to find a substitution of the function template parameters that make the parameterized type P identical to type A. However, when this is not possible, the following differences are tolerable:

  • If the original parameter was declared with a reference declarator, the substituted P type may be more const/volatile-qualified than the A type.

  • If the A type is a pointer or pointer-to-member type, it may be convertible to the substituted P type by a qualification conversion (in other words, a conversion that adds const and/or volatile qualifiers).

  • Unless deduction occurs for a conversion operator template, the substituted P type may be a base class type of the A type, or a pointer to a base class type of the class type for which A is a pointer type. For example:

template<typename T> 
class B<T> { 
}; 

template<typename T> 
class D : B<T> { 
}; 

template<typename T> void f(B<T>*); 

void g(D<long> dl) 
{ 
    f(&dl);  // deduction succeeds with T substituted with long 
} 

The relaxed matching requirements are considered only if an exact match was not possible. Even so, deduction succeeds only if exactly one substitution was found to fit the A type to the substituted P type with these added conversions.