[iterators.counted]

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

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

### 24.5.7 Counted iterators [iterators.counted]

#### [24.5.7.1](#counted.iterator) Class template counted_iterator [[counted.iterator]](counted.iterator)

[1](#counted.iterator-1)

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

Class template counted_iterator is an iterator adaptor
with the same behavior as the underlying iterator except that
it keeps track of the distance to the end of its range[.](#counted.iterator-1.sentence-1)

It can be used together with default_sentinel in calls to generic algorithms to operate on
a range of N elements starting at a given position
without needing to know the end position a priori[.](#counted.iterator-1.sentence-2)

[2](#counted.iterator-2)

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

[*Example [1](#counted.iterator-example-1)*: list<string> s;// populate the list s with at least 10 strings vector<string> v;// copies 10 strings into v: ranges::copy(counted_iterator(s.begin(), 10), default_sentinel, back_inserter(v)); â *end example*]

[3](#counted.iterator-3)

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

Two values i1 and i2 of typescounted_iterator<I1> andcounted_iterator<I2> refer to elements of the same sequence if and only if
there exists some integer n such thatnext(i1.base(), i1.count() + n) andnext(i2.base(), i2.count() + n) refer to the same (possibly past-the-end) element[.](#counted.iterator-3.sentence-1)

[ð](#lib:counted_iterator)

namespace std {template<[input_or_output_iterator](iterator.concept.iterator#concept:input_or_output_iterator "24.3.4.6 Concept input_­or_­output_­iterator [iterator.concept.iterator]") I>class counted_iterator {public:using iterator_type = I; using value_type = iter_value_t<I>; // present only// if I models [indirectly_readable](iterator.concept.readable#concept:indirectly_readable "24.3.4.2 Concept indirectly_­readable [iterator.concept.readable]")using difference_type = iter_difference_t<I>; using iterator_concept = typename I::iterator_concept; // present only// if the [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3 Qualified names [expr.prim.id.qual]") I​::​iterator_concept is valid and denotes a typeusing iterator_category = typename I::iterator_category; // present only// if the [*qualified-id*](expr.prim.id.qual#nt:qualified-id "7.5.5.3 Qualified names [expr.prim.id.qual]") I​::​iterator_category is valid and denotes a typeconstexpr counted_iterator() requires [default_initializable](concept.default.init#concept:default_initializable "18.4.12 Concept default_­initializable [concept.default.init]")<I> = default; constexpr counted_iterator(I x, iter_difference_t<I> n); template<class I2>requires [convertible_to](concept.convertible#concept:convertible_to "18.4.4 Concept convertible_­to [concept.convertible]")<const I2&, I>constexpr counted_iterator(const counted_iterator<I2>& x); template<class I2>requires [assignable_from](concept.assignable#concept:assignable_from "18.4.8 Concept assignable_­from [concept.assignable]")<I&, const I2&>constexpr counted_iterator& operator=(const counted_iterator<I2>& x); constexpr const I& base() const & noexcept; constexpr I base() &&; constexpr iter_difference_t<I> count() const noexcept; constexpr decltype(auto) operator*(); constexpr decltype(auto) operator*() constrequires [*dereferenceable*](iterator.synopsis#concept:dereferenceable "24.2 Header <iterator>&nbsp;synopsis [iterator.synopsis]")<const I>; constexpr auto operator->() const noexceptrequires [contiguous_iterator](iterator.concept.contiguous#concept:contiguous_iterator "24.3.4.14 Concept contiguous_­iterator [iterator.concept.contiguous]")<I>; constexpr counted_iterator& operator++(); constexpr decltype(auto) operator++(int); 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>; constexpr counted_iterator& operator--()requires [bidirectional_iterator](iterator.concept.bidir#concept:bidirectional_iterator "24.3.4.12 Concept bidirectional_­iterator [iterator.concept.bidir]")<I>; 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>; constexpr counted_iterator operator+(iter_difference_t<I> n) constrequires [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]")<I>; 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>; 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>; constexpr counted_iterator operator-(iter_difference_t<I> n) constrequires [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]")<I>; 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); friend constexpr iter_difference_t<I> operator-(const counted_iterator& x, default_sentinel_t) noexcept; friend constexpr iter_difference_t<I> operator-( default_sentinel_t, const counted_iterator& y) noexcept; 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>; constexpr decltype(auto) operator[](iter_difference_t<I> n) constrequires [random_access_iterator](iterator.concept.random.access#concept:random_access_iterator "24.3.4.13 Concept random_­access_­iterator [iterator.concept.random.access]")<I>; template<[common_with](concept.common#concept:common_with "18.4.6 Concept common_­with [concept.common]")<I> I2>friend constexpr bool operator==(const counted_iterator& x, const counted_iterator<I2>& y); friend constexpr bool operator==(const counted_iterator& x, default_sentinel_t) noexcept; template<[common_with](concept.common#concept:common_with "18.4.6 Concept common_­with [concept.common]")<I> I2>friend constexpr strong_ordering operator<=>(const counted_iterator& x, const counted_iterator<I2>& y); friend constexpr decltype(auto) iter_move(const counted_iterator& i)noexcept(noexcept(ranges::iter_move(i.current)))requires [input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]")<I>; template<[indirectly_swappable](alg.req.ind.swap#concept:indirectly_swappable "24.3.7.4 Concept indirectly_­swappable [alg.req.ind.swap]")<I> I2>friend constexpr void iter_swap(const counted_iterator& x, const counted_iterator<I2>& y)noexcept(noexcept(ranges::iter_swap(x.current, y.current))); private: I current = I(); // *exposition only* iter_difference_t<I> length = 0; // *exposition only*}; template<[input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]") I>requires [same_as](concept.same#concept:same_as "18.4.2 Concept same_­as [concept.same]")<*ITER_TRAITS*(I), iterator_traits<I>> // see [[iterator.concepts.general]](iterator.concepts.general "24.3.4.1 General")struct iterator_traits<counted_iterator<I>> : iterator_traits<I> {using pointer = conditional_t<[contiguous_iterator](iterator.concept.contiguous#concept:contiguous_iterator "24.3.4.14 Concept contiguous_­iterator [iterator.concept.contiguous]")<I>,
 add_pointer_t<iter_reference_t<I>>, void>; };}

#### [24.5.7.2](#counted.iter.const) Constructors and conversions [[counted.iter.const]](counted.iter.const)

[ð](#lib:counted_iterator,constructor)

`constexpr counted_iterator(I i, iter_difference_t<I> n);
`

[1](#counted.iter.const-1)

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

*Hardened preconditions*: n >= 0 is true[.](#counted.iter.const-1.sentence-1)

[2](#counted.iter.const-2)

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

*Effects*: Initializes current with std​::​move(i) andlength with n[.](#counted.iter.const-2.sentence-1)

[ð](#lib:counted_iterator,constructor_)

`template<class I2>
  requires [convertible_to](concept.convertible#concept:convertible_to "18.4.4 Concept convertible_­to [concept.convertible]")<const I2&, I>
    constexpr counted_iterator(const counted_iterator<I2>& x);
`

[3](#counted.iter.const-3)

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

*Effects*: Initializes current with x.current andlength with x.length[.](#counted.iter.const-3.sentence-1)

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

`template<class I2>
  requires [assignable_from](concept.assignable#concept:assignable_from "18.4.8 Concept assignable_­from [concept.assignable]")<I&, const I2&>
    constexpr counted_iterator& operator=(const counted_iterator<I2>& x);
`

[4](#counted.iter.const-4)

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

*Effects*: Assigns x.current to current andx.length to length[.](#counted.iter.const-4.sentence-1)

[5](#counted.iter.const-5)

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

*Returns*: *this[.](#counted.iter.const-5.sentence-1)

#### [24.5.7.3](#counted.iter.access) Accessors [[counted.iter.access]](counted.iter.access)

[ð](#lib:base,counted_iterator)

`constexpr const I& base() const & noexcept;
`

[1](#counted.iter.access-1)

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

*Effects*: Equivalent to: return current;

[ð](#lib:base,counted_iterator_)

`constexpr I base() &&;
`

[2](#counted.iter.access-2)

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

*Returns*: std​::​move(current)[.](#counted.iter.access-2.sentence-1)

[ð](#lib:count,counted_iterator)

`constexpr iter_difference_t<I> count() const noexcept;
`

[3](#counted.iter.access-3)

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

*Effects*: Equivalent to: return length;

#### [24.5.7.4](#counted.iter.elem) Element access [[counted.iter.elem]](counted.iter.elem)

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

`constexpr decltype(auto) operator*();
constexpr decltype(auto) operator*() const
  requires [dereferenceable](iterator.synopsis#concept:dereferenceable "24.2 Header <iterator>&nbsp;synopsis [iterator.synopsis]")<const I>;
`

[1](#counted.iter.elem-1)

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

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

[2](#counted.iter.elem-2)

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

*Effects*: Equivalent to: return *current;

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

`constexpr auto operator->() const noexcept
  requires [contiguous_iterator](iterator.concept.contiguous#concept:contiguous_iterator "24.3.4.14 Concept contiguous_­iterator [iterator.concept.contiguous]")<I>;
`

[3](#counted.iter.elem-3)

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

*Effects*: Equivalent to: return to_address(current);

[ð](#lib:operator%5b%5d,counted_iterator)

`constexpr decltype(auto) 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>;
`

[4](#counted.iter.elem-4)

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

*Hardened preconditions*: n < length is true[.](#counted.iter.elem-4.sentence-1)

[5](#counted.iter.elem-5)

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

*Effects*: Equivalent to: return current[n];

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

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

`constexpr counted_iterator& operator++();
`

[1](#counted.iter.nav-1)

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

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

[2](#counted.iter.nav-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](#counted.iter.nav-3)

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

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

[4](#counted.iter.nav-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](#counted.iter.nav-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](#counted.iter.nav-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](#counted.iter.nav-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](#counted.iter.nav-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](#counted.iter.nav-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](#counted.iter.nav-10)

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

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

[11](#counted.iter.nav-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](#counted.iter.nav-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](#counted.iter.nav-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"))[.](#counted.iter.nav-13.sentence-1)

[14](#counted.iter.nav-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](#counted.iter.nav-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](#counted.iter.nav-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](#counted.iter.nav-17)

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

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

[18](#counted.iter.nav-18)

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

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

#### [24.5.7.6](#counted.iter.cmp) Comparisons [[counted.iter.cmp]](counted.iter.cmp)

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

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

[1](#counted.iter.cmp-1)

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

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

[2](#counted.iter.cmp-2)

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

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

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

`friend constexpr bool operator==(
  const counted_iterator& x, default_sentinel_t) noexcept;
`

[3](#counted.iter.cmp-3)

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

*Effects*: Equivalent to: return x.length == 0;

[ð](#lib:operator%3c=%3e,counted_iterator)

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

[4](#counted.iter.cmp-4)

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

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

[5](#counted.iter.cmp-5)

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

*Effects*: Equivalent to: return y.length <=> x.length;

[6](#counted.iter.cmp-6)

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

[*Note [1](#counted.iter.cmp-note-1)*:

The argument order in the *Effects*: element is reversed
because length counts down, not up[.](#counted.iter.cmp-6.sentence-1)

â *end note*]

#### [24.5.7.7](#counted.iter.cust) Customizations [[counted.iter.cust]](counted.iter.cust)

[ð](#lib:iter_move,counted_iterator)

`friend constexpr decltype(auto)
  iter_move(const counted_iterator& i)
    noexcept(noexcept(ranges::iter_move(i.current)))
    requires [input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]")<I>;
`

[1](#counted.iter.cust-1)

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

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

[2](#counted.iter.cust-2)

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

*Effects*: Equivalent to: return ranges​::​iter_move(i.current);

[ð](#lib:iter_swap,counted_iterator)

`template<[indirectly_swappable](alg.req.ind.swap#concept:indirectly_swappable "24.3.7.4 Concept indirectly_­swappable [alg.req.ind.swap]")<I> I2>
  friend constexpr void
    iter_swap(const counted_iterator& x, const counted_iterator<I2>& y)
      noexcept(noexcept(ranges::iter_swap(x.current, y.current)));
`

[3](#counted.iter.cust-3)

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

*Hardened preconditions*: Both x.length > 0 and y.length > 0 are true[.](#counted.iter.cust-3.sentence-1)

[4](#counted.iter.cust-4)

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

*Effects*: Equivalent to ranges​::​iter_swap(x.current, y.current)[.](#counted.iter.cust-4.sentence-1)
