Namespaces
Variants
Views
Actions

std::ranges::split_view<V,Pattern>::iterator

From cppreference.com
< cpp‎ | ranges‎ | split view
 
 
Ranges library
Range access
Range conversions
(C++23)
Range primitives
Dangling iterator handling
Range concepts
Views

Factories
Adaptors
Range adaptor objects
Range adaptor closure objects
Helper items
 
 
class /*iterator*/; // exposition only
(since C++20)

The return type of split_view::begin. The name iterator is for exposition purposes only.

This is a forward_iterator, so it is expected that V models at least forward_range.

Contents

[edit] Member types

Member type Definition
iterator_concept std::forward_iterator_tag
iterator_category std::input_iterator_tag
value_type ranges::subrange<ranges::iterator_t<V>>
difference_type ranges::range_difference_t<V>

[edit] Data members

Typical implementations of iterator hold four non-static data members:

  • a pointer of type ranges::split_view<V, Pattern>* to the parent split_view object (shown here as parent_ for exposition only),
  • an iterator of type ranges::iterator_t<V> (shown here as cur_ for exposition only) into the underlying view; cur_ points to the begin of a current subrange,
  • a subrange of type ranges::subrange<ranges::iterator_t<V>> (shown here as next_ for exposition only) to the position of the pattern next to the current subrange, and
  • a boolean flag (shown here as trailing_empty_ for exposition only) that indicates whether an empty trailing subrange (if any) was reached.

[edit] Member functions

(constructor)
(C++20)
constructs an iterator
(public member function)
base
(C++20)
returns the underlying iterator
(public member function)
operator*
(C++20)
returns the current subrange
(public member function)
operator++operator++(int)
(C++20)
advances the iterator
(public member function)

std::ranges::split_view::iterator::iterator

/*iterator*/() = default;
(1) (since C++20)
constexpr /*iterator*/( split_view& parent, ranges::iterator_t<V> current,
                        ranges::subrange<ranges::iterator_t<V>> next );
(2) (since C++20)
1) Value-initializes non-static data members with their default member initializers, that is
2) Initializes non-static data members:

std::ranges::split_view::iterator::base

constexpr const ranges::iterator_t<V> base() const;
(since C++20)

Equivalent to return cur_;.

std::ranges::split_view::iterator::operator*

constexpr ranges::range_reference_t<V> operator*() const;
(since C++20)

Equivalent to return {cur_, next_.begin()};.

std::ranges::split_view::iterator::operator++

constexpr /*iterator*/& operator++();
(1) (since C++20)
constexpr void operator++( int );
(2) (since C++20)
1) Equivalent to
cur_ = next_.begin();

if (cur_ != ranges::end(parent_->base_)) {
  cur_ = next_.end();
  if (cur_ == ranges::end(parent_->base_)) {
    trailing_empty_ = true;
    next_ = {cur_, cur_};
  } else {
    next_ = parent_->find_next(cur_);
  }
} else {
  trailing_empty_ = false;
}

return *this;
.
2) Equivalent to auto tmp = *this; ++*this; return tmp;.

[edit] Non-member functions

operator==
(C++20)
compares the underlying iterators
(function)

operator==(std::ranges::split_view::iterator, std::ranges::split_view::iterator)

friend constexpr bool operator==( const /*iterator*/& x, const /*iterator*/& y );
(since C++20)

Equivalent to return x.cur_ == y.cur_ && x.trailing_empty_ == y.trailing_empty_;.

The != operator is synthesized from operator==.

This function is not visible to ordinary unqualified or qualified lookup, and can only be found by argument-dependent lookup when std::ranges::split_view::iterator is an associated class of the arguments.