The final C++11 standard includes provisions for range-based for to \"just work\" for native arrays without having to include
or any other head
GCC 7.1 produces the following error if <initializer_list>
is not included:
error: deducing from brace-enclosed initializer list requires #include <initializer_list>
for (auto i : { 1, 2, 3, 4, 5 })
^
To see this error one should omit <iostream>
, because including <iostream>
will also include <initializer_list>
.
I'd say yes. According to §6.5.4[stmt.ranged]/1, the statement
for (auto i : { 1, 2, 3, 4, 5 })
...
is just equivalent to
auto&& __range = { 1, 2, 3, 4, 5 };
...
and that means an initializer_list<int>
is used, and the <initializer_list>
header needs to be included.