RPNX::DataStructures
Header-only C++ data structures and supporting utilities.
Loading...
Searching...
No Matches
rpnx::segmented_dynar< T, Alloc >::iterator_impl< Const > Class Template Reference

Random-access iterator over the segmented logical sequence. More...

#include <segmented_dynar.hpp>

Public Types

using iterator_category = std::random_access_iterator_tag
 Iterator category for legacy algorithms.
 
using difference_type = std::ptrdiff_t
 Signed iterator-distance type.
 
using value_type = T
 Iterated element type.
 
using pointer = std::conditional_t< Const, T const*, T* >
 Mutable or immutable element pointer type.
 
using reference = std::conditional_t< Const, T const&, T& >
 Mutable or immutable element reference type.
 
using container_ptr = std::conditional_t< Const, const segmented_dynar*, segmented_dynar* >
 Pointer to the mutable or immutable owning container.
 

Public Member Functions

 iterator_impl ()=default
 Constructs a singular iterator.
 
 iterator_impl (container_ptr container, std::size_t index)
 Constructs an iterator at a logical index.
 
template<bool Const2, typename = std::enable_if_t< Const && !Const2 >>
 iterator_impl (const iterator_impl< Const2 > &other)
 Converts a mutable iterator to an immutable iterator.
 
reference operator* () const
 Dereferences the current position.
 
pointer operator-> () const
 Accesses the current element.
 
iterator_imploperator++ ()
 Advances one element.
 
iterator_impl operator++ (int)
 Advances one element.
 
iterator_imploperator-- ()
 Retreats one element.
 
iterator_impl operator-- (int)
 Retreats one element.
 
iterator_imploperator+= (difference_type n)
 Moves by a signed offset.
 
iterator_imploperator-= (difference_type n)
 Moves backward by a signed offset.
 
iterator_impl operator+ (difference_type n) const
 Returns an iterator moved by an offset.
 
iterator_impl operator- (difference_type n) const
 Returns an iterator moved backward by an offset.
 
difference_type operator- (const iterator_impl< true > &other) const
 Computes distance from an immutable iterator.
 
difference_type operator- (const iterator_impl< false > &other) const
 Computes distance from a mutable iterator.
 
reference operator[] (difference_type n) const
 Dereferences an offset position.
 
bool operator== (const iterator_impl< true > &other) const
 Compares with an immutable iterator for equality.
 
bool operator== (const iterator_impl< false > &other) const
 Compares with a mutable iterator for equality.
 
bool operator!= (const iterator_impl< true > &other) const
 Compares with an immutable iterator for inequality.
 
bool operator!= (const iterator_impl< false > &other) const
 Compares with a mutable iterator for inequality.
 
bool operator< (const iterator_impl< true > &other) const
 Tests whether this index precedes an immutable iterator.
 
bool operator< (const iterator_impl< false > &other) const
 Tests whether this index precedes a mutable iterator.
 
bool operator> (const iterator_impl< true > &other) const
 Tests whether this index follows an immutable iterator.
 
bool operator> (const iterator_impl< false > &other) const
 Tests whether this index follows a mutable iterator.
 
bool operator<= (const iterator_impl< true > &other) const
 Tests whether this index does not follow an immutable iterator.
 
bool operator<= (const iterator_impl< false > &other) const
 Tests whether this index does not follow a mutable iterator.
 
bool operator>= (const iterator_impl< true > &other) const
 Tests whether this index does not precede an immutable iterator.
 
bool operator>= (const iterator_impl< false > &other) const
 Tests whether this index does not precede a mutable iterator.
 

Friends

class segmented_dynar
 

Detailed Description

template<typename T, typename Alloc = std::allocator< T >>
template<bool Const>
class rpnx::segmented_dynar< T, Alloc >::iterator_impl< Const >

Random-access iterator over the segmented logical sequence.

Template Parameters
ConstWhether dereference yields an immutable reference.

The iterator is non-owning. It caches the current segment while using a global logical index for comparison and cross-segment movement.

Constructor & Destructor Documentation

◆ iterator_impl() [1/2]

template<typename T, typename Alloc = std::allocator< T >>
template<bool Const>
rpnx::segmented_dynar< T, Alloc >::iterator_impl< Const >::iterator_impl ( container_ptr container,
std::size_t index )
inline

Constructs an iterator at a logical index.

Parameters
containerContainer to reference.
indexIndex in [0, container->size()].

◆ iterator_impl() [2/2]

template<typename T, typename Alloc = std::allocator< T >>
template<bool Const>
template<bool Const2, typename = std::enable_if_t< Const && !Const2 >>
rpnx::segmented_dynar< T, Alloc >::iterator_impl< Const >::iterator_impl ( const iterator_impl< Const2 > & other)
inline

Converts a mutable iterator to an immutable iterator.

Template Parameters
Const2Source constness, required to be false.
Parameters
otherMutable iterator to copy.

Member Function Documentation

◆ operator!=() [1/2]

template<typename T, typename Alloc = std::allocator< T >>
template<bool Const>
bool rpnx::segmented_dynar< T, Alloc >::iterator_impl< Const >::operator!= ( const iterator_impl< false > & other) const
inline

Compares with a mutable iterator for inequality.

Parameters
otherIterator in the same container.
Returns
Index comparison result.

◆ operator!=() [2/2]

template<typename T, typename Alloc = std::allocator< T >>
template<bool Const>
bool rpnx::segmented_dynar< T, Alloc >::iterator_impl< Const >::operator!= ( const iterator_impl< true > & other) const
inline

Compares with an immutable iterator for inequality.

Parameters
otherIterator in the same container.
Returns
Index comparison result.

◆ operator*()

template<typename T, typename Alloc = std::allocator< T >>
template<bool Const>
reference rpnx::segmented_dynar< T, Alloc >::iterator_impl< Const >::operator* ( ) const
inline

Dereferences the current position.

Returns
Element reference.
Precondition
The iterator is dereferenceable.

◆ operator+()

template<typename T, typename Alloc = std::allocator< T >>
template<bool Const>
iterator_impl rpnx::segmented_dynar< T, Alloc >::iterator_impl< Const >::operator+ ( difference_type n) const
inline

Returns an iterator moved by an offset.

Parameters
nOffset in elements.
Returns
Shifted iterator.

◆ operator++() [1/2]

template<typename T, typename Alloc = std::allocator< T >>
template<bool Const>
iterator_impl & rpnx::segmented_dynar< T, Alloc >::iterator_impl< Const >::operator++ ( )
inline

Advances one element.

Returns
Reference to this iterator.
Precondition
The iterator is not at end().

◆ operator++() [2/2]

template<typename T, typename Alloc = std::allocator< T >>
template<bool Const>
iterator_impl rpnx::segmented_dynar< T, Alloc >::iterator_impl< Const >::operator++ ( int )
inline

Advances one element.

Returns
Copy of the iterator before increment.
Precondition
The iterator is not at end().

◆ operator+=()

template<typename T, typename Alloc = std::allocator< T >>
template<bool Const>
iterator_impl & rpnx::segmented_dynar< T, Alloc >::iterator_impl< Const >::operator+= ( difference_type n)
inline

Moves by a signed offset.

Parameters
nOffset in elements.
Returns
Reference to this iterator.
Precondition
The resulting position belongs to the same container range.

◆ operator-() [1/3]

template<typename T, typename Alloc = std::allocator< T >>
template<bool Const>
difference_type rpnx::segmented_dynar< T, Alloc >::iterator_impl< Const >::operator- ( const iterator_impl< false > & other) const
inline

Computes distance from a mutable iterator.

Parameters
otherIterator in the same container.
Returns
Signed index difference.

◆ operator-() [2/3]

template<typename T, typename Alloc = std::allocator< T >>
template<bool Const>
difference_type rpnx::segmented_dynar< T, Alloc >::iterator_impl< Const >::operator- ( const iterator_impl< true > & other) const
inline

Computes distance from an immutable iterator.

Parameters
otherIterator in the same container.
Returns
Signed index difference.

◆ operator-() [3/3]

template<typename T, typename Alloc = std::allocator< T >>
template<bool Const>
iterator_impl rpnx::segmented_dynar< T, Alloc >::iterator_impl< Const >::operator- ( difference_type n) const
inline

Returns an iterator moved backward by an offset.

Parameters
nOffset in elements.
Returns
Shifted iterator.

◆ operator--() [1/2]

template<typename T, typename Alloc = std::allocator< T >>
template<bool Const>
iterator_impl & rpnx::segmented_dynar< T, Alloc >::iterator_impl< Const >::operator-- ( )
inline

Retreats one element.

Returns
Reference to this iterator.
Precondition
The iterator is not at begin().

◆ operator--() [2/2]

template<typename T, typename Alloc = std::allocator< T >>
template<bool Const>
iterator_impl rpnx::segmented_dynar< T, Alloc >::iterator_impl< Const >::operator-- ( int )
inline

Retreats one element.

Returns
Copy of the iterator before decrement.
Precondition
The iterator is not at begin().

◆ operator-=()

template<typename T, typename Alloc = std::allocator< T >>
template<bool Const>
iterator_impl & rpnx::segmented_dynar< T, Alloc >::iterator_impl< Const >::operator-= ( difference_type n)
inline

Moves backward by a signed offset.

Parameters
nOffset in elements.
Returns
Reference to this iterator.
Precondition
The resulting position belongs to the same container range.

◆ operator->()

template<typename T, typename Alloc = std::allocator< T >>
template<bool Const>
pointer rpnx::segmented_dynar< T, Alloc >::iterator_impl< Const >::operator-> ( ) const
inline

Accesses the current element.

Returns
Element pointer.
Precondition
The iterator is dereferenceable.

◆ operator<() [1/2]

template<typename T, typename Alloc = std::allocator< T >>
template<bool Const>
bool rpnx::segmented_dynar< T, Alloc >::iterator_impl< Const >::operator< ( const iterator_impl< false > & other) const
inline

Tests whether this index precedes a mutable iterator.

Parameters
otherIterator in the same container.
Returns
Index comparison result.

◆ operator<() [2/2]

template<typename T, typename Alloc = std::allocator< T >>
template<bool Const>
bool rpnx::segmented_dynar< T, Alloc >::iterator_impl< Const >::operator< ( const iterator_impl< true > & other) const
inline

Tests whether this index precedes an immutable iterator.

Parameters
otherIterator in the same container.
Returns
Index comparison result.

◆ operator<=() [1/2]

template<typename T, typename Alloc = std::allocator< T >>
template<bool Const>
bool rpnx::segmented_dynar< T, Alloc >::iterator_impl< Const >::operator<= ( const iterator_impl< false > & other) const
inline

Tests whether this index does not follow a mutable iterator.

Parameters
otherIterator in the same container.
Returns
Index comparison result.

◆ operator<=() [2/2]

template<typename T, typename Alloc = std::allocator< T >>
template<bool Const>
bool rpnx::segmented_dynar< T, Alloc >::iterator_impl< Const >::operator<= ( const iterator_impl< true > & other) const
inline

Tests whether this index does not follow an immutable iterator.

Parameters
otherIterator in the same container.
Returns
Index comparison result.

◆ operator==() [1/2]

template<typename T, typename Alloc = std::allocator< T >>
template<bool Const>
bool rpnx::segmented_dynar< T, Alloc >::iterator_impl< Const >::operator== ( const iterator_impl< false > & other) const
inline

Compares with a mutable iterator for equality.

Parameters
otherIterator in the same container.
Returns
Index comparison result.

◆ operator==() [2/2]

template<typename T, typename Alloc = std::allocator< T >>
template<bool Const>
bool rpnx::segmented_dynar< T, Alloc >::iterator_impl< Const >::operator== ( const iterator_impl< true > & other) const
inline

Compares with an immutable iterator for equality.

Parameters
otherIterator in the same container.
Returns
Index comparison result.

◆ operator>() [1/2]

template<typename T, typename Alloc = std::allocator< T >>
template<bool Const>
bool rpnx::segmented_dynar< T, Alloc >::iterator_impl< Const >::operator> ( const iterator_impl< false > & other) const
inline

Tests whether this index follows a mutable iterator.

Parameters
otherIterator in the same container.
Returns
Index comparison result.

◆ operator>() [2/2]

template<typename T, typename Alloc = std::allocator< T >>
template<bool Const>
bool rpnx::segmented_dynar< T, Alloc >::iterator_impl< Const >::operator> ( const iterator_impl< true > & other) const
inline

Tests whether this index follows an immutable iterator.

Parameters
otherIterator in the same container.
Returns
Index comparison result.

◆ operator>=() [1/2]

template<typename T, typename Alloc = std::allocator< T >>
template<bool Const>
bool rpnx::segmented_dynar< T, Alloc >::iterator_impl< Const >::operator>= ( const iterator_impl< false > & other) const
inline

Tests whether this index does not precede a mutable iterator.

Parameters
otherIterator in the same container.
Returns
Index comparison result.

◆ operator>=() [2/2]

template<typename T, typename Alloc = std::allocator< T >>
template<bool Const>
bool rpnx::segmented_dynar< T, Alloc >::iterator_impl< Const >::operator>= ( const iterator_impl< true > & other) const
inline

Tests whether this index does not precede an immutable iterator.

Parameters
otherIterator in the same container.
Returns
Index comparison result.

◆ operator[]()

template<typename T, typename Alloc = std::allocator< T >>
template<bool Const>
reference rpnx::segmented_dynar< T, Alloc >::iterator_impl< Const >::operator[] ( difference_type n) const
inline

Dereferences an offset position.

Parameters
nOffset from this iterator.
Returns
Element reference.

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