The loop is defined to be equivalent to:
for ( auto __begin = ,
__end = ;
__begin != __end;
++__begin ) {
auto& f = *__begin;
// loop body
}
where
is foo.begin()
, or begin(foo)
if there isn't a suitable member function, and likewise for
. (This is a simplification of the specification in C++11 6.5.4, for this particular case where the range is a lvalue of class type).
So you need to define an iterator type that supports pre-increment ++it
, dereference *it
and comparison i1 != i2
; and either
- give
foo
public member functions begin()
and end()
; or
- define non-member functions
begin(foo)
and end(foo)
, in the same namespace as foo
so that they can be found by argument-dependent lookup.