Template Class IndexingIterator
Defined in File indexing_iterator.hpp
Class Documentation
-
template<class Indexable, class Index = typename Indexable::size_type>
class IndexingIterator 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:
Indexable – Container type, potentially const. It must support subscripting.
Index – Container index type. It must be default constructible and integral-like. Defaults to the indexable container size type, if defined.
Public Types
-
using value_type = std::remove_cv_t<std::remove_reference_t<decltype(std::declval<Indexable>()[std::declval<Index>()])>>
Value type of the iterator.
-
using reference = decltype(std::declval<Indexable>()[std::declval<Index>()])
Value reference type of the iterator.
-
using pointer = decltype(std::addressof(std::declval<Indexable>()[std::declval<Index>()]))
Value pointer type of the iterator.
-
using difference_type = std::make_signed_t<decltype(std::declval<Index>() - std::declval<Index>())>
Signed difference type of the iterator.
-
using iterator_category = std::random_access_iterator_tag
Category of the iterator.
Public Functions
-
explicit IndexingIterator() = default
Default constructor. Iterator will point nowhere.
-
inline explicit IndexingIterator(Indexable *indexable, Index cursor = Index{})
Constructs iterator given a pointer to an
indexable
container and acursor
index on it.
-
inline explicit IndexingIterator(Indexable &indexable, Index cursor = Index{})
Constructs iterator given a reference to an
indexable
container and acursor
index on it.
-
inline IndexingIterator operator++(int) noexcept
Post-increments iterator position in the target container.
-
inline IndexingIterator &operator++() noexcept
Pre-increments iterator position in the target container.
-
inline IndexingIterator operator--(int) noexcept
Post-decrements iterator position in the target container.
-
inline IndexingIterator &operator--() noexcept
Pre-decrements iterator position in the target container.
-
inline IndexingIterator &operator+=(difference_type offset) noexcept
Forwards iterator position a given
offset
, in-place.
-
inline IndexingIterator operator+(difference_type offset) const noexcept
Forwards iterator position a given
offset
, yielding a modified copy.
-
inline IndexingIterator &operator-=(difference_type offset) noexcept
Rewinds iterator position a given
offset
, in-place.
-
inline IndexingIterator operator-(difference_type offset) const noexcept
Rewinds iterator position a given
offset
, yielding a modified copy.
-
inline difference_type operator-(const IndexingIterator &other) const noexcept
Computes the difference (i.e. the distance) between the positions of this iterator and another.
-
inline reference operator[](difference_type offset) const noexcept
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.
-
inline reference operator*() const noexcept
Dereferences iterator at its current position.
Behavior is undefined if the iterator is past the limits of the target container.
-
inline pointer operator->() const noexcept
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.
-
inline bool operator<(const IndexingIterator &other) const noexcept
Checks if iterator position is strictly before that of another.
Can only be true for iterators that have the same target container.
-
inline bool operator<=(const IndexingIterator &other) const noexcept
Checks if iterator position is before or equal to that of another.
Can only be true for iterators that have the same target container.
-
inline bool operator>(const IndexingIterator &other) const noexcept
Checks if iterator position is strictly after that of another.
Can only be true for iterators that have the same target container.
-
inline bool operator>=(const IndexingIterator &other) const noexcept
Checks if iterator position is after or equal to that of another.
Can only be true for iterators that have the same target container.
-
inline bool operator==(const IndexingIterator &other) const noexcept
Checks if iterator position is equal to that of another.
Can only be true for iterators that have the same target container.
-
inline bool operator!=(const IndexingIterator &other) const noexcept
Checks if iterator position is not equal to that of another.
Friends
-
inline friend IndexingIterator operator+(difference_type offset, const IndexingIterator &iterator)
Forwards
iterator
a givenoffset
, yielding a modified copy.