24 Ranges library [ranges]

24.7 Range adaptors [range.adaptors]

24.7.15 Elements view [range.elements]

24.7.15.3 Class template elements_­view​::​iterator [range.elements.iterator]

namespace std::ranges {
  template<class V, size_t N>
  template<bool Const>
  class elements_view<V, N>::iterator {                 // exposition only
    using base_t = conditional_t<Const, const V, V>;
    friend iterator<!Const>;

    iterator_t<base_t> current_;
  public:
    using iterator_category = typename iterator_traits<iterator_t<base_t>>::iterator_category;
    using value_type = remove_cvref_t<tuple_element_t<N, range_value_t<base_t>>>;
    using difference_type = range_difference_t<base_t>;

    iterator() = default;
    constexpr explicit iterator(iterator_t<base_t> current);
    constexpr iterator(iterator<!Const> i)
      requires Const && convertible_to<iterator_t<V>, iterator_t<base_t>>;

    constexpr iterator_t<base_t> base() const &
      requires copyable<iterator_t<base_t>>;
    constexpr iterator_t<base_t> base() &&;

    constexpr decltype(auto) operator*() const
    { return get<N>(*current_); }

    constexpr iterator& operator++();
    constexpr void operator++(int) requires (!forward_range<base_t>);
    constexpr iterator operator++(int) requires forward_range<base_t>;

    constexpr iterator& operator--() requires bidirectional_range<base_t>;
    constexpr iterator operator--(int) requires bidirectional_range<base_t>;

    constexpr iterator& operator+=(difference_type x)
      requires random_access_range<base_t>;
    constexpr iterator& operator-=(difference_type x)
      requires random_access_range<base_t>;

    constexpr decltype(auto) operator[](difference_type n) const
      requires random_access_range<base_t>
    { return get<N>(*(current_ + n)); }

    friend constexpr bool operator==(const iterator& x, const iterator& y)
      requires equality_comparable<iterator_t<base_t>>;
    friend constexpr bool operator==(const iterator& x, const sentinel_t<base_t>& y);

    friend constexpr bool operator<(const iterator& x, const iterator& y)
      requires random_access_range<base_t>;
    friend constexpr bool operator>(const iterator& x, const iterator& y)
      requires random_access_range<base_t>;
    friend constexpr bool operator<=(const iterator& y, const iterator& y)
      requires random_access_range<base_t>;
    friend constexpr bool operator>=(const iterator& x, const iterator& y)
      requires random_access_range<base_t>;
    friend constexpr compare_three_way_result_t<iterator_t<base_t>>
      operator<=>(const iterator& x, const iterator& y)
        requires random_access_range<base_t> && three_way_comparable<iterator_t<base_t>>;

    friend constexpr iterator operator+(const iterator& x, difference_type y)
      requires random_access_range<base_t>;
    friend constexpr iterator operator+(difference_type x, const iterator& y)
      requires random_access_range<base_t>;
    friend constexpr iterator operator-(const iterator& x, difference_type y)
      requires random_access_range<base_t>;
    friend constexpr difference_type operator-(const iterator& x, const iterator& y)
      requires random_access_range<base_t>;

    friend constexpr difference_type
      operator-(const iterator<Const>& x, const sentinel_t<base_t>& y)
        requires sized_sentinel_for<sentinel_t<base_t>, iterator_t<base_t>>;
    friend constexpr difference_type
      operator-(const sentinel_t<base_t>& x, const iterator<Const>& y)
        requires sized_sentinel_for<sentinel_t<base_t>, iterator_t<base_t>>;
  };
}
constexpr explicit iterator(iterator_t<base_t> current);
Effects: Initializes current_­ with std​::​move(current).
constexpr iterator(iterator<!Const> i) requires Const && convertible_to<iterator_t<V>, iterator_t<base_t>>;
Effects: Initializes current_­ with std​::​move(i.current_­).
constexpr iterator_t<base_t> base() const & requires copyable<iterator_t<base_t>>;
Effects: Equivalent to: return current_­;
constexpr iterator_t<base_t> base() &&;
Effects: Equivalent to: return std​::​move(current_­);
constexpr iterator& operator++();
Effects: Equivalent to:
++current_;
return *this;
constexpr void operator++(int) requires (!forward_range<base_t>);
Effects: Equivalent to: ++current_­.
constexpr iterator operator++(int) requires forward_range<base_t>;
Effects: Equivalent to:
auto temp = *this;
++current_;
return temp;
constexpr iterator& operator--() requires bidirectional_range<base_t>;
Effects: Equivalent to:
--current_;
return *this;
constexpr iterator operator--(int) requires bidirectional_range<base_t>;
Effects: Equivalent to:
auto temp = *this;
--current_;
return temp;
constexpr iterator& operator+=(difference_type n); requires random_access_range<base_t>;
Effects: Equivalent to:
current_ += n;
return *this;
constexpr iterator& operator-=(difference_type n) requires random_access_range<base_t>;
Effects: Equivalent to:
current_ -= n;
return *this;
friend constexpr bool operator==(const iterator& x, const iterator& y) requires equality_comparable<base_t>;
Effects: Equivalent to: return x.current_­ == y.current_­;
friend constexpr bool operator==(const iterator& x, const sentinel_t<base_t>& y);
Effects: Equivalent to: return x.current_­ == y;
friend constexpr bool operator<(const iterator& x, const iterator& y) requires random_access_range<base_t>;
Effects: Equivalent to: return x.current_­ < y.current_­;
friend constexpr bool operator>(const iterator& x, const iterator& y) requires random_access_range<base_t>;
Effects: Equivalent to: return y < x;
friend constexpr bool operator<=(const iterator& x, const iterator& y) requires random_access_range<base_t>;
Effects: Equivalent to: return !(y < x);
friend constexpr bool operator>=(const iterator& x, const iterator& y) requires random_access_range<base_t>;
Effects: Equivalent to: return !(x < y);
friend constexpr compare_three_way_result_t<iterator_t<base_t>> operator<=>(const iterator& x, const iterator& y) requires random_access_range<base_t> && three_way_comparable<iterator_t<base_t>>;
Effects: Equivalent to: return x.current_­ <=> y.current_­;
friend constexpr iterator operator+(const iterator& x, difference_type y) requires random_access_range<base_t>;
Effects: Equivalent to: return iterator{x} += y;
friend constexpr iterator operator+(difference_type x, const iterator& y) requires random_access_range<base_t>;
Effects: Equivalent to: return y + x;
constexpr iterator operator-(const iterator& x, difference_type y) requires random_access_range<base_t>;
Effects: Equivalent to: return iterator{x} -= y;
constexpr difference_type operator-(const iterator& x, const iterator& y) requires random_access_range<base_t>;
Effects: Equivalent to: return x.current_­ - y.current_­;
friend constexpr difference_type operator-(const iterator<Const>& x, const sentinel_t<base_t>& y) requires sized_sentinel_for<sentinel_t<base_t>, iterator_t<base_t>>;
Effects: Equivalent to: return x.current_­ - y;
friend constexpr difference_type operator-(const sentinel_t<base_t>& x, const iterator<Const>& y) requires sized_sentinel_for<sentinel_t<base_t>, iterator_t<base_t>>;
Effects: Equivalent to: return -(y - x);