General Utility Library for C++14  2.7
Public Types | Public Member Functions | Protected Attributes | Friends | List of all members
gul14::SlidingBuffer< ElementT, fixed_capacity, Container >::SlidingBufferIterator< BufferPointer > Class Template Reference

Detailed Description

template<typename ElementT, std::size_t fixed_capacity = 0u, typename Container = typename std::conditional_t<(fixed_capacity >= 1u), std::array<ElementT, fixed_capacity>, std::vector<ElementT>>>
template<typename BufferPointer>
class gul14::SlidingBuffer< ElementT, fixed_capacity, Container >::SlidingBufferIterator< BufferPointer >

Iterator of the SlidingBuffer container.

This is a random access iterator.

Invalidation
An iterator is considered invalid if at least one of these conditions is true:
  • it can not be safely dereferenced (implementation dependent or undefined behavior)
  • it points to junk data
  • it does not point to the element which it is supposed to point to
Depending on what supposed means two specifications can be given:
  1. Iterator is supposed to point to a specific logical position/index in the buffer
  2. Iterator is supposed to point to a specific value held in the buffer
It has the following guarantees for case 1:
It has the following guarantees for case 2:
  • No invalidation on any read
  • All iterators invalidated by push_front()
  • All iterators invalidated by push_back() after the container is filled
  • Only end() invalidated on size increase by push_back()
  • All iterators invalidated on size change

The SlidingBufferIterator represents a logical index in the SlidingBuffer. In other words, the iterator does not "follow" the sliding data when push_back() or push_front() are used.

Template Parameters
BufferPointerType of the pointer used to access the SlidingBuffer
Since
GUL version 2.0, SlidingBufferIterator fulfills the requirements of a LegacyRandomAccessIterator. In previous versions, it only fulfilled the requirements of a LegacyBidirectionalIterator.

#include <SlidingBuffer.h>

Public Types

using iterator_category = std::random_access_iterator_tag
 Defines the category of the iterator.
 
using value_type = ElementT
 The type "pointed to" by the iterator.
 
using difference_type = std::ptrdiff_t
 Distance between iterators is represented as this type.
 
using pointer = value_type *
 This type represents a pointer-to-value_type.
 
using reference = value_type &
 This type represents a reference-to-value_type.
 

Public Member Functions

 SlidingBufferIterator (BufferPointer buff, size_type num=0) noexcept
 Create an iterator pointing into a SlidingBuffer. More...
 
auto operator++ () noexcept -> SlidingBufferIterator &
 Pre-increment iterator by one position.
 
auto operator++ (int) noexcept -> SlidingBufferIterator
 Post-increment iterator by one position.
 
auto operator+= (difference_type d) noexcept -> SlidingBufferIterator &
 Increase iterator by a given number of positions.
 
auto operator-- () noexcept -> SlidingBufferIterator &
 Pre-decrement iterator by one position.
 
auto operator-- (int) noexcept -> SlidingBufferIterator
 Post-decrement iterator by one position.
 
auto operator-= (difference_type d) noexcept -> SlidingBufferIterator &
 Decrease iterator by a given number of positions.
 
auto operator* () const noexcept -> typename std::conditional_t< std::is_const< std::remove_pointer_t< BufferPointer >>::value, const_reference, reference >
 Access element pointed to by the iterator.
 
auto operator-> () const noexcept -> typename std::conditional_t< std::is_const< std::remove_pointer_t< BufferPointer >>::value, const_pointer, pointer >
 Access member of element pointed to by the iterator.
 
auto operator[] (difference_type offs) noexcept -> typename std::conditional_t< std::is_const< std::remove_pointer_t< BufferPointer >>::value, const_reference, reference >
 Dereference the iterator at a certain index offset.
 

Protected Attributes

size_type position_ { 0 }
 This is the logical index we are currently pointing at.
 

Friends

auto operator+ (const SlidingBufferIterator &it, difference_type d) noexcept -> SlidingBufferIterator
 Add an integer to an iterator.
 
auto operator+ (difference_type d, const SlidingBufferIterator &it) noexcept -> SlidingBufferIterator
 Add an integer and an iterator.
 
auto operator- (const SlidingBufferIterator &it, difference_type d) noexcept -> SlidingBufferIterator
 Subtract an integer from an iterator.
 
auto operator- (const SlidingBufferIterator &lhs, const SlidingBufferIterator &rhs) noexcept -> difference_type
 Subtract two iterators.
 
auto operator== (const SlidingBufferIterator &lhs, const SlidingBufferIterator &rhs) noexcept -> bool
 Compare two iterators for equality. More...
 
auto operator!= (const SlidingBufferIterator &lhs, const SlidingBufferIterator &rhs) noexcept -> bool
 Compare two iterators for inequality. More...
 
auto operator> (const SlidingBufferIterator &lhs, const SlidingBufferIterator &rhs) noexcept -> bool
 Determine if the left iterator refers to a greater position than the right one.
 
auto operator< (const SlidingBufferIterator &lhs, const SlidingBufferIterator &rhs) noexcept -> bool
 Determine if the left iterator refers to a lower position than the right one.
 
auto operator>= (const SlidingBufferIterator &lhs, const SlidingBufferIterator &rhs) noexcept -> bool
 Determine if the left iterator refers to position that is greater than or equal to than the right one.
 
auto operator<= (const SlidingBufferIterator &lhs, const SlidingBufferIterator &rhs) noexcept -> bool
 Determine if the left iterator refers to a position that is less than or equal to than the right one.
 

Constructor & Destructor Documentation

◆ SlidingBufferIterator()

template<typename ElementT , std::size_t fixed_capacity = 0u, typename Container = typename std::conditional_t<(fixed_capacity >= 1u), std::array<ElementT, fixed_capacity>, std::vector<ElementT>>>
template<typename BufferPointer >
gul14::SlidingBuffer< ElementT, fixed_capacity, Container >::SlidingBufferIterator< BufferPointer >::SlidingBufferIterator ( BufferPointer  buff,
size_type  num = 0 
)
inlineexplicitnoexcept

Create an iterator pointing into a SlidingBuffer.

Parameters
buffReference to the SlidingBuffer the iterator points into.
numIndex of the element the iterator points to.

Friends And Related Function Documentation

◆ operator!=

template<typename ElementT , std::size_t fixed_capacity = 0u, typename Container = typename std::conditional_t<(fixed_capacity >= 1u), std::array<ElementT, fixed_capacity>, std::vector<ElementT>>>
template<typename BufferPointer >
auto operator!= ( const SlidingBufferIterator< BufferPointer > &  lhs,
const SlidingBufferIterator< BufferPointer > &  rhs 
) -> bool
friend

Compare two iterators for inequality.

Both iterators must be from the same container, or the result is undefined.

◆ operator==

template<typename ElementT , std::size_t fixed_capacity = 0u, typename Container = typename std::conditional_t<(fixed_capacity >= 1u), std::array<ElementT, fixed_capacity>, std::vector<ElementT>>>
template<typename BufferPointer >
auto operator== ( const SlidingBufferIterator< BufferPointer > &  lhs,
const SlidingBufferIterator< BufferPointer > &  rhs 
) -> bool
friend

Compare two iterators for equality.

Both iterators must be from the same container, or the result is undefined.


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