Detail

Provides the seqan3::detail::random_access_iterator class.

Author
Marie Hoffmann <marie.hoffmann AT fu-berlin.de>

namespace detail

The internal SeqAn3 namespace.

The contents of this namespace are not visible to consumers of the library and the documentation is only generated for developers.

See
https://github.com/seqan/seqan3/wiki/Documentation

template <typename container_type>
class random_access_iterator
#include <range/detail/random_access_iterator.hpp>

Implementation of a random access iterator on an input container pointer.

No iterator operation will modify the container. Arithmetic and boolean operations are applied to the iterator positions, not the corresponding values of their containers.

Template Parameters
  • container_type: The data structure on which the iterator operates, e.g. std::vector<int>.

The iterator makes certain assumptions on the container_type, but does not formally require it to satisfy the seqan3::random_access_range_concept, because the iterator itself is a requirement for this.

Constructors/Destructors

constexpr random_access_iterator()
constexpr random_access_iterator(container_type &host)

Construct by host, default position pointer with 0.

constexpr random_access_iterator(container_type &host, position_type const pos)

Construct by host and explicit position.

constexpr random_access_iterator(random_access_iterator const&)

Copy constructor.

constexpr random_access_iterator &operator=(random_access_iterator const&)

Copy construction via assignment.

constexpr random_access_iterator(random_access_iterator&&)

Move constructor.

constexpr random_access_iterator &operator=(random_access_iterator&&)

Move assignment.

~random_access_iterator()

Use default deconstructor.

template <typename t>
constexpr random_access_iterator(random_access_iterator<t> const &rhs)

Constructor for const version from non-const version.

Comparison operators

Compares only the absolute position of two iterators.

constexpr bool operator==(random_access_iterator const &rhs) const
constexpr bool operator!=(random_access_iterator const &rhs) const
constexpr bool operator<(random_access_iterator const &rhs) const
constexpr bool operator>(random_access_iterator const &rhs) const
constexpr bool operator<=(random_access_iterator const &rhs) const
constexpr bool operator>=(random_access_iterator const &rhs) const

Arithmetic operators

constexpr random_access_iterator &operator++()

Pre-increment, return updated iterator.

constexpr random_access_iterator operator++(int)

Post-increment, return previous iterator state.

constexpr random_access_iterator &operator--()

Pre-decrement, return updated iterator.

constexpr random_access_iterator operator--(int)

Post-decrement, return previous iterator state.

constexpr random_access_iterator &operator+=(difference_type const skip)

Forward this iterator.

constexpr random_access_iterator operator+(difference_type const skip) const

Forward copy of this iterator.

constexpr random_access_iterator &operator-=(difference_type const skip)

Decrement iterator by skip.

constexpr random_access_iterator operator-(difference_type const skip) const

Return decremented copy of this iterator.

constexpr difference_type operator-(random_access_iterator const lhs) const

Return offset between this and remote iterator’s position.

random_access_iterator operator+(difference_type const skip, random_access_iterator const &it)

Non-member operator+ delegates to non-friend operator+.

friend constexpr random_access_iterator operator-(difference_type const skip, random_access_iterator const &it)

Non-member operator- delegates to non-friend operator-.

Reference/Dereference operators

constexpr reference operator*()

Dereference operator returns element currently pointed at.

constexpr pointer operator->() const

Return pointer to this iterator.

constexpr reference operator[](position_type const n) const

Return underlying container value currently pointed at.

Public Types

template<>
using difference_type = ranges::v3::difference_type_t<container_type>

Type for distances between iterators.

template<>
using value_type = ranges::v3::value_type_t<container_type>

Value type of container elements.

template<>
using reference = std::conditional_t<std::is_const_v<container_type>, typename container_type::const_reference, typename container_type::reference>

Use reference type defined by container.

template<>
using const_reference = typename container_type::const_reference

Use const reference type provided by container.

template<>
using pointer = value_type *

Pointer type is pointer of container element type.

template<>
using iterator_category = std::random_access_iterator_tag

Tag this class as a random access iterator.

Private Types

template<>
using position_type = ranges::v3::size_type_t<container_type>

Use container’s size_type as a position.

Private Members

std::add_pointer_t<container_type> host = {nullptr}

Iterator stores pointer to underlying container structure.

position_type pos = {static_cast<position_type>(0)}

Store position index for container.

requires std::is_same_v<std::remove_const_t<container_type>, t>&& friend class seqan3::detail::random_access_iterator::random_access_iterator

This friend declaration is required to allow non-const to const-construction.