Consider the code below:
#include
#include
void f(std::vector v) {std::cout << __PRETTY_FUNCTION__ <<
Forcing std::vector overload
int main()
{
f(std::vector{42}); // the vector overload is being picked up now
}
Why isn't the vector(initializer_list)
constructor being picked up?
Assume that another header declares a void f(std::set
.
How would you like the compiler to react when faced with f({1})
: construct a vector
or construct a set
?