VectorPro
High-performance, header-only dynamic array with configurable growth policy, custom allocator support, and optional modification-event notifications.
Loading...
Searching...
No Matches
VectorPro::Iterator< T > Class Template Reference

A raw-pointer-backed contiguous random-access iterator. More...

#include <Iterator.h>

Public Types

using iterator_concept = std::contiguous_iterator_tag
 
using iterator_category = std::random_access_iterator_tag
 
using value_type = std::remove_cv_t< T >
 
using element_type = T
 
using difference_type = std::ptrdiff_t
 
using pointer = T *
 
using reference = T &
 

Public Member Functions

constexpr Iterator () noexcept=default
 Constructs a null (singular) iterator.
 
constexpr Iterator (pointer ptr) noexcept
 Constructs an iterator pointing to ptr.
 
template<typename U >
requires std::is_same_v<U, std::remove_cv_t<T>>
constexpr Iterator (const Iterator< U > &other) noexcept
 Converting constructor from a non-const iterator to a const iterator.
 
constexpr reference operator* () const noexcept
 Dereferences the iterator.
 
constexpr pointer operator-> () const noexcept
 Returns the underlying pointer.
 
constexpr reference operator[] (difference_type n) const noexcept
 Accesses the element n positions away.
 
constexpr Iterator & operator++ () noexcept
 Pre-increments the iterator to point to the next element.
 
constexpr Iterator operator++ (int) noexcept
 Post-increments the iterator to point to the next element.
 
constexpr Iterator & operator-- () noexcept
 Pre-decrements the iterator to point to the previous element.
 
constexpr Iterator operator-- (int) noexcept
 Post-decrements the iterator to point to the previous element.
 
constexpr Iterator & operator+= (difference_type n) noexcept
 Advances the iterator by n positions.
 
constexpr Iterator & operator-= (difference_type n) noexcept
 Moves the iterator back by n positions.
 

Friends

constexpr Iterator operator+ (Iterator i, difference_type n) noexcept
 Returns an iterator advanced by n positions.
 
constexpr Iterator operator+ (difference_type n, Iterator i) noexcept
 Returns an iterator advanced by n positions.
 
constexpr Iterator operator- (Iterator i, difference_type n) noexcept
 Returns an iterator moved back by n positions.
 
constexpr difference_type operator- (Iterator a, Iterator b) noexcept
 Computes the distance between two iterators.
 
constexpr bool operator== (const Iterator &a, const Iterator &b) noexcept
 Compares two iterators for equality.
 
constexpr auto operator<=> (const Iterator &a, const Iterator &b) noexcept
 Three-way compares two iterators by position.
 

Detailed Description

template<typename T>
class VectorPro::Iterator< T >

A raw-pointer-backed contiguous random-access iterator.

Template Parameters
TElement type pointed to. May be const-qualified for a const iterator.

Satisfies std::contiguous_iterator. Used as VectorPro::Vector's iterator and const_iterator (with T and const T respectively).

Member Typedef Documentation

◆ difference_type

template<typename T >
using VectorPro::Iterator< T >::difference_type = std::ptrdiff_t

◆ element_type

template<typename T >
using VectorPro::Iterator< T >::element_type = T

◆ iterator_category

template<typename T >
using VectorPro::Iterator< T >::iterator_category = std::random_access_iterator_tag

◆ iterator_concept

template<typename T >
using VectorPro::Iterator< T >::iterator_concept = std::contiguous_iterator_tag

◆ pointer

template<typename T >
using VectorPro::Iterator< T >::pointer = T*

◆ reference

template<typename T >
using VectorPro::Iterator< T >::reference = T&

◆ value_type

template<typename T >
using VectorPro::Iterator< T >::value_type = std::remove_cv_t<T>

Constructor & Destructor Documentation

◆ Iterator() [1/3]

template<typename T >
constexpr VectorPro::Iterator< T >::Iterator ( )
constexprdefaultnoexcept

Constructs a null (singular) iterator.

◆ Iterator() [2/3]

template<typename T >
constexpr VectorPro::Iterator< T >::Iterator ( pointer  ptr)
inlineexplicitconstexprnoexcept

Constructs an iterator pointing to ptr.

Parameters
ptrPointer to the element the iterator should reference.

◆ Iterator() [3/3]

template<typename T >
template<typename U >
requires std::is_same_v<U, std::remove_cv_t<T>>
constexpr VectorPro::Iterator< T >::Iterator ( const Iterator< U > &  other)
inlineconstexprnoexcept

Converting constructor from a non-const iterator to a const iterator.

Template Parameters
USource element type, must be std::remove_cv_t<T>.
Parameters
otherIterator to convert from.

Enables implicit iterator -> const_iterator conversion.

Member Function Documentation

◆ operator*()

template<typename T >
constexpr reference VectorPro::Iterator< T >::operator* ( ) const
inlineconstexprnoexcept

Dereferences the iterator.

Returns
Reference to the pointed-to element.

◆ operator++() [1/2]

template<typename T >
constexpr Iterator & VectorPro::Iterator< T >::operator++ ( )
inlineconstexprnoexcept

Pre-increments the iterator to point to the next element.

Returns
Reference to *this.

◆ operator++() [2/2]

template<typename T >
constexpr Iterator VectorPro::Iterator< T >::operator++ ( int  )
inlineconstexprnoexcept

Post-increments the iterator to point to the next element.

Returns
A copy of the iterator's value before incrementing.
Note
cert-dcl21-cpp asks postfix ++/– to return a const object to block it++ = x-style misuse. That conflicts with C++20's std::incrementable concept (required by std::contiguous_iterator, which this type satisfies), which mandates { i++ } -> std::same_as<I> – an exact, non-const Iterator return type. The concept requirement wins here, so this diagnostic is intentionally suppressed.

◆ operator+=()

template<typename T >
constexpr Iterator & VectorPro::Iterator< T >::operator+= ( difference_type  n)
inlineconstexprnoexcept

Advances the iterator by n positions.

Parameters
nNumber of positions to advance (may be negative).
Returns
Reference to *this.

◆ operator--() [1/2]

template<typename T >
constexpr Iterator & VectorPro::Iterator< T >::operator-- ( )
inlineconstexprnoexcept

Pre-decrements the iterator to point to the previous element.

Returns
Reference to *this.

◆ operator--() [2/2]

template<typename T >
constexpr Iterator VectorPro::Iterator< T >::operator-- ( int  )
inlineconstexprnoexcept

Post-decrements the iterator to point to the previous element.

Returns
A copy of the iterator's value before decrementing.
Note
See the operator++(int) note above – the same std::incrementable/concept conflict applies here, so cert-dcl21-cpp is intentionally suppressed rather than adding const.

◆ operator-=()

template<typename T >
constexpr Iterator & VectorPro::Iterator< T >::operator-= ( difference_type  n)
inlineconstexprnoexcept

Moves the iterator back by n positions.

Parameters
nNumber of positions to move back (may be negative).
Returns
Reference to *this.

◆ operator->()

template<typename T >
constexpr pointer VectorPro::Iterator< T >::operator-> ( ) const
inlineconstexprnoexcept

Returns the underlying pointer.

◆ operator[]()

template<typename T >
constexpr reference VectorPro::Iterator< T >::operator[] ( difference_type  n) const
inlineconstexprnoexcept

Accesses the element n positions away.

Parameters
nOffset from the current position.
Returns
Reference to the element at the offset position.

Friends And Related Symbol Documentation

◆ operator+ [1/2]

template<typename T >
constexpr Iterator operator+ ( difference_type  n,
Iterator< T >  i 
)
friend

Returns an iterator advanced by n positions.

Parameters
iBase iterator.
nNumber of positions to advance.
Returns
A new iterator, offset from i by n.

◆ operator+ [2/2]

template<typename T >
constexpr Iterator operator+ ( Iterator< T >  i,
difference_type  n 
)
friend

Returns an iterator advanced by n positions.

Parameters
iBase iterator.
nNumber of positions to advance.
Returns
A new iterator, offset from i by n.

◆ operator- [1/2]

template<typename T >
constexpr difference_type operator- ( Iterator< T >  a,
Iterator< T >  b 
)
friend

Computes the distance between two iterators.

Parameters
aFirst iterator.
bSecond iterator.
Returns
The number of elements between b and a (a - b).

◆ operator- [2/2]

template<typename T >
constexpr Iterator operator- ( Iterator< T >  i,
difference_type  n 
)
friend

Returns an iterator moved back by n positions.

Parameters
iBase iterator.
nNumber of positions to move back.
Returns
A new iterator, offset from i by -n.

◆ operator<=>

template<typename T >
constexpr auto operator<=> ( const Iterator< T > &  a,
const Iterator< T > &  b 
)
friend

Three-way compares two iterators by position.

Parameters
aFirst iterator.
bSecond iterator.
Returns
The strong ordering between a and b.

◆ operator==

template<typename T >
constexpr bool operator== ( const Iterator< T > &  a,
const Iterator< T > &  b 
)
friend

Compares two iterators for equality.

Parameters
aFirst iterator.
bSecond iterator.
Returns
true if both point to the same element.

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