9 Iterators library [iterators]

9.3 Iterator requirements [iterator.requirements]

9.3.10 Concept SizedSentinel [iterators.sizedsentinel]

The SizedSentinel concept specifies requirements on an Iterator and a Sentinel that allow the use of the - operator to compute the distance between them in constant time.

template <class S, class I> concept bool SizedSentinel = Sentinel<S, I> && !disable_sized_sentinel<remove_cv_t<S>, remove_cv_t<I>> && requires(const I& i, const S& s) { { s - i } -> Same<difference_type_t<I>>&&; { i - s } -> Same<difference_type_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. SizedSentinel<S, I> is satisfied only if:

  • If N is representable by difference_type_t<I>, then s - i is well-defined and equals N.

  • If -N is representable by difference_type_t<I>, then i - s is well-defined and equals -N.

Note: disable_sized_sentinel provides a mechanism to enable use of sentinels and iterators with the library that meet the syntactic requirements but do not in fact satisfy SizedSentinel. A program that instantiates a library template that requires SizedSentinel with an iterator type I and sentinel type S that meet the syntactic requirements of SizedSentinel<S, I> but do not satisfy SizedSentinel is ill-formed with no diagnostic required unless disable_sized_sentinel<S, I> evaluates to true ([structure.requirements]).  — end note ]

Note: The SizedSentinel concept is satisfied by pairs of RandomAccessIterators ([iterators.random.access]) and by counted iterators and their sentinels ([counted.iterator]). — end note ]