SeqAn3 3.4.0-rc.1
The Modern C++ library for sequence analysis.
Loading...
Searching...
No Matches
seqan3::detail::random_access_iterator_base< range_type, derived_t_template, args_t > Class Template Reference

A CRTP base template for creating random access iterators. More...

#include <seqan3/core/range/detail/random_access_iterator.hpp>

+ Inheritance diagram for seqan3::detail::random_access_iterator_base< range_type, derived_t_template, args_t >:

Public Types

using const_reference = typename range_type::const_reference
 Use const reference type provided by container.
 
using difference_type = typename range_type::difference_type
 Type for distances between iterators.
 
using iterator_category = std::random_access_iterator_tag
 Tag this class as a random access iterator.
 
using pointer = value_type *
 Pointer type is pointer of container element type.
 
using reference = std::conditional_t< std::is_const_v< range_type >, typename range_type::const_reference, typename range_type::reference >
 Use reference type defined by container.
 
using value_type = typename range_type::value_type
 Value type of container elements.
 

Public Member Functions

Constructors/Destructors
constexpr random_access_iterator_base ()=default
 Default constructor.
 
constexpr random_access_iterator_base (random_access_iterator_base const &)=default
 Copy constructor.
 
constexpr random_access_iterator_baseoperator= (random_access_iterator_base const &)=default
 Copy construction via assignment.
 
constexpr random_access_iterator_base (random_access_iterator_base &&)=default
 Move constructor.
 
constexpr random_access_iterator_baseoperator= (random_access_iterator_base &&)=default
 Move assignment.
 
 ~random_access_iterator_base ()=default
 Use default deconstructor.
 
constexpr random_access_iterator_base (range_type &host) noexcept
 Construct by host, default position pointer with 0.
 
constexpr random_access_iterator_base (range_type &host, position_type const pos) noexcept
 Construct by host and explicit position.
 
template<typename range_type2 >
requires std::is_const_v<range_type> && (!std::is_const_v<range_type2>) && std::is_same_v<std::remove_const_t<range_type>, range_type2>
constexpr random_access_iterator_base (random_access_iterator_base< range_type2, derived_t_template > const &rhs) noexcept
 Constructor for const version from non-const version.
 
Comparison operators

Compare iterators by position. seqan3::detail::random_access_iterator_base operators are used unless specialised in derived type.

template<typename range_type2 >
requires std::is_same_v<std::remove_const_t<range_type>, std::remove_const_t<range_type2>>
constexpr bool operator== (random_access_iterator_base< range_type2, derived_t_template > const &rhs) const noexcept
 Checks whether *this is equal to rhs.
 
template<typename range_type2 >
requires std::is_same_v<std::remove_const_t<range_type>, std::remove_const_t<range_type2>>
constexpr bool operator!= (random_access_iterator_base< range_type2, derived_t_template > const &rhs) const noexcept
 Checks whether *this is not equal to rhs.
 
template<typename range_type2 >
requires std::is_same_v<std::remove_const_t<range_type>, std::remove_const_t<range_type2>>
constexpr bool operator< (random_access_iterator_base< range_type2, derived_t_template > const &rhs) const noexcept
 Checks whether *this is less than rhs.
 
template<typename range_type2 >
requires std::is_same_v<std::remove_const_t<range_type>, std::remove_const_t<range_type2>>
constexpr bool operator> (random_access_iterator_base< range_type2, derived_t_template > const &rhs) const noexcept
 Checks whether *this is greater than rhs.
 
template<typename range_type2 >
requires std::is_same_v<std::remove_const_t<range_type>, std::remove_const_t<range_type2>>
constexpr bool operator<= (random_access_iterator_base< range_type2, derived_t_template > const &rhs) const noexcept
 Checks whether *this is less than or equal to rhs.
 
template<typename range_type2 >
requires std::is_same_v<std::remove_const_t<range_type>, std::remove_const_t<range_type2>>
constexpr bool operator>= (random_access_iterator_base< range_type2, derived_t_template > const &rhs) const noexcept
 Checks whether *this is greater than or equal to rhs.
 
Reference/Dereference operators

seqan3::detail::random_access_iterator_base operators are used unless specialised in derived type.

constexpr reference operator* () const noexcept(noexcept((*host)[pos]))
 Dereference operator returns element currently pointed at.
 
constexpr pointer operator-> () const noexcept(noexcept((&host)[pos]))
 Return pointer to this iterator.
 
constexpr reference operator[] (position_type const n) const noexcept(noexcept((*host)[pos+n]))
 Return underlying container value currently pointed at.
 

Protected Types

using derived_t = derived_t_template< range_type >
 Because this is CRTP, we know the full derived type:
 
using position_type = std::make_unsigned_t< typename range_type::difference_type >
 Use container's size_type as a position.
 

Protected Attributes

std::add_pointer_t< range_type > host {nullptr}
 Iterator stores pointer to underlying container structure.
 
position_type pos {static_cast<position_type>(0)}
 Store position index for container.
 

Private Member Functions

constexpr derived_tthis_derived ()
 Cast this to derived type.
 
constexpr derived_t const * this_derived () const
 Cast this to derived type.
 

Friends

template<typename range_type2 , template< typename... > typename derived_t_template2, typename... args2_t>
class random_access_iterator_base
 This friend declaration is required to allow non-const to const-construction.
 

Arithmetic operators

seqan3::detail::random_access_iterator_base operators are used unless specialised in derived type.

constexpr friend derived_t operator+ (difference_type const skip, derived_t const &it) noexcept
 Non-member operator+ delegates to non-friend operator+.
 
constexpr friend derived_t operator- (difference_type const skip, derived_t const &it) noexcept
 Non-member operator- delegates to non-friend operator-.
 
constexpr friend difference_type operator- (derived_t const &lhs, derived_t const &rhs) noexcept
 Return offset between this and remote iterator's position.
 
constexpr derived_toperator++ () noexcept
 Pre-increment, return updated iterator.
 
constexpr derived_t operator++ (int) noexcept
 Post-increment, return previous iterator state.
 
constexpr derived_toperator-- () noexcept
 Pre-decrement, return updated iterator.
 
constexpr derived_t operator-- (int) noexcept
 Post-decrement, return previous iterator state.
 
constexpr derived_toperator+= (difference_type const skip) noexcept
 Forward this iterator.
 
constexpr derived_t operator+ (difference_type const skip) const noexcept
 Forward copy of this iterator.
 
constexpr derived_toperator-= (difference_type const skip) noexcept
 Decrement iterator by skip.
 
constexpr derived_t operator- (difference_type const skip) const noexcept
 Return decremented copy of this iterator.
 

Detailed Description

template<typename range_type, template< typename... > typename derived_t_template, typename... args_t>
class seqan3::detail::random_access_iterator_base< range_type, derived_t_template, args_t >

A CRTP base template for creating random access iterators.

Template Parameters
range_typeThe data structure on which the iterator operates, e.g. std::vector<int>.
derived_t_templateThe derived type template, see below.

The iterator makes certain assumptions on the range_type, but does not formally require it to satisfy the std::ranges::random_access_range, because the iterator itself may be a requirement for this.

Actual functionality of this iterator is realised via the host range's [] operator and member type definitions, i.e. you need to implement these in the range before you can make use of this iterator.

Since the CRTP parameter is in fact a template template, CRTP instantiation looks a little different, e.g.:

// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: CC0-1.0
template <typename range_type>
class my_random_access_iterator :
public seqan3::detail::random_access_iterator_base<range_type, seqan3::detail::random_access_iterator>
{
//...
};
int main()
{}
A CRTP base template for creating random access iterators.
Definition random_access_iterator.hpp:39
Provides the seqan3::detail::random_access_iterator class.

Member Function Documentation

◆ this_derived()

template<typename range_type , template< typename... > typename derived_t_template, typename... args_t>
constexpr derived_t const * seqan3::detail::random_access_iterator_base< range_type, derived_t_template, args_t >::this_derived ( ) const
inlineconstexprprivate

Cast this to derived type.


The documentation for this class was generated from the following file:
Hide me