23 Iterators library [iterators]

23.3 Iterator requirements [iterator.requirements]

23.3.4 Iterator concepts [iterator.concepts]

23.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]

The sized_­sentinel_­for concept specifies requirements on an input_­or_­output_­iterator type I and a corresponding sentinel_­for<I> that allow the use of the - operator to compute the distance between them in constant time.
template<class S, class I> concept sized_­sentinel_­for = sentinel_­for<S, I> && !disable_sized_sentinel_for<remove_cv_t<S>, remove_cv_t<I>> && requires(const I& i, const S& s) { { s - i } -> same_­as<iter_difference_t<I>>; { i - s } -> same_­as<iter_difference_t<I>>; };
Let i be an iterator of type I, and s a sentinel of type S such that [i, s) denotes a range.
Let N be the smallest number of applications of ++i necessary to make bool(i == s) be true.
S and I model sized_­sentinel_­for<S, I> only if
  • If N is representable by iter_­difference_­t<I>, then s - i is well-defined and equals N.
  • If is representable by iter_­difference_­t<I>, then i - s is well-defined and equals .
template<class S, class I> inline constexpr bool disable_sized_sentinel_for = false;
Remarks: Pursuant to [namespace.std], users may specialize disable_­sized_­sentinel_­for for cv-unqualified non-array object types S and I if S and/or I is a program-defined type.
Such specializations shall be usable in constant expressions ([expr.const]) and have type const bool.
[Note
:
disable_­sized_­sentinel_­for allows use of sentinels and iterators with the library that satisfy but do not in fact model sized_­sentinel_­for.
— end note
]
[Example
:
The sized_­sentinel_­for concept is modeled by pairs of random_­access_­iterators ([iterator.concept.random.access]) and by counted iterators and their sentinels ([counted.iterator]).
— end example
]