In cppreference.com, there is an example:
template<class T>
void f(T, T*); // #1
template<class T>
void f(T, int*); // #2
void m(int* p)
{
f(0, p); // deduction for #1: void f(T, T*) [T = int]
// deduction for #2: void f(T, int*) [T = int]
// partial ordering:
// #1 from #2: void(T,T*) from void(U1,int*): P1=T, A1=U1: T=U1
// P2=T*, A2=int*: T=int: fails
// #2 from #1: void(T,int*) from void(U1,U2*): P1=T A1=U1: T=U1
// P2=int* A2=U2*: fails
// neither is more specialized w.r.t T, the call is ambiguous
}
I think the deduction procedure "#1 from #2" is success because "P2=T*, A2=int*: T=int". But it fails, I don't know the reason.
CodePudding user response:
For each type, non-type, and template parameter, including parameter packs, a unique fictitious type, value, or template is generated and substituted into function type of the template
U1
here is not a template type; it's a unique ficitious type and it's different from int
, so the deduction fails.