Overload resolution favours to consider {} as being of some fundamental type as opposed to some container.
For example:
#include <iostream>
#include <string>
void foo(const std::string&) {std::cout << "string\n";}
void foo(int) {std::cout << "int\n";}
int main() { foo({}); }
That compiles without any diagnostics and outputs:
int
https://godbolt.org/z/zETfrs5as
If to comment out the int
overload then it works fine with string
.
The question is why? For programmer's standpoint it can be confusing illusion.