Consider the following code:
void fnc(int)
{
std::cout << "int";
}
void fnc(long double)
{
std::cout << "long double";
}
int main()
{
fnc(42.3); // error
}
It gives an error because of an ambiguous call to fnc.
However, if we write the next code:
std::variant<int, long double> v{42.3};
std::cout << v.index();
the output is 1, which demonstrates that the double->long double conversion has been chosen.
As far as I know, std::variant follows the C++ rules about conversion ranks, but this example shows the difference. Is there any explanation for such a behavior?