Monado OpenXR Runtime
|
Template for base class used by "random-access" iterators and const_iterators, providing all the functionality that is independent of element type and const-ness of the iterator. More...
#include <util/u_iterator_base.hpp>
Public Types | |
using | iterator_category = std::random_access_iterator_tag |
using | difference_type = std::ptrdiff_t |
using | const_iterator_base = std::conditional_t< std::is_const< ContainerOrHelper >::value, RandomAccessIteratorBase, RandomAccessIteratorBase< std::add_const_t< ContainerOrHelper > > > |
Public Member Functions | |
bool | valid () const noexcept |
Is this iterator valid? More... | |
operator bool () const noexcept | |
Is this iterator valid? More... | |
size_t | index () const noexcept |
What is the index stored by this iterator? More... | |
bool | is_past_the_end () const noexcept |
Is this iterator pointing "past the end" of the container? More... | |
bool | is_cleared () const noexcept |
True if this iterator is "irrecoverably" invalid (that is, cleared or default constructed). More... | |
std::ptrdiff_t | operator- (const RandomAccessIteratorBase< ContainerOrHelper > &other) const |
Compute the difference between two iterators. More... | |
RandomAccessIteratorBase & | operator+= (std::ptrdiff_t n) |
Increment by an arbitrary value. More... | |
RandomAccessIteratorBase & | operator-= (std::ptrdiff_t n) |
Decrement by an arbitrary value. More... | |
RandomAccessIteratorBase | operator+ (std::ptrdiff_t n) const |
Add some arbitrary amount to a copy of this iterator. More... | |
RandomAccessIteratorBase | operator- (std::ptrdiff_t n) const |
Subtract some arbitrary amount from a copy of this iterator. More... | |
RandomAccessIteratorBase ()=default | |
Default constructor - initializes to "cleared" (that is, irrecoverably invalid - because we have no reference to a container) More... | |
RandomAccessIteratorBase (ContainerOrHelper &container, size_t index) | |
Constructor from a helper/container and index. More... | |
const_iterator_base | as_const () const |
Get a const iterator base pointing to the same element as this element. More... | |
Static Public Member Functions | |
static RandomAccessIteratorBase | begin (ContainerOrHelper &container) |
Factory function: construct the "begin" iterator. More... | |
static RandomAccessIteratorBase | end (ContainerOrHelper &container) |
Factory function: construct the "past the end" iterator that can be decremented safely. More... | |
Protected Member Functions | |
RandomAccessIteratorBase (ContainerOrHelper *container, size_t index) | |
for internal use More... | |
void | increment_n (std::size_t n) |
Increment an arbitrary amount. More... | |
void | decrement_n (std::size_t n) |
Decrement an arbitrary amount. More... | |
ContainerOrHelper * | container () const noexcept |
Get the associated container or helper. More... | |
Related Functions | |
(Note that these are not member functions.) | |
template<typename ContainerOrHelper > | |
static bool | operator== (RandomAccessIteratorBase< ContainerOrHelper > const &lhs, RandomAccessIteratorBase< ContainerOrHelper > const &rhs) noexcept |
Equality comparison operator for RandomAccessIteratorBase. More... | |
template<typename ContainerOrHelper > | |
static bool | operator!= (RandomAccessIteratorBase< ContainerOrHelper > const &lhs, RandomAccessIteratorBase< ContainerOrHelper > const &rhs) noexcept |
Inequality comparison operator for RandomAccessIteratorBase. More... | |
Template for base class used by "random-access" iterators and const_iterators, providing all the functionality that is independent of element type and const-ness of the iterator.
Using inheritance instead of composition here to more easily satisfy the C++ standard's requirements for iterators (e.g. that const iterators and iterators are comparable, etc.)
All invalid instances will compare as equal, as required by the spec, but they are not all equivalent. You can freely go "past the end" (they will be invalid, so cannot dereference, but you can get them back to valid), but you can't go "past the beginning". That is, you can do *(buf.end() - 1)
successfully if your buffer has at least one element, even though buf.end()
is invalid.
ContainerOrHelper | Your container or some member thereof that provides a size() method. If it's a helper instead of the actual container, make it const. |
|
default |
Default constructor - initializes to "cleared" (that is, irrecoverably invalid - because we have no reference to a container)
Referenced by xrt::auxiliary::util::RandomAccessIteratorBase< ContainerOrHelper >::begin(), and xrt::auxiliary::util::RandomAccessIteratorBase< ContainerOrHelper >::end().
|
inlineexplicit |
Constructor from a helper/container and index.
container | The helper or container we will iterate through. |
index | An index - may be out of range. |
|
inlineprotected |
for internal use
|
inline |
Get a const iterator base pointing to the same element as this element.
References xrt::auxiliary::util::RandomAccessIteratorBase< ContainerOrHelper >::is_cleared().
|
inlinestatic |
Factory function: construct the "begin" iterator.
References xrt::auxiliary::util::RandomAccessIteratorBase< ContainerOrHelper >::container(), and xrt::auxiliary::util::RandomAccessIteratorBase< ContainerOrHelper >::RandomAccessIteratorBase().
|
inlineprotectednoexcept |
Get the associated container or helper.
Referenced by xrt::auxiliary::util::RandomAccessIteratorBase< ContainerOrHelper >::begin(), and xrt::auxiliary::util::RandomAccessIteratorBase< ContainerOrHelper >::end().
|
inlineprotected |
Decrement an arbitrary amount.
|
inlinestatic |
Factory function: construct the "past the end" iterator that can be decremented safely.
References xrt::auxiliary::util::RandomAccessIteratorBase< ContainerOrHelper >::container(), and xrt::auxiliary::util::RandomAccessIteratorBase< ContainerOrHelper >::RandomAccessIteratorBase().
|
inlineprotected |
Increment an arbitrary amount.
|
inlinenoexcept |
What is the index stored by this iterator?
|
inlinenoexcept |
True if this iterator is "irrecoverably" invalid (that is, cleared or default constructed).
Implies !valid() but is stronger. buf.end().is_cleared()
is false.
Referenced by xrt::auxiliary::util::RandomAccessIteratorBase< ContainerOrHelper >::as_const(), and xrt::auxiliary::util::RandomAccessIteratorBase< ContainerOrHelper >::operator-().
|
inlinenoexcept |
Is this iterator pointing "past the end" of the container?
|
inlineexplicitnoexcept |
Is this iterator valid?
References xrt::auxiliary::util::RandomAccessIteratorBase< ContainerOrHelper >::valid().
RandomAccessIteratorBase xrt::auxiliary::util::RandomAccessIteratorBase< ContainerOrHelper >::operator+ | ( | std::ptrdiff_t | n | ) | const |
Add some arbitrary amount to a copy of this iterator.
|
inline |
Increment by an arbitrary value.
|
inline |
Compute the difference between two iterators.
std::logic_error | if exactly one of the iterators is cleared |
std::out_of_range | if at least one of the iterators has an index larger than the maximum value of std::ptrdiff_t. |
References xrt::auxiliary::util::RandomAccessIteratorBase< ContainerOrHelper >::is_cleared().
RandomAccessIteratorBase xrt::auxiliary::util::RandomAccessIteratorBase< ContainerOrHelper >::operator- | ( | std::ptrdiff_t | n | ) | const |
Subtract some arbitrary amount from a copy of this iterator.
|
inline |
Decrement by an arbitrary value.
|
inlinenoexcept |
Is this iterator valid?
Referenced by xrt::auxiliary::util::RandomAccessIteratorBase< ContainerOrHelper >::operator bool().
|
related |
Inequality comparison operator for RandomAccessIteratorBase.
|
related |
Equality comparison operator for RandomAccessIteratorBase.