[iterator.concept.sizedsentinel]

# 24 Iterators library [[iterators]](./#iterators)

## 24.3 Iterator requirements [[iterator.requirements]](iterator.requirements#iterator.concept.sizedsentinel)

### 24.3.4 Iterator concepts [[iterator.concepts]](iterator.concepts#iterator.concept.sizedsentinel)

#### 24.3.4.8 Concept sized_sentinel_for [iterator.concept.sizedsentinel]

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L1688)

The [sized_sentinel_for](#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]") concept specifies
requirements on an [input_or_output_iterator](iterator.concept.iterator#concept:input_or_output_iterator "24.3.4.6 Concept input_­or_­output_­iterator [iterator.concept.iterator]") type I and
a corresponding [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept sentinel_­for [iterator.concept.sentinel]")<I> that allow the use of the - operator to compute the distance
between them in constant time[.](#1.sentence-1)

[ð](#concept:sized_sentinel_for)

`template<class S, class I>
  concept [sized_sentinel_for](#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]") =
    [sentinel_for](iterator.concept.sentinel#concept:sentinel_for "24.3.4.7 Concept 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.2 Concept same_­as [concept.same]")<iter_difference_t<I>>;
      { i - s } -> [same_as](concept.same#concept:same_as "18.4.2 Concept same_­as [concept.same]")<iter_difference_t<I>>;
    };
`

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L1707)

Let i be an iterator of type I, and s a sentinel of type S such that [i, s) denotes a range[.](#2.sentence-1)

Let N be the smallest number of applications of ++i necessary to make bool(i == s) be true[.](#2.sentence-2)

S and I model [sized_sentinel_for](#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]")<S, I> only if:

- [(2.1)](#2.1)

  If N is representable by iter_difference_t<I>,
 then s - i is well-defined and equals N[.](#2.1.sentence-1)

- [(2.2)](#2.2)

  If âN is representable by iter_difference_t<I>,
 then i - s is well-defined and equals âN[.](#2.2.sentence-1)

[ð](#lib:disable_sized_sentinel_for)

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

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L1729)

*Remarks*: Pursuant to [[namespace.std]](namespace.std "16.4.5.2.1 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[.](#3.sentence-1)

Such specializations shall
be usable in constant expressions ([[expr.const]](expr.const "7.7 Constant expressions")) and
have type const bool[.](#3.sentence-2)

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L1739)

[*Note [1](#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](#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]")[.](#4.sentence-1)

â *end note*]

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L1745)

[*Example [1](#example-1)*:

The [sized_sentinel_for](#concept:sized_sentinel_for "24.3.4.8 Concept sized_­sentinel_­for [iterator.concept.sizedsentinel]") concept is modeled by pairs of[random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]")s ([[iterator.concept.random.access]](iterator.concept.random.access "24.3.4.13 Concept random_­access_­iterator")) and by
counted iterators and their sentinels ([[counted.iterator]](counted.iterator "24.5.7.1 Class template counted_­iterator"))[.](#5.sentence-1)

â *end example*]
