Files
2025-10-25 03:02:53 +03:00

4.3 KiB
Raw Permalink Blame History

[iterator.concept.sizedsentinel]

24 Iterators library [iterators]

24.3 Iterator requirements [iterator.requirements]

24.3.4 Iterator concepts [iterator.concepts]

24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]

1

#

The sized_sentinel_for concept specifies requirements on an input_or_output_iterator type I and a corresponding sentinel_for 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](#concept:sized_sentinel_for "24.3.4.8Concept sized_­sentinel_­for[iterator.concept.sizedsentinel]") = [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7Concept sentinel_­for[iterator.concept.sentinel]")<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](concept.same#concept:same_as "18.4.2Concept same_­as[concept.same]")<iter_difference_t<I>>; { i - s } -> [same_as](concept.same#concept:same_as "18.4.2Concept same_­as[concept.same]")<iter_difference_t<I>>; };

2

#

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:

  • (2.1)

    If N is representable by iter_difference_t, then s - i is well-defined and equals N.

  • (2.2)

    If −N is representable by iter_difference_t, then i - s is well-defined and equals −N.

🔗

template<class S, class I> constexpr bool disable_sized_sentinel_for = false;

3

#

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.

4

#

[Note 1:

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]

5

#

[Example 1:

The sized_sentinel_for concept is modeled by pairs ofrandom_access_iterators ([iterator.concept.random.access]) and by counted iterators and their sentinels ([counted.iterator]).

— end example]