This paper provides proposed wording for "option #5" in N3257 by Jonathan Wakely and Bjarne Stroustrup, which specifies that the range-based for loop should look for member functions begin()
and end()
first, and fall back to the current ADL-based behavior only when the type of the range does not contain either "begin" or "end".
Modify 6.5.4 [stmt.ranged]p1 by inserting the following new bullet after the first:
_RangeT
is an array type, begin-expr and end-expr are __range
and __range + __bound
, respectively, where __bound
is the array bound. If _RangeT
is an array of unknown size or an array of incomplete type, the program is ill-formed.;_RangeT
is a class type, the unqualified-ids begin
and end
are looked up in the scope of class _RangeT
as if by class member access lookup (3.4.5), and if either (or both) finds at least one declaration, begin-expr and end-expr are __range.begin()
and __range.end()
, respectively;begin(__range)
and end(__range)
, respectively, where begin and end are looked up with argument-dependent lookup (3.4.2). For the purposes of this name lookup, namespace std is an associated namespace.