19namespace xrt::auxiliary::util {
39 using iterator_category = std::random_access_iterator_tag;
40 using difference_type = std::ptrdiff_t;
48 explicit operator
bool() const noexcept
64 return container_ !=
nullptr && index_ >= container_->size();
75 return container_ ==
nullptr;
145 using const_iterator_base = std::conditional_t<std::is_const<ContainerOrHelper>::value,
161 return const_iterator_base{*container_, index_};
191 ContainerOrHelper *container_{
nullptr};
202template <
typename ContainerOrHelper>
207 const bool lhs_valid = lhs.valid();
208 const bool rhs_valid = rhs.valid();
209 if (!lhs_valid && !rhs_valid) {
213 if (lhs_valid != rhs_valid) {
218 return lhs.index() == rhs.index();
224template <
typename ContainerOrHelper>
229 return lhs == rhs.as_const();
234template <
typename ContainerOrHelper>
239 return lhs.as_const() == rhs;
247template <
typename ContainerOrHelper>
252 return !(lhs == rhs);
258template <
typename ContainerOrHelper>
263 return !(lhs == rhs.as_const());
269template <
typename ContainerOrHelper>
274 return !(lhs.as_const() == rhs);
277template <
typename ContainerOrHelper>
281 return container_ !=
nullptr && index_ < container_->size();
284template <
typename ContainerOrHelper>
289 decrement_n(
static_cast<size_t>(-1 * n));
291 increment_n(
static_cast<size_t>(n));
296template <
typename ContainerOrHelper>
301 increment_n(
static_cast<size_t>(-1 * n));
303 decrement_n(
static_cast<size_t>(n));
308template <
typename ContainerOrHelper>
318template <
typename ContainerOrHelper>
333template <
typename ContainerOrHelper>
337 const bool self_cleared = is_cleared();
338 const bool other_cleared = other.
is_cleared();
339 if (self_cleared && other_cleared) {
343 if (self_cleared || other_cleared) {
345 throw std::logic_error(
346 "Tried to find the difference between a cleared iterator and a non-cleared iterator.");
348 constexpr size_t max_ptrdiff =
static_cast<size_t>(std::numeric_limits<std::ptrdiff_t>::max());
349 if (index_ > max_ptrdiff || other.index_ > max_ptrdiff) {
350 throw std::out_of_range(
"An index exceeded the maximum value of the signed version of the index type.");
353 return static_cast<std::ptrdiff_t
>(index_) -
static_cast<std::ptrdiff_t
>(other.index_);
356template <
typename ContainerOrHelper>
358 : container_(&container), index_(index)
Template for base class used by "random-access" iterators and const_iterators, providing all the func...
Definition: u_iterator_base.hpp:37
void increment_n(std::size_t n)
Increment an arbitrary amount.
Definition: u_iterator_base.hpp:310
static RandomAccessIteratorBase end(ContainerOrHelper &container)
Factory function: construct the "past the end" iterator that can be decremented safely.
Definition: u_iterator_base.hpp:124
RandomAccessIteratorBase operator+(std::ptrdiff_t n) const
Add some arbitrary amount to a copy of this iterator.
std::ptrdiff_t operator-(const RandomAccessIteratorBase< ContainerOrHelper > &other) const
Compute the difference between two iterators.
Definition: u_iterator_base.hpp:335
static bool operator==(RandomAccessIteratorBase< ContainerOrHelper > const &lhs, RandomAccessIteratorBase< ContainerOrHelper > const &rhs) noexcept
Equality comparison operator for RandomAccessIteratorBase.
Definition: u_iterator_base.hpp:204
void decrement_n(std::size_t n)
Decrement an arbitrary amount.
Definition: u_iterator_base.hpp:320
RandomAccessIteratorBase & operator+=(std::ptrdiff_t n)
Increment by an arbitrary value.
Definition: u_iterator_base.hpp:286
bool valid() const noexcept
Is this iterator valid?
Definition: u_iterator_base.hpp:279
RandomAccessIteratorBase & operator-=(std::ptrdiff_t n)
Decrement by an arbitrary value.
Definition: u_iterator_base.hpp:298
static bool operator!=(RandomAccessIteratorBase< ContainerOrHelper > const &lhs, RandomAccessIteratorBase< ContainerOrHelper > const &rhs) noexcept
Inequality comparison operator for RandomAccessIteratorBase.
Definition: u_iterator_base.hpp:249
ContainerOrHelper * container() const noexcept
Get the associated container or helper.
Definition: u_iterator_base.hpp:178
RandomAccessIteratorBase(ContainerOrHelper *container, size_t index)
for internal use
Definition: u_iterator_base.hpp:166
bool is_past_the_end() const noexcept
Is this iterator pointing "past the end" of the container?
Definition: u_iterator_base.hpp:62
size_t index() const noexcept
What is the index stored by this iterator?
Definition: u_iterator_base.hpp:55
static RandomAccessIteratorBase begin(ContainerOrHelper &container)
Factory function: construct the "begin" iterator.
Definition: u_iterator_base.hpp:117
bool is_cleared() const noexcept
True if this iterator is "irrecoverably" invalid (that is, cleared or default constructed).
Definition: u_iterator_base.hpp:73
RandomAccessIteratorBase operator-(std::ptrdiff_t n) const
Subtract some arbitrary amount from a copy of this iterator.
RandomAccessIteratorBase()=default
Default constructor - initializes to "cleared" (that is, irrecoverably invalid - because we have no r...
const_iterator_base as_const() const
Get a const iterator base pointing to the same element as this element.
Definition: u_iterator_base.hpp:155
RandomAccessIteratorBase(ContainerOrHelper &container, size_t index)
Constructor from a helper/container and index.
Definition: u_iterator_base.hpp:357
static bool operator==(RandomAccessIteratorBase< const ContainerOrHelper > const &lhs, RandomAccessIteratorBase< ContainerOrHelper > const &rhs) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: u_iterator_base.hpp:226
static bool operator!=(RandomAccessIteratorBase< const ContainerOrHelper > const &lhs, RandomAccessIteratorBase< ContainerOrHelper > const &rhs) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: u_iterator_base.hpp:260