RPNX::DataStructures
Header-only C++ data structures and supporting utilities.
Loading...
Searching...
No Matches
rpnx::bounded_iterator< It > Class Template Reference

Forward iterator adapter that checks access against an end sentinel. More...

#include <iterator.hpp>

Public Types

using iterator_type = It
 Wrapped iterator type.
 
using iterator_category = typename traits::iterator_category
 Iterator category exposed by the wrapped iterator.
 
using value_type = typename traits::value_type
 Iterated value type.
 
using difference_type = typename traits::difference_type
 Signed iterator-distance type.
 
using pointer = typename traits::pointer
 Pointer type returned by member access.
 
using reference = typename traits::reference
 Reference type returned by dereference.
 

Public Member Functions

 bounded_iterator ()=default
 Constructs a value-initialized iterator and sentinel.
 
constexpr bounded_iterator (It current, It last)
 Constructs an adapter for a current position and end sentinel.
 
constexpr reference operator* () const
 Dereferences the current position.
 
constexpr pointer operator-> () const
 Accesses the current element.
 
constexpr bounded_iteratoroperator++ ()
 Advances to the next position.
 
constexpr bounded_iterator operator++ (int)
 Advances to the next position.
 
constexpr bool operator== (const bounded_iterator &rhs) const
 Compares current positions.
 
constexpr bool operator!= (const bounded_iterator &rhs) const
 Compares current positions for inequality.
 

Detailed Description

template<class It>
class rpnx::bounded_iterator< It >

Forward iterator adapter that checks access against an end sentinel.

The adapter turns dereferencing or incrementing an end iterator into a deterministic std::out_of_range exception. The wrapped iterator and sentinel must belong to the same underlying range and must outlive this non-owning adapter.

Template Parameters
ItForward iterator type to wrap.

Constructor & Destructor Documentation

◆ bounded_iterator()

template<class It>
rpnx::bounded_iterator< It >::bounded_iterator ( It current,
It last )
inlineconstexpr

Constructs an adapter for a current position and end sentinel.

Parameters
currentCurrent iterator position.
lastEnd sentinel for the same range.

Member Function Documentation

◆ operator!=()

template<class It>
bool rpnx::bounded_iterator< It >::operator!= ( const bounded_iterator< It > & rhs) const
inlineconstexpr

Compares current positions for inequality.

Parameters
rhsIterator to compare.
Returns
Negation of equality.

◆ operator*()

template<class It>
reference rpnx::bounded_iterator< It >::operator* ( ) const
inlineconstexpr

Dereferences the current position.

Returns
Referenced element.
Exceptions
std::out_of_rangeif positioned at the end sentinel.

◆ operator++() [1/2]

template<class It>
bounded_iterator & rpnx::bounded_iterator< It >::operator++ ( )
inlineconstexpr

Advances to the next position.

Returns
Reference to this iterator.
Exceptions
std::out_of_rangeif already at the end sentinel.

◆ operator++() [2/2]

template<class It>
bounded_iterator rpnx::bounded_iterator< It >::operator++ ( int )
inlineconstexpr

Advances to the next position.

Returns
Copy of the iterator before increment.
Exceptions
std::out_of_rangeif already at the end sentinel.

◆ operator->()

template<class It>
pointer rpnx::bounded_iterator< It >::operator-> ( ) const
inlineconstexpr

Accesses the current element.

Returns
Pointer to the current element.
Exceptions
std::out_of_rangeif positioned at the end sentinel.

◆ operator==()

template<class It>
bool rpnx::bounded_iterator< It >::operator== ( const bounded_iterator< It > & rhs) const
inlineconstexpr

Compares current positions.

Parameters
rhsIterator to compare.
Returns
true when both wrap equal current iterators.

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