Hello.
Some years ago, when I was first experimenting with C++11's new
features, I remember feeling excited about the possibility of directly
initializing containers from a literal list of values. I also remember
being bit by the fact that compilers will always favor constructor
overloads that take std::initializer_list. I felt disappointed and
wondered how that could have been overlooked or accepted by the
committee. Why did they not choose a syntax which would not lead to
ambiguity? Wouldn't having braces around list elements (in addition to
the braces for the uniform initialization syntax) take care of it?
a) std::vector<int> v{ {4, 1} };
b) std::vector<int> w( {4, 1} };
c) std::vector<int> x{4, 1};
d) std::vector<int> y(4, 1);
a) and b) should produce vector objects with 2 elements, 4 and 1. c) and
d) should produce vectors with 4 elements, all of them equal to 1.
Here is a discussion on Stack Overflow:
http://stackoverflow.com/questions/22501368/why-wasnt-a-double-curly-braces-syntax-preferred-for-constructors-taking-a-std
And here's a post by Scott Meyers on different, but related issues:
http://scottmeyers.blogspot.com.br/2015/09/thoughts-on-vagaries-of-c-initialization.html
Does anybody know if there's any work being done to mend this situation?
Thank you.