omni::detail::PointerIterator
Defined in omni/detail/PointerIterator.h
-
template<typename TPointer, typename TContainer>
class PointerIterator This iterator adapter wraps a pointer type into a class. It does not change the semantics of any operations from the fundamental logic of pointers. There are no bounds checks, there is no additional safety.
// This is meant to be used on contiguous containers where returning a pointer from @c begin and @c end would be // inappropriate. template <typename T> class MyContainer { public: using iterator = detail::PointerIterator<T*, MyContainer>; using const_iterator = detail::PointerIterator<T const*, MyContainer>; // ... iterator begin() { return iterator{data()}; } };
- Template Parameters
TPointer – The pointer to base this wrapper on. The underlying value type of the pointer can be const-qualified.
TContainer – The container type this iterator iterates over. This is useful to make types distinct, even in cases where
TPointer
would be identical; for example, astring
vs avector<char>
. This is allowed to bevoid
for cases where there is no underlying container.
Public Types
-
using value_type = typename underlying_traits_type::value_type
The underlying value that dereferencing this iterator returns. Note that this is not const-qualified; the
const_iterator
for a container will still returnT
.
-
using reference = typename underlying_traits_type::reference
The reference type dereferencing this iterator returns. This is const-qualified, so
iterator
for a container will returnT&
andconst_iterator
will returnconst T&
.
-
using pointer = typename underlying_traits_type::pointer
The underlying pointer type
operator->()
returns. This is const-qualified, soiterator
for a container will returnT*
andconst_iterator
will returnconst T*
.
-
using difference_type = typename underlying_traits_type::difference_type
The type used to represent the distance between two iterators. This will always be
std::ptrdiff_t
.
-
using iterator_category = typename underlying_traits_type::iterator_category
The category of this iterator. This will always be
std::random_access_iterator_tag
.
Public Functions
-
inline constexpr PointerIterator() noexcept
Default construction of a pointer-iterator results in an iterator pointing to
nullptr
.
-
inline explicit constexpr PointerIterator(pointer src) noexcept
Create an iterator from src pointer.
-
PointerIterator(const PointerIterator&) = default
Instances are trivially copy-constructible.
-
PointerIterator(PointerIterator&&) = default
Instances are trivially move-constructible.
-
PointerIterator &operator=(const PointerIterator&) = default
Instances are trivially copyable.
-
PointerIterator &operator=(PointerIterator&&) = default
Instances are trivially movable.
-
~PointerIterator() = default
Instances are trivially destructible.
-
template<typename UPointer, typename = std::enable_if_t<!std::is_same<TPointer, UPointer>::value && std::is_convertible<std::remove_reference_t<typename PointerIterator<UPointer, TContainer>::reference> (*)[], std::remove_reference_t<reference> (*)[]>::value>>
inline constexpr PointerIterator(const PointerIterator<UPointer, TContainer> &src) noexcept Converting constructor to allow conversion from a non-const iterator type to a const iterator type. Generally, this allows a
TContainer::iterator
to become aTContainer::const_iterator
.This constructor is only enabled if:
The
TContainer
for the two types is the same.The
TPointer
is different fromUPointer
(there is a conversion which needs to occur).A pointer to an array of the src const-qualified
value_type
(akaremove_reference_t<reference>
) is convertible to an array of this const-qualifiedvalue_type
. This restricts conversion of iterators from a derived to a base class pointer type.
-
inline constexpr reference operator[](difference_type idx) const noexcept
Get the value at offset idx from this iterator. Negative values are supported to reference behind this instance.
-
inline constexpr PointerIterator &operator++() noexcept
Move the iterator forward by one.
-
inline constexpr PointerIterator operator++(int) noexcept
Move the iterator forward by one, but return the previous position.
-
inline constexpr PointerIterator &operator--() noexcept
Move the iterator backwards by one.
-
inline constexpr PointerIterator operator--(int) noexcept
Move the iterator backwards by one, but return the previous position.
-
inline constexpr PointerIterator &operator+=(difference_type dist) noexcept
Move the iterator forward by dist.
-
inline constexpr PointerIterator operator+(difference_type dist) const noexcept
Get a new iterator pointing dist elements forward from this one.
-
inline constexpr PointerIterator &operator-=(difference_type dist) noexcept
Move the iterator backwards by dist.
-
inline constexpr PointerIterator operator-(difference_type dist) const noexcept
Get a new iterator pointing dist elements backwards from this one.