Consider this snippet:
#include <iostream>
#include <vector>
void f(std::vector<int>){std::cout << __PRETTY_FUNCTION__ << '\n';}
void f(int x){std::cout << __PRETTY_FUNCTION__ << '\n';}
int main()
{
f({42});
}
If you run it, you can see that the f(int)
overload was preferred, even though std::vector
has an std::initializer_list
constructor (see #8).
Question: Why is the conversion {42}
to int
preferred (instead of conversion to std::vector
, as {42}
is an std::initializer_list
)?