The following two things wouldn't work
// "{ 1, 2, 3 }" not an expression
for(int i : { 1, 2, 3 }) ...;
// "{ 1, 2, 3 }" not an assignment-expression
void f(vector<int> v = { 1, 2, 3 });
Instead, the really ugly following syntax is needed to make this work
for(int i : initializer_list<int>{1, 2, 3}) ...;
In both cases, it appears to be non-ambiguous to me to support using
the "initializer-clause" production, which could either be a braced-
init-list or an assignment-expression. This would then exclude the
comma operator as a toplevel-expression - but do you really think the
following is all that worth to support? I don't
// oops, no "begin" for argument "int" found.
for(int i : 1, 2, 3) ...;
The change to support the range based for loop, as far as i can see
follow. Instead of saying at 6.5.4
"where __range, __begin, and __end are variables defined for
exposition only, _RangeT is the type of the expression, and begin-
expr and end-expr are determined as follows:"
We need to say
"where __range, __begin, and __end are variables defined for
exposition only, _RangeT is the type of the expression '__range', and
begin-expr and end-expr are determined as follows:"
Along with changing "expression" in the grammar to "initializer-
clause".
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std...@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Are you sure? �7.1.6.4/6 seems to disagree. It contains the following
examples:
auto x1 = {1,2}; // decltype(x1) is std::initializer_list<int>
auto x2 = {1,2.0}; // error: cannot deduce element type
Stroustrup's C++0x FAQ still contains the following example:
for (const auto x : { 1,2,3,5,8,13,21,34 }) cout << x << '\n';
(http://www.research.att.com/~bs/C++0xFAQ.html)
Cheers!
SG