Public Types | Public Member Functions | Private Attributes | Friends | List of all members
beluga::IndexingIterator< Indexable, Index > Class Template Reference

A random access iterator for any indexable container. More...

#include <indexing_iterator.hpp>

Public Types

using difference_type = std::make_signed_t< decltype(std::declval< Index >() - std::declval< Index >())>
 Signed difference type of the iterator. More...
 
using iterator_category = std::random_access_iterator_tag
 Category of the iterator. More...
 
using pointer = decltype(std::addressof(std::declval< Indexable >()[std::declval< Index >()]))
 Value pointer type of the iterator. More...
 
using reference = decltype(std::declval< Indexable >()[std::declval< Index >()])
 Value reference type of the iterator. More...
 
using value_type = std::remove_cv_t< std::remove_reference_t< decltype(std::declval< Indexable >()[std::declval< Index >()])> >
 Value type of the iterator. More...
 

Public Member Functions

 IndexingIterator ()=default
 Default constructor. Iterator will point nowhere. More...
 
 IndexingIterator (Indexable &indexable, Index cursor=Index{})
 Constructs iterator given a reference to an indexable container and a cursor index on it. More...
 
 IndexingIterator (Indexable *indexable, Index cursor=Index{})
 Constructs iterator given a pointer to an indexable container and a cursor index on it. More...
 
bool operator!= (const IndexingIterator &other) const noexcept
 Checks if iterator position is not equal to that of another. More...
 
reference operator* () const noexcept
 Dereferences iterator at its current position. More...
 
IndexingIterator operator+ (difference_type offset) const noexcept
 Forwards iterator position a given offset, yielding a modified copy. More...
 
IndexingIteratoroperator++ () noexcept
 Pre-increments iterator position in the target container. More...
 
IndexingIterator operator++ (int) noexcept
 Post-increments iterator position in the target container. More...
 
IndexingIteratoroperator+= (difference_type offset) noexcept
 Forwards iterator position a given offset, in-place. More...
 
difference_type operator- (const IndexingIterator &other) const noexcept
 Computes the difference (i.e. the distance) between the positions of this iterator and another. More...
 
IndexingIterator operator- (difference_type offset) const noexcept
 Rewinds iterator position a given offset, yielding a modified copy. More...
 
IndexingIteratoroperator-- () noexcept
 Pre-decrements iterator position in the target container. More...
 
IndexingIterator operator-- (int) noexcept
 Post-decrements iterator position in the target container. More...
 
IndexingIteratoroperator-= (difference_type offset) noexcept
 Rewinds iterator position a given offset, in-place. More...
 
pointer operator-> () const noexcept
 Dereferences iterator at its current position and yields a pointer to it. More...
 
bool operator< (const IndexingIterator &other) const noexcept
 Checks if iterator position is strictly before that of another. More...
 
bool operator<= (const IndexingIterator &other) const noexcept
 Checks if iterator position is before or equal to that of another. More...
 
bool operator== (const IndexingIterator &other) const noexcept
 Checks if iterator position is equal to that of another. More...
 
bool operator> (const IndexingIterator &other) const noexcept
 Checks if iterator position is strictly after that of another. More...
 
bool operator>= (const IndexingIterator &other) const noexcept
 Checks if iterator position is after or equal to that of another. More...
 
reference operator[] (difference_type offset) const noexcept
 Dereferences iterator at a given offset from its current position. More...
 

Private Attributes

Index cursor_ {}
 
Indexable * indexable_ {nullptr}
 

Friends

IndexingIterator operator+ (difference_type offset, const IndexingIterator &iterator)
 Forwards iterator a given offset, yielding a modified copy. More...
 

Detailed Description

template<class Indexable, class Index = typename Indexable::size_type>
class beluga::IndexingIterator< Indexable, Index >

A random access iterator for any indexable container.

It can provide a pair of iterators for any container type that supports subscripting with an integral-like index.

Template Parameters
IndexableContainer type, potentially const. It must support subscripting.
IndexContainer index type. It must be default constructible and integral-like. Defaults to the indexable container size type, if defined.

Definition at line 38 of file indexing_iterator.hpp.

Member Typedef Documentation

◆ difference_type

template<class Indexable , class Index = typename Indexable::size_type>
using beluga::IndexingIterator< Indexable, Index >::difference_type = std::make_signed_t<decltype(std::declval<Index>() - std::declval<Index>())>

Signed difference type of the iterator.

Definition at line 48 of file indexing_iterator.hpp.

◆ iterator_category

template<class Indexable , class Index = typename Indexable::size_type>
using beluga::IndexingIterator< Indexable, Index >::iterator_category = std::random_access_iterator_tag

Category of the iterator.

Definition at line 50 of file indexing_iterator.hpp.

◆ pointer

template<class Indexable , class Index = typename Indexable::size_type>
using beluga::IndexingIterator< Indexable, Index >::pointer = decltype(std::addressof(std::declval<Indexable>()[std::declval<Index>()]))

Value pointer type of the iterator.

Definition at line 46 of file indexing_iterator.hpp.

◆ reference

template<class Indexable , class Index = typename Indexable::size_type>
using beluga::IndexingIterator< Indexable, Index >::reference = decltype(std::declval<Indexable>()[std::declval<Index>()])

Value reference type of the iterator.

Definition at line 44 of file indexing_iterator.hpp.

◆ value_type

template<class Indexable , class Index = typename Indexable::size_type>
using beluga::IndexingIterator< Indexable, Index >::value_type = std::remove_cv_t<std::remove_reference_t<decltype(std::declval<Indexable>()[std::declval<Index>()])> >

Value type of the iterator.

Definition at line 42 of file indexing_iterator.hpp.

Constructor & Destructor Documentation

◆ IndexingIterator() [1/3]

template<class Indexable , class Index = typename Indexable::size_type>
beluga::IndexingIterator< Indexable, Index >::IndexingIterator ( )
explicitdefault

Default constructor. Iterator will point nowhere.

◆ IndexingIterator() [2/3]

template<class Indexable , class Index = typename Indexable::size_type>
beluga::IndexingIterator< Indexable, Index >::IndexingIterator ( Indexable *  indexable,
Index  cursor = Index{} 
)
inlineexplicit

Constructs iterator given a pointer to an indexable container and a cursor index on it.

Definition at line 56 of file indexing_iterator.hpp.

◆ IndexingIterator() [3/3]

template<class Indexable , class Index = typename Indexable::size_type>
beluga::IndexingIterator< Indexable, Index >::IndexingIterator ( Indexable &  indexable,
Index  cursor = Index{} 
)
inlineexplicit

Constructs iterator given a reference to an indexable container and a cursor index on it.

Definition at line 60 of file indexing_iterator.hpp.

Member Function Documentation

◆ operator!=()

template<class Indexable , class Index = typename Indexable::size_type>
bool beluga::IndexingIterator< Indexable, Index >::operator!= ( const IndexingIterator< Indexable, Index > &  other) const
inlinenoexcept

Checks if iterator position is not equal to that of another.

Definition at line 193 of file indexing_iterator.hpp.

◆ operator*()

template<class Indexable , class Index = typename Indexable::size_type>
reference beluga::IndexingIterator< Indexable, Index >::operator* ( ) const
inlinenoexcept

Dereferences iterator at its current position.

Behavior is undefined if the iterator is past the limits of the target container.

Definition at line 148 of file indexing_iterator.hpp.

◆ operator+()

template<class Indexable , class Index = typename Indexable::size_type>
IndexingIterator beluga::IndexingIterator< Indexable, Index >::operator+ ( difference_type  offset) const
inlinenoexcept

Forwards iterator position a given offset, yielding a modified copy.

Definition at line 101 of file indexing_iterator.hpp.

◆ operator++() [1/2]

template<class Indexable , class Index = typename Indexable::size_type>
IndexingIterator& beluga::IndexingIterator< Indexable, Index >::operator++ ( )
inlinenoexcept

Pre-increments iterator position in the target container.

Definition at line 71 of file indexing_iterator.hpp.

◆ operator++() [2/2]

template<class Indexable , class Index = typename Indexable::size_type>
IndexingIterator beluga::IndexingIterator< Indexable, Index >::operator++ ( int  )
inlinenoexcept

Post-increments iterator position in the target container.

Definition at line 64 of file indexing_iterator.hpp.

◆ operator+=()

template<class Indexable , class Index = typename Indexable::size_type>
IndexingIterator& beluga::IndexingIterator< Indexable, Index >::operator+= ( difference_type  offset)
inlinenoexcept

Forwards iterator position a given offset, in-place.

Definition at line 90 of file indexing_iterator.hpp.

◆ operator-() [1/2]

template<class Indexable , class Index = typename Indexable::size_type>
difference_type beluga::IndexingIterator< Indexable, Index >::operator- ( const IndexingIterator< Indexable, Index > &  other) const
inlinenoexcept

Computes the difference (i.e. the distance) between the positions of this iterator and another.

Definition at line 131 of file indexing_iterator.hpp.

◆ operator-() [2/2]

template<class Indexable , class Index = typename Indexable::size_type>
IndexingIterator beluga::IndexingIterator< Indexable, Index >::operator- ( difference_type  offset) const
inlinenoexcept

Rewinds iterator position a given offset, yielding a modified copy.

Definition at line 124 of file indexing_iterator.hpp.

◆ operator--() [1/2]

template<class Indexable , class Index = typename Indexable::size_type>
IndexingIterator& beluga::IndexingIterator< Indexable, Index >::operator-- ( )
inlinenoexcept

Pre-decrements iterator position in the target container.

Definition at line 84 of file indexing_iterator.hpp.

◆ operator--() [2/2]

template<class Indexable , class Index = typename Indexable::size_type>
IndexingIterator beluga::IndexingIterator< Indexable, Index >::operator-- ( int  )
inlinenoexcept

Post-decrements iterator position in the target container.

Definition at line 77 of file indexing_iterator.hpp.

◆ operator-=()

template<class Indexable , class Index = typename Indexable::size_type>
IndexingIterator& beluga::IndexingIterator< Indexable, Index >::operator-= ( difference_type  offset)
inlinenoexcept

Rewinds iterator position a given offset, in-place.

Definition at line 113 of file indexing_iterator.hpp.

◆ operator->()

template<class Indexable , class Index = typename Indexable::size_type>
pointer beluga::IndexingIterator< Indexable, Index >::operator-> ( ) const
inlinenoexcept

Dereferences iterator at its current position and yields a pointer to it.

Behavior is undefined if the iterator is past the limits of the target container.

Definition at line 154 of file indexing_iterator.hpp.

◆ operator<()

template<class Indexable , class Index = typename Indexable::size_type>
bool beluga::IndexingIterator< Indexable, Index >::operator< ( const IndexingIterator< Indexable, Index > &  other) const
inlinenoexcept

Checks if iterator position is strictly before that of another.

Can only be true for iterators that have the same target container.

Definition at line 160 of file indexing_iterator.hpp.

◆ operator<=()

template<class Indexable , class Index = typename Indexable::size_type>
bool beluga::IndexingIterator< Indexable, Index >::operator<= ( const IndexingIterator< Indexable, Index > &  other) const
inlinenoexcept

Checks if iterator position is before or equal to that of another.

Can only be true for iterators that have the same target container.

Definition at line 168 of file indexing_iterator.hpp.

◆ operator==()

template<class Indexable , class Index = typename Indexable::size_type>
bool beluga::IndexingIterator< Indexable, Index >::operator== ( const IndexingIterator< Indexable, Index > &  other) const
inlinenoexcept

Checks if iterator position is equal to that of another.

Can only be true for iterators that have the same target container.

Definition at line 188 of file indexing_iterator.hpp.

◆ operator>()

template<class Indexable , class Index = typename Indexable::size_type>
bool beluga::IndexingIterator< Indexable, Index >::operator> ( const IndexingIterator< Indexable, Index > &  other) const
inlinenoexcept

Checks if iterator position is strictly after that of another.

Can only be true for iterators that have the same target container.

Definition at line 176 of file indexing_iterator.hpp.

◆ operator>=()

template<class Indexable , class Index = typename Indexable::size_type>
bool beluga::IndexingIterator< Indexable, Index >::operator>= ( const IndexingIterator< Indexable, Index > &  other) const
inlinenoexcept

Checks if iterator position is after or equal to that of another.

Can only be true for iterators that have the same target container.

Definition at line 182 of file indexing_iterator.hpp.

◆ operator[]()

template<class Indexable , class Index = typename Indexable::size_type>
reference beluga::IndexingIterator< Indexable, Index >::operator[] ( difference_type  offset) const
inlinenoexcept

Dereferences iterator at a given offset from its current position.

Behavior is undefined for offsets that take the iterator past the limits of the target container.

Definition at line 142 of file indexing_iterator.hpp.

Friends And Related Function Documentation

◆ operator+

template<class Indexable , class Index = typename Indexable::size_type>
IndexingIterator operator+ ( difference_type  offset,
const IndexingIterator< Indexable, Index > &  iterator 
)
friend

Forwards iterator a given offset, yielding a modified copy.

Definition at line 108 of file indexing_iterator.hpp.

Member Data Documentation

◆ cursor_

template<class Indexable , class Index = typename Indexable::size_type>
Index beluga::IndexingIterator< Indexable, Index >::cursor_ {}
private

Definition at line 197 of file indexing_iterator.hpp.

◆ indexable_

template<class Indexable , class Index = typename Indexable::size_type>
Indexable* beluga::IndexingIterator< Indexable, Index >::indexable_ {nullptr}
private

Definition at line 196 of file indexing_iterator.hpp.


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


beluga
Author(s):
autogenerated on Tue Jul 16 2024 02:59:54