I was looking over some ugly code (that was modifying the underlying sequence while iterating), and to explore the definition of the range-based for
loop, I went to cppreference.
There I noticed something strange:
The range based for
loop changed in C++17, but I do not see the reason for the change, and the code looks the same to me (just "refactored").
So the old one was:
{
auto && __range = range_expression;
for (auto __begin = begin_expr, __end = end_expr; __begin != __end; ++__begin) {
range_declaration = *__begin;
loop_statement
}
}
The new one is
{
auto && __range = range_expression;
auto __begin = begin_expr;
auto __end = end_expr;
for ( ; __begin != __end; ++__begin) {
range_declaration = *__begin;
loop_statement
}
}
Why was this change made, and does it make any legal C++14 programs exhibit undefined behavior (UB) in C++17?