Template Class RingBufferIterator

Class Documentation

template<typename T>
class RingBufferIterator

Forward declaration.

RingBufferIterator is the random access iterator class used with the RingBuffer container.

Public Types

using difference_type = ptrdiff_t

Type when taking the difference between two iterators.

using value_type = T

Type of elements pointed to by the iterator.

using pointer = T*

Type to represent a pointer to an element pointed by the iterator.

using reference = T&

Type to represent a reference to an element pointed by the iterator.

using iterator_category = std::random_access_iterator_tag

Category to which the iterator belongs.

Public Functions

inline RingBufferIterator(T *buffer = new T[1](), std::size_t offset = 0, std::size_t capacity = 1)

Constructor.

Parameters
  • buffer – the storage for the ring buffer

  • offset – iterator value used to index the buffer

  • capacity – size (number of elements) of buffer

inline bool operator==(const RingBufferIterator &rhs)

Equal operator.

Parameters

rhs – iterator to compare to

Returns

true if iterators are equal

inline bool operator!=(const RingBufferIterator &rhs)

Not equal operator.

Parameters

rhs – iterator to compare to

Returns

true if iterators are not equal

inline RingBufferIterator &operator++()

Prefix increment operator.

Returns

*this

inline RingBufferIterator operator++(int)

Postfix increment operator.

Returns

Iterator (by value)

inline RingBufferIterator operator+(int amount) const

Addition operator.

Parameters

amount – to add

Returns

Iterator (by value)

inline RingBufferIterator operator-(int amount) const

Subtraction operator.

Parameters

amount – to subtract

Returns

Iterator (by value)

inline RingBufferIterator &operator--()

Prefix decrement operator.

Returns

*this

inline RingBufferIterator operator--(int)

Postfix decrement operator.

Returns

Iterator (by value)

inline std::ptrdiff_t operator-(RingBufferIterator const &rhs) const

Difference operator.

Parameters

rhs – iterator to compare to

Returns

Difference between iterator and rhs (iterator - rhs)

inline RingBufferIterator &operator+=(int amount)

Addition assignment operator.

Parameters

amount – to add to iterator

Returns

Modified iterator (by reference)

inline RingBufferIterator &operator-=(int amount)

Subtraction assignment operator.

Parameters

amount – to subtract from iterator

Returns

Modified iterator (by reference)

inline bool operator<(RingBufferIterator const &rhs) const

Less than operator.

Parameters

rhs – iterator to compare to

Returns

true if iterator is less than rhs (iterator < rhs)

inline bool operator<=(RingBufferIterator const &rhs) const

Less than or equal to operator.

Parameters

rhs – iterator to compare to

Returns

true if iterator is less than or equal to rhs (iterator <= rhs)

inline bool operator>(RingBufferIterator const &rhs) const

Greater than operator.

Parameters

rhs – iterator to compare to

Returns

true if iterator is greater than rhs (iterator > rhs)

inline bool operator>=(RingBufferIterator const &rhs) const

Greater than or equal to operator.

Parameters

rhs – iterator to compare to

Returns

true if iterator is greater than or equal to rhs (iterator >= rhs)

inline T &operator[](int index) const
Parameters

index – of element from iterator

Returns

Element at index (by reference)

inline T &operator*() const
Returns

Element pointed to by iterator (by reference)

inline T *operator->() const
Returns

Address of element pointed to by iterator