Given the following program
#include
template struct id { using type = T; };
template
int func(T1, T2
This is bog-standard partial ordering. We substitute unique types into one of the function templates and try to deduce the other against it. Do it both ways and if deduction only succeeds in one direction, we have an order. If you want to read the arcane rules, see [temp.func.order] and [temp.deduct.partial].
So here,
T1=U1, T2=U2
into the first overload's function type produces int f(U1, U2);
Can we deduce T1
and T2
in the second overload from this? No; both are in non-deduced contexts. Ergo, deduction fails.T1=U1, T2=U2
into the second overload produces int f(id::type, id::type)
(this is conducted in the definition context so we can't substitute further into id
- there may be a specialization somewhere). Can we deduce the T1
and T2
in the first overload from this? Yes, by deducing T1 = id::type
and T2 = id::type
. Deduction succeeds.Since deduction succeeds only in one direction - deducing the first from transformed second - the second is more specialized than the first and is preferentially picked by overload resolution.
The alias template case changes nothing.
These templates are neither equivalent nor functionally equivalent.