The current realisation of C++ includes a new kind of loop, named “Range-based for Statement” [1, 2].
It has a form of “for( declaration : expression ) statement” and allows simplification of code. For example, if we have a vector and iterate its elements using a classical for:
vector<int> v = { 10, 11, 12, 13, 14 };
// print all of elements
for( auto iter = v.begin(); iter != v.end(); ++iter )
{
int element = *iter;
cout << element << endl;
}
then we can use the new variant of for:
vector<int> v = { 10, 11, 12, 13, 14 };
// print all of elements
for( int element : v )
{
cout << element << endl;
}
Looks like an influence of Continue reading