Thomas Köppe wrote the proposal P0614R1 to describe a new feature called “Range-based for statements with initializer”. This document has been approved as part of the C++20 standard.
The document is pretty straightforward since the feature is quite simple. If you have heard of if statement with initializer from C++17, then you have probably already guessed what “range-based for statements with initializer” means.
To understand this new feature, let’s say we want some code to print all the elements of a collection. The first idea would be to use a range-based for loop. But let’s add another requirement: we want to print the index of the element in the collection. Let’s write some code before and after C++20 and compare them.