10 Ranges library [ranges]

10.6 Range requirements [ranges.requirements]

10.6.2 Ranges [ranges.range]

The Range concept defines the requirements of a type that allows iteration over its elements by providing a begin iterator and an end sentinel. [ Note: Most algorithms requiring this concept simply forward to an Iterator-based algorithm by calling begin and end.  — end note ]

template <class T> concept bool Range = requires(T&& t) { ranges::begin(t); // not necessarily equality-preserving (see below) ranges::end(t); };

Given an lvalue t of type remove_reference_t<T>, Range<T> is satisfied only if

  • [begin(t),end(t)) denotes a range.

  • Both begin(t) and end(t) are amortized constant time and non-modifying. [ Note: begin(t) and end(t) do not require implicit expression variations ([concepts.lib.general.equality]).  — end note ]

  • If iterator_t<T> satisfies ForwardIterator, begin(t) is equality preserving.

Note: Equality preservation of both begin and end enables passing a Range whose iterator type satisfies ForwardIterator to multiple algorithms and making multiple passes over the range by repeated calls to begin and end. Since begin is not required to be equality preserving when the return type does not satisfy ForwardIterator, repeated calls might not return equal values or might not be well-defined; begin should be called at most once for such a range.  — end note ]