I recall someone once telling me,
"there is no need for
auto
inside range-based for loops. It would not be ambiguous in the language if we were to remove it."
Is that a true statement?
Is the folowing code valid C++ syntax?
for (elem : range){...}
I had assumed this was already valid syntax, but when I went to compile with
clang++ --std=c++1z
, I was shown the following error:
range-based for loop requires type for loop variable
for (elem: range){
The compiler still recognizes this as a range-based for loop, so why can't it also derive the type?
See Question&Answers more detail:os