#include <vector>
int main()
{
auto v = std::vector{std::vector<int>{}};
return v.front().empty(); // error
}
See online demo
However, according to Scott Meyers' Effective Modern C++ (emphasis in original):
If, however, one or more constructors declare a parameter of type
std::initializer_list
, calls using the braced initialization syntax strongly prefer the overloads takingstd::initializer_lists
. Strongly. If there's any way for compilers to construe a call using a braced initializer to be a constructor taking astd::initializer_list
, compilers will employ that interpretation.
So, I think std::vector{std::vector<int>{}};
should produce an object of std::vector<std::vector<int>>
rather than std::vector<int>
.
Who is wrong? and why?
std::vector{std::vector<int>{}}
founds copy/move constructor. – Slumpauto v = std::vector{{std::vector<int>{}}};
cppinsights.io/s/7a34c18e – Briannabriannestd::initializer_list
not take the priority as Scott said? @Slump – Aida