Why the equivalent representation of a range-for required to be updated?

69 views Asked by At

Since C++11 and until C++17, the range-for loop is equivalent to the following code:

{
    auto && __range = range_expression ; 
    for (auto __begin = begin_expr, __end = end_expr; __begin != __end; ++__begin) { 
        range_declaration = *__begin; 
        loop_statement 
    } 
}

Starting from C++17 the equivalence will be (apparently) updated to this one:

{
    auto && __range = range_expression ; 
    auto __begin = begin_expr ;
    auto __end = end_expr ;
    for ( ; __begin != __end; ++__begin) { 
        range_declaration = *__begin; 
        loop_statement 
    } 
}

At a first glance the only difference I can see is in the fact that __begin and __end have no longer to share the type, as long as they are (let me say) comparable.

Is there any other reason for which this kind of change is required?

0

There are 0 answers