When I'm trying to compile the following code, the compiler complains:
int main(void)
{
std::initializer_list<int> lst1{};
std::initializer_list<int> lst2{lst1}; // error
}
The compiler (gcc) gives me the following error:
error: could not convert '{lst1}' from '<brace-enclosed initializer list>' to 'std::initializer_list<int>'
But when I tried to use direct-initialization the program compiles fines:
std::initializer_list<int> lst2(lst1); // OK
Why this is well-formed? Why the compiler rejects the list-initialization and allows direct-initialization? Is there's a rule from the standard for that?
Aslo, Is the following code is well-formed? I mean, Can I do this:
int main(void)
{
std::initializer_list<int> lst1{};
std::initializer_list<std::initializer_list<int>> lst2{lst1}; //OK
}
?