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

iterator for the circular_queue class. More...

#include <circular_queue.h>

Public Types

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

Public Member Functions

 iterator (const circular_queue *const buffer, pointer start, bool parity) noexcept
 Constructor. More...
 
 iterator (const circular_queue *const buffer, queue_pointer pointer) noexcept
 
 iterator (const iterator &other)=default
 
iteratoroperator= (const iterator &other)=default
 
 iterator (iterator &&other) noexcept
 
iteratoroperator= (iterator &&other) noexcept
 
 ~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 iterator &rhs) const noexcept
 equality operator More...
 
bool operator!= (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...
 
iteratoroperator++ () noexcept
 Increment iterator position (prefix) More...
 
iterator operator++ (int)
 Increment iterator position (postfix) More...
 
iteratoroperator+= (difference_type n) noexcept
 Advance iterator. More...
 
iterator operator+ (difference_type n) const noexcept
 Addition operator. More...
 
iteratoroperator-- () noexcept
 Decrease iterator position (prefix) More...
 
iterator operator-- (int)
 Decrease iterator position (postfix) More...
 
iteratoroperator-= (difference_type n) noexcept
 Retrocede iterator. More...
 
iterator operator- (difference_type n) const
 subtraction operator More...
 
difference_type operator- (const iterator &other) const
 subtraction operator More...
 
bool operator< (const iterator &rhs) const noexcept
 less-than operator More...
 
bool operator<= (const iterator &rhs) const
 less-than-or-equal operator More...
 
bool operator> (const iterator &rhs) const
 greater-than operator More...
 
bool operator>= (const iterator &rhs) const
 greater-than-or-equal operator More...
 
 operator const_iterator () const
 Allow implicit conversion from iterator to const_iterator as required by STL.
 

Protected Attributes

const circular_queuem_buffer = nullptr
 
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 >::iterator

iterator for the circular_queue class.

Constructor & Destructor Documentation

◆ iterator()

template<class T , class Alloc = std::allocator<T>>
circular_queue< T, Alloc >::iterator::iterator ( const circular_queue *const  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 iterator's starting offset

Member Function Documentation

◆ operator!=()

template<class T , class Alloc = std::allocator<T>>
bool circular_queue< T, Alloc >::iterator::operator!= ( 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 >::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 >::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>>
iterator circular_queue< T, Alloc >::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>>
iterator& circular_queue< T, Alloc >::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>>
iterator circular_queue< T, Alloc >::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>>
iterator& circular_queue< T, Alloc >::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 >::iterator::operator- ( 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>>
iterator circular_queue< T, Alloc >::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>>
iterator& circular_queue< T, Alloc >::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>>
iterator circular_queue< T, Alloc >::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>>
iterator& circular_queue< T, Alloc >::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 >::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 >::iterator::operator< ( 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 >::iterator::operator<= ( 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 >::iterator::operator== ( 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 >::iterator::operator> ( 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 >::iterator::operator>= ( 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 >::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: