9 Statements [stmt.stmt]

9.5 Iteration statements [stmt.iter]

9.5.4 The range-based for statement [stmt.ranged]

The range-based for statement

for ( for-range-declaration : for-range-initializer ) statement

is equivalent to

{
	auto &&__range = for-range-initializer ;
	auto __begin = begin-expr ;
	auto __end = end-expr ;
	for ( ; __begin != __end; ++__begin ) {
		for-range-declaration = *__begin;
		statement
	}
}

where

[Example:

int array[5] = { 1, 2, 3, 4, 5 };
for (int& x : array)
  x *= 2;

end example]

In the decl-specifier-seq of a for-range-declaration, each decl-specifier shall be either a type-specifier or constexpr. The decl-specifier-seq shall not define a class or enumeration.