User Tools

Site Tools


This is an old revision of the document!


How begin and end are used in range-for statements.

The rules (from TC++PL4)

The expression after the colon must denote a sequence (a range); that is, it must yield a value for which we can call v.begin() and v.end() or begin(v) and end(v) to obtain iterators (§4.5):

  • the compiler first looks for members begin and end and tries to use those. If a begin or an end is found that cannot be used as a range (e.g., because a member begin is a variable rather than a function), the range-for is an error.
  • Otherwise, the compiler looks for a begin/end member pair in the enclosing scope. If none is found or if what is found cannot be used (e.g., because the begin did not take an argument of the sequence’s type), the range-for is an error.
c_begin_end.1517832846.txt.gz · Last modified: 2018/02/05 12:14 by rpjday