Queue  1.0.0
A C++17 Library of various `queue` containers
circular_queue< T, Alloc >::const_iterator Class Reference

constant iterator for the circular_queue class. More...

#include <circular_queue.h>

Public Types

using iterator_category = std::random_access_iterator_tag
 
using value_type = const T
 
using difference_type = ptrdiff_t
 
using pointer = const T *
 
using reference = const T &
 

Public Member Functions

 const_iterator (const circular_queue *buffer, pointer start, bool parity) noexcept
 Constructor. More...
 
 const_iterator (const circular_queue *buffer, queue_pointer pointer) noexcept
 
 const_iterator (const const_iterator &other)=default
 
const_iteratoroperator= (const const_iterator &other)=default
 
 const_iterator (const_iterator &&other) noexcept
 
const_iteratoroperator= (const_iterator &&other) noexcept
 
 ~const_iterator () noexcept=default
 destructor. Complexity: Constant.
Exception Safety: No-throw guarantee: This function never throws exceptions.

 
reference operator* () const
 Dereference operator. More...
 
pointer operator& () const
 Dereference operator. More...
 
pointer operator-> () const
 Dereference operator. More...
 
reference operator[] (difference_type n) const
 Dereference iterator with offset. More...
 
bool operator== (const const_iterator &rhs) const noexcept
 equality operator More...
 
bool operator!= (const const_iterator &rhs) const
 inequality operator Complexity: Constant.
Iterator Validity: No changes.
Data Races: The container is accessed.
Exception Safety: No-throw guarantee: This function never throws exceptions.
More...
 
const_iteratoroperator++ () noexcept
 Increment iterator position (prefix) More...
 
const_iterator operator++ (int)
 Increment iterator position (postfix) More...
 
const_iteratoroperator+= (difference_type n) noexcept
 Advance iterator. More...
 
const_iterator operator+ (difference_type n) const noexcept
 Addition operator. More...
 
const_iteratoroperator-- () noexcept
 Decrease iterator position (prefix) More...
 
const_iterator operator-- (int)
 Decrease iterator position (postfix) More...
 
const_iteratoroperator-= (difference_type n) noexcept
 Retrocede iterator. More...
 
const_iterator operator- (difference_type n) const
 subtraction operator More...
 
difference_type operator- (const const_iterator &other) const
 subtraction operator More...
 
bool operator< (const const_iterator &rhs) const noexcept
 less-than operator More...
 
bool operator<= (const const_iterator &rhs) const
 less-than-or-equal operator More...
 
bool operator> (const const_iterator &rhs) const
 greater-than operator More...
 
bool operator>= (const const_iterator &rhs) const
 greater-than-or-equal operator More...
 

Protected Attributes

const circular_queuem_buffer = nullptr
 pointer to the buffer object that this iterates on.
 
queue_pointer m_pointer
 Iterator position.
 

Friends

class circular_queue
 

Detailed Description

template<class T, class Alloc = std::allocator<T>>
class circular_queue< T, Alloc >::const_iterator

constant iterator for the circular_queue class.

Constructor & Destructor Documentation

◆ const_iterator()

template<class T , class Alloc = std::allocator<T>>
circular_queue< T, Alloc >::const_iterator::const_iterator ( const circular_queue buffer,
pointer  start,
bool  parity 
)
inlinenoexcept

Constructor.

Creates an initialized iterator. Complexity: Constant.
Iterator Validity: N/A.
Data Races: N/A.
Exception Safety: No-throw guarantee: This function never throws exceptions.

Parameters
[in]bufferpointer to the underlying container.
[in]startpointer to the iterators starting offset

Member Function Documentation

◆ operator!=()

template<class T , class Alloc = std::allocator<T>>
bool circular_queue< T, Alloc >::const_iterator::operator!= ( const const_iterator rhs) const
inline

inequality operator Complexity: Constant.
Iterator Validity: No changes.
Data Races: The container is accessed.
Exception Safety: No-throw guarantee: This function never throws exceptions.

Parameters
[in]rhsright-hand-side of the equation.
Returns
true if both iterators point to different objects.

◆ operator&()

template<class T , class Alloc = std::allocator<T>>
pointer circular_queue< T, Alloc >::const_iterator::operator& ( ) const
inline

Dereference operator.

Returns a pointer to the element pointed to by the iterator. Complexity: Constant.
Iterator Validity: Unchanged.
Data Races: The object is accessed.
Exception Safety: Undefined if the iterator is not valid.

Returns
A pointer to the element pointed by the iterator.

◆ operator*()

template<class T , class Alloc = std::allocator<T>>
reference circular_queue< T, Alloc >::const_iterator::operator* ( ) const
inline

Dereference operator.

Returns a reference to the element pointed to by the iterator. Complexity: Constant.
Iterator Validity: No changes.
Data Races: The object is accessed.
Exception Safety: Undefined if the iterator is not valid.

Returns
A reference to the element pointed by the iterator.

◆ operator+()

template<class T , class Alloc = std::allocator<T>>
const_iterator circular_queue< T, Alloc >::const_iterator::operator+ ( difference_type  n) const
inlinenoexcept

Addition operator.

Returns an iterator pointing to the element located n positions away from the element the iterator currently points to.
Complexity: Constant.
Iterator Validity: Undefined behavior if the element n positions away is out of bounds.
Data Races: The object is accessed but NOT modified.
Exception Safety: Strong guarantee: if the constructor throws an exception, there are no side effects.

Parameters
[in]nnumber of elements to offset.
Returns
An iterator pointing to the element n positions away.

◆ operator++() [1/2]

template<class T , class Alloc = std::allocator<T>>
const_iterator& circular_queue< T, Alloc >::const_iterator::operator++ ( )
inlinenoexcept

Increment iterator position (prefix)

Advances the iterator by 1 position. Complexity: Constant.
Iterator Validity: Valid IFF the iterator is incrementable.
Data Races: The object is modified.
Exception Safety: No-throw guarantee: This function never throws exceptions.

Returns
A reference to the incremented iterator.

◆ operator++() [2/2]

template<class T , class Alloc = std::allocator<T>>
const_iterator circular_queue< T, Alloc >::const_iterator::operator++ ( int  )
inline

Increment iterator position (postfix)

Advances the iterator by 1 position. Complexity: Constant.
Iterator Validity: Valid IFF the iterator is incrementable.
Data Races: The object is modified.
Exception Safety: Strong guarantee: if the function throws an exception, there are no side effects.

Returns
A copy of the iterator before it was incremented.

◆ operator+=()

template<class T , class Alloc = std::allocator<T>>
const_iterator& circular_queue< T, Alloc >::const_iterator::operator+= ( difference_type  n)
inlinenoexcept

Advance iterator.

Advances the iterator by n element positions.
Complexity: Constant.
Iterator Validity: Results in undefined behavior if the element at position n does not exist.
Data Races: The object is modified.
Exception Safety: No-throw guarantee: This function never throws exceptions.

Parameters
[]n
Returns
circular_queueIterator&

◆ operator-() [1/2]

template<class T , class Alloc = std::allocator<T>>
difference_type circular_queue< T, Alloc >::const_iterator::operator- ( const const_iterator other) const
inline

subtraction operator

Returns the distance between two iterators. Complexity: Constant.
Iterator Validity: Undefined behavior if the iterator is not decrementable, otherwise no changes.
Data Races: the object is accessed but NOT modified.
Exception Safety: Strong guarantee: if the constructor throws an exception, there are no side effects.

Parameters
[in]otheriterator to determine distance from.
Returns
number of elements between the two iterators.

◆ operator-() [2/2]

template<class T , class Alloc = std::allocator<T>>
const_iterator circular_queue< T, Alloc >::const_iterator::operator- ( difference_type  n) const
inline

subtraction operator

Returns an iterator whose position is n elements before the current position Complexity: Constant.
Iterator Validity: Undefined behavior if the iterator is not decrementable, otherwise no changes.
Data Races: the object is accessed but NOT modified.
Exception Safety: Strong guarantee: if the constructor throws an exception, there are no side effects.

Parameters
[in]nNumberof elements to offset. Member type difference_type is an alias of the base container's own difference type.
Returns
An iterator decremented n positions from the current iterator position.

◆ operator--() [1/2]

template<class T , class Alloc = std::allocator<T>>
const_iterator& circular_queue< T, Alloc >::const_iterator::operator-- ( )
inlinenoexcept

Decrease iterator position (prefix)

Decreases the iterator by one position.
Complexity: Constant.
Iterator Validity: Undefined behavior if the iterator is not decrementable, otherwise no changes.
Data Races: The object is modified.
Exception Safety: No-throw guarantee: This function never throws exceptions.

Returns
A reference to an iterator pointing to the post-decrement iterator.

◆ operator--() [2/2]

template<class T , class Alloc = std::allocator<T>>
const_iterator circular_queue< T, Alloc >::const_iterator::operator-- ( int  )
inline

Decrease iterator position (postfix)

Decreases the iterator by one position.
Complexity: Constant.
Iterator Validity: Undefined behavior if the iterator is not decrementable, otherwise no changes.
Data Races: The object is accessed but NOT modified.
Exception Safety: Strong guarantee: if the constructor throws an exception, there are no side effects.

Returns
A iterator pointing to the pre-decremented element.

◆ operator-=()

template<class T , class Alloc = std::allocator<T>>
const_iterator& circular_queue< T, Alloc >::const_iterator::operator-= ( difference_type  n)
inlinenoexcept

Retrocede iterator.

Decreases the iterator by n element positions. Complexity: Constant.
Iterator Validity: Undefined behavior if the iterator is not decrementable, otherwise no changes.
Data Races: The object is modified.
Exception Safety: No-throw guarantee: This function never throws exceptions.

Parameters
[in]nNumber of elements to offset. Member type difference_type is an alias of the base container's own difference type.
Returns
the iterator itself, decremented by n positions.

◆ operator->()

template<class T , class Alloc = std::allocator<T>>
pointer circular_queue< T, Alloc >::const_iterator::operator-> ( ) const
inline

Dereference operator.

Returns a pointer to the element pointed to by the iterator. Complexity: Constant.
Iterator Validity: Unchanged.
Data Races: The object is accessed.
Exception Safety: Undefined if the iterator is not valid.

Returns
A pointer to the element pointed by the iterator.

◆ operator<()

template<class T , class Alloc = std::allocator<T>>
bool circular_queue< T, Alloc >::const_iterator::operator< ( const const_iterator rhs) const
inlinenoexcept

less-than operator

Performs the appropriate comparison. Complexity: Constant.
Iterator Validity: No changes.
Data Races: The object is accessed.
Exception Safety: No-throw guarantee: This function never throws exceptions.

Parameters
[in]rhsiterator for the right-hand side of the comparison.
Returns
true if this iterator is less than rhs.

◆ operator<=()

template<class T , class Alloc = std::allocator<T>>
bool circular_queue< T, Alloc >::const_iterator::operator<= ( const const_iterator rhs) const
inline

less-than-or-equal operator

Performs the appropriate comparison. Complexity: Constant.
Iterator Validity: No changes.
Data Races: The object is accessed.
Exception Safety: No-throw guarantee: This function never throws exceptions.

Parameters
[in]rhsiterator for the right-hand side of the comparison.
Returns
true if this iterator is less than or equal to rhs.

◆ operator==()

template<class T , class Alloc = std::allocator<T>>
bool circular_queue< T, Alloc >::const_iterator::operator== ( const const_iterator rhs) const
inlinenoexcept

equality operator

Two iterators are equal if they point to the same object and have the same parity value (i.e. one isn't wrapped around the buffer from the other).
Complexity: Constant.
Iterator Validity: No changes.
Data Races: The container is accessed.
Exception Safety: No-throw guarantee: This function never throws exceptions.

Parameters
[in]rhsright-hand-side of the equation.
Returns
true if both iterators point to the same object.

◆ operator>()

template<class T , class Alloc = std::allocator<T>>
bool circular_queue< T, Alloc >::const_iterator::operator> ( const const_iterator rhs) const
inline

greater-than operator

Performs the appropriate comparison. Complexity: Constant.
Iterator Validity: No changes.
Data Races: The object is accessed.
Exception Safety: No-throw guarantee: This function never throws exceptions.

Parameters
[in]rhsiterator for the right-hand side of the comparison.
Returns
true if this iterator is greater than rhs.

◆ operator>=()

template<class T , class Alloc = std::allocator<T>>
bool circular_queue< T, Alloc >::const_iterator::operator>= ( const const_iterator rhs) const
inline

greater-than-or-equal operator

Performs the appropriate comparison. Complexity: Constant.
Iterator Validity: No changes.
Data Races: The object is accessed.
Exception Safety: No-throw guarantee: This function never throws exceptions.

Parameters
[in]rhsiterator for the right-hand side of the comparison.
Returns
true if this iterator is greater than or equal to rhs.

◆ operator[]()

template<class T , class Alloc = std::allocator<T>>
reference circular_queue< T, Alloc >::const_iterator::operator[] ( difference_type  n) const
inline

Dereference iterator with offset.

Accesses the element located n positions away from the element currently pointed to by the iterator. If such an element does not exist, it causes undefined behavior. Complexity: Constant.
Iterator Validity: Unchanged.
Data Races: The object is accessed. Depending on the return type, the value returned may be used to access or modify elements.
Exception Safety: Undefined behavior if n is out of range.

Parameters
[in]nNumber of elements to offset. Member type difference_type is an alias of the base container's own difference type.
Returns
The element n positions away from the element currently pointed by the iterator.

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