I have a misunderstanding about the template type deduction :) as I couldn't figure out how the sample code below works:
template<typename T1, typename T2>
auto max(T1 a, T2 b)
{
return b < a ? a : b;
}
template<typename RT, typename T1, typename T2>
RT max(T1 a, T2 b)
{
return b < a ? a : b;
}
int main()
{
auto c = ::max<int>(4, 7.2);
}
So in the main, I have an error saying that the resolution is ambiguous since the two templates fcts are candidate.
So far, what I understand (and hope is correct) is from ::max<int>(4, 7.2);
I will have
- temlplated Fct 1 Signature
double int double
(T1 will be deduced as int, T2 as double ans return type double). - temlplated Fct 2 Signature
int int double
(RT will be deduced as int, T1 as int and T2 as double).
As I know after type deduction there is no type conversion so from the signatures I would say the second fuction is the candidate.
Any clue for how the two functions are candidates for template argument int ?
Thank you