Why is an equivalent range representation required for updating?

Since C ++ 11 and before 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 with C ++ 17, equivalence will (apparently) be updated to this:

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

At first glance, the only difference that I see is that __begin and __end can no longer share types if they are (let's __end it this way) comparable.

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

+5
source share

Source: https://habr.com/ru/post/1261467/


All Articles