[counted.iter.nav]

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

## 24.5 Iterator adaptors [[predef.iterators]](predef.iterators#counted.iter.nav)

### 24.5.7 Counted iterators [[iterators.counted]](iterators.counted#counted.iter.nav)

#### 24.5.7.5 Navigation [counted.iter.nav]

[ð](#lib:operator++,counted_iterator)

`constexpr counted_iterator& operator++();
`

[1](#1)

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

*Hardened preconditions*: length > 0 is true[.](#1.sentence-1)

[2](#2)

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

*Effects*: Equivalent to:++current;--length;return *this;

[ð](#lib:operator++,counted_iterator_)

`constexpr decltype(auto) operator++(int);
`

[3](#3)

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

*Hardened preconditions*: length > 0 is true[.](#3.sentence-1)

[4](#4)

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

*Effects*: Equivalent to:--length;try { return current++; }catch(...) { ++length; throw; }

[ð](#lib:operator++,counted_iterator__)

`constexpr counted_iterator operator++(int)
  requires [forward_iterator](iterator.concept.forward#concept:forward_iterator "24.3.4.11 Concept forward_­iterator [iterator.concept.forward]")<I>;
`

[5](#5)

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

*Effects*: Equivalent to:counted_iterator tmp = *this;++*this;return tmp;

[ð](#lib:operator--,counted_iterator)

`constexpr counted_iterator& operator--()
  requires [bidirectional_iterator](iterator.concept.bidir#concept:bidirectional_iterator "24.3.4.12 Concept bidirectional_­iterator [iterator.concept.bidir]")<I>;
`

[6](#6)

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

*Effects*: Equivalent to:--current;++length;return *this;

[ð](#lib:operator--,counted_iterator_)

`constexpr counted_iterator operator--(int)
  requires [bidirectional_iterator](iterator.concept.bidir#concept:bidirectional_iterator "24.3.4.12 Concept bidirectional_­iterator [iterator.concept.bidir]")<I>;
`

[7](#7)

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

*Effects*: Equivalent to:counted_iterator tmp = *this;--*this;return tmp;

[ð](#lib:operator+,counted_iterator)

`constexpr counted_iterator operator+(iter_difference_t<I> n) const
  requires [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]")<I>;
`

[8](#8)

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

*Effects*: Equivalent to: return counted_iterator(current + n, length - n);

[ð](#lib:operator+,counted_iterator_)

`friend constexpr counted_iterator operator+(
  iter_difference_t<I> n, const counted_iterator& x)
    requires [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]")<I>;
`

[9](#9)

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

*Effects*: Equivalent to: return x + n;

[ð](#lib:operator+=,counted_iterator)

`constexpr counted_iterator& operator+=(iter_difference_t<I> n)
  requires [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]")<I>;
`

[10](#10)

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

*Hardened preconditions*: n <= length is true[.](#10.sentence-1)

[11](#11)

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

*Effects*: Equivalent to:current += n;
length -= n;return *this;

[ð](#lib:operator-,counted_iterator)

`constexpr counted_iterator operator-(iter_difference_t<I> n) const
  requires [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]")<I>;
`

[12](#12)

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

*Effects*: Equivalent to: return counted_iterator(current - n, length + n);

[ð](#lib:operator-,counted_iterator_)

`template<[common_with](concept.common#concept:common_with "18.4.6 Concept common_­with [concept.common]")<I> I2>
  friend constexpr iter_difference_t<I2> operator-(
    const counted_iterator& x, const counted_iterator<I2>& y);
`

[13](#13)

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

*Preconditions*: x and y refer to elements of the same
sequence ([[counted.iterator]](counted.iterator "24.5.7.1 Class template counted_­iterator"))[.](#13.sentence-1)

[14](#14)

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

*Effects*: Equivalent to: return y.length - x.length;

[ð](#lib:operator-,counted_iterator__)

`friend constexpr iter_difference_t<I> operator-(
  const counted_iterator& x, default_sentinel_t) noexcept;
`

[15](#15)

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

*Effects*: Equivalent to:return -x.length;

[ð](#lib:operator-,counted_iterator___)

`friend constexpr iter_difference_t<I> operator-(
  default_sentinel_t, const counted_iterator& y) noexcept;
`

[16](#16)

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

*Effects*: Equivalent to: return y.length;

[ð](#lib:operator-=,counted_iterator)

`constexpr counted_iterator& operator-=(iter_difference_t<I> n)
  requires [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]")<I>;
`

[17](#17)

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

*Hardened preconditions*: -n <= length is true[.](#17.sentence-1)

[18](#18)

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

*Effects*: Equivalent to:current -= n;
length += n;return *this;
