General Utility Library for C++14  2.12
Public Types | Public Member Functions | List of all members
gul14::SlidingBufferExposed< ElementT, fixed_capacity, Container > 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>>>
class gul14::SlidingBufferExposed< ElementT, fixed_capacity, Container >

A variant of SlidingBuffer that exposes the underlying container through its iterator interface.

The direct iterator access to the underlying buffer offers a performance benefit in some cases. However, it comes at the cost of limited flexibility. SlidingBufferExposed behaves identically to SlidingBuffer except for the differences listed here:

Iterator invalidation
It is only specified that all elements can be visited by traversing from begin() to end().
If the size changes (push_front(), push_back(), resize(), reserve()) all iterators are invalidated.
Furthermore, when both push_front() and push_back() have been used on a single SlidingBufferExposed, the whole capacity of the buffer is visited by traversing from begin() to end(), including possible 'unfilled' (default constructed) elements in the unused slots.
See begin() and end() for more details.
Member types:
iterator container_type::iterator
const_iterator container_type::const_iterator
reverse_iterator container_type::reverse_iterator
const_reverse_iterator container_type::const_reverse_iterator
Member functions:
Iterators:
begin, cbegin Returns an iterator to the first element of the container
end, cend Returns an iterator to the element following the last element of the container
rbegin, crbegin Returns an iterator to the first element of the reversed container
rend, crend Returns an iterator to the element following the last element of the reversed container
Non-member functions:
operator<< Dump the raw data of the buffer to an ostream
typename Container::reverse_iterator reverse_iterator
Iterator to an element in reversed container.
Definition: SlidingBuffer.h:1084
auto begin() noexcept -> iterator
Return an iterator to the first occupied element of the underlying container.
Definition: SlidingBuffer.h:1121
auto cend() const noexcept -> const_iterator
Return a constant iterator to the element following the last element in the used space of the underly...
Definition: SlidingBuffer.h:1186
typename Container::const_iterator const_iterator
Iterator to a const element.
Definition: SlidingBuffer.h:1082
auto cbegin() const noexcept -> const_iterator
Return a constant iterator to the first occupied element of the underlying container.
Definition: SlidingBuffer.h:1141
auto rbegin() noexcept -> reverse_iterator
Return a reverse iterator to the first used element of the reversed underlying container.
Definition: SlidingBuffer.h:1202
auto end() noexcept -> iterator
Return an iterator to the element following the last element in the used space of the underlying cont...
Definition: SlidingBuffer.h:1166
auto crend() const noexcept -> const_reverse_iterator
Return a constant iterator to the last element of the reversed underlying container.
Definition: SlidingBuffer.h:1236
auto rend() noexcept -> reverse_iterator
Return an iterator to the last element of the reversed underlying container.
Definition: SlidingBuffer.h:1225
typename Container::iterator iterator
Iterator to an element.
Definition: SlidingBuffer.h:1080
auto crbegin() const noexcept -> const_reverse_iterator
Return a constant reverse iterator to the first used element of the reversed underlying container.
Definition: SlidingBuffer.h:1215
typename Container::const_reverse_iterator const_reverse_iterator
Iterator to a const element in reversed container.
Definition: SlidingBuffer.h:1086
Template Parameters
ElementTType of elements in the buffer
fixed_capacityMaximum number of elements in the buffer (i.e. capacity), zero if unspecified/dynamic
ContainerType of the underlying container, usually not specified

#include <SlidingBuffer.h>

Inherits SlidingBuffer< ElementT, 0u, typename std::conditional_t<(0u >=1u), std::array< ElementT, 0u >, std::vector< ElementT >> >.

Public Types

using iterator = typename Container::iterator
 Iterator to an element.
 
using const_iterator = typename Container::const_iterator
 Iterator to a const element.
 
using reverse_iterator = typename Container::reverse_iterator
 Iterator to an element in reversed container.
 
using const_reverse_iterator = typename Container::const_reverse_iterator
 Iterator to a const element in reversed container.
 

Public Member Functions

auto begin () noexcept -> iterator
 Return an iterator to the first occupied element of the underlying container. More...
 
auto begin () const noexcept -> const_iterator
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
auto cbegin () const noexcept -> const_iterator
 Return a constant iterator to the first occupied element of the underlying container. More...
 
auto end () noexcept -> iterator
 Return an iterator to the element following the last element in the used space of the underlying container. More...
 
auto end () const noexcept -> const_iterator
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
auto cend () const noexcept -> const_iterator
 Return a constant iterator to the element following the last element in the used space of the underlying container. More...
 
auto rbegin () noexcept -> reverse_iterator
 Return a reverse iterator to the first used element of the reversed underlying container. More...
 
auto crbegin () const noexcept -> const_reverse_iterator
 Return a constant reverse iterator to the first used element of the reversed underlying container. More...
 
auto rend () noexcept -> reverse_iterator
 Return an iterator to the last element of the reversed underlying container. More...
 
auto crend () const noexcept -> const_reverse_iterator
 Return a constant iterator to the last element of the reversed underlying container. More...
 
auto resize (size_type new_capacity, ShrinkBehavior shrink_behavior=ShrinkBehavior::keep_front_elements) -> void
 Resize the container. More...
 
auto reserve (size_type size, ShrinkBehavior shrink_behavior=ShrinkBehavior::keep_front_elements) -> void
 Resize the container (identical to resize()). More...
 

Member Function Documentation

◆ begin()

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>>>
auto gul14::SlidingBufferExposed< ElementT, fixed_capacity, Container >::begin ( ) -> iterator
inlinenoexcept

Return an iterator to the first occupied element of the underlying container.

The iterator accesses the underlying container in its native order. If the elements are stored in contiguous fashion (if only push_back() or only push_front() were used to add them), begin() returns an iterator pointing to the first occupied element. If the elements are non-contiguous (which can happen if push_front() and push_back() were mixed and the buffer is not yet full), begin() simply points to the start of the container and the range [begin(), end()] may enclose default-constructed elements.

If the container is empty, the returned iterator is equal to end().

◆ cbegin()

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>>>
auto gul14::SlidingBufferExposed< ElementT, fixed_capacity, Container >::cbegin ( ) const -> const_iterator
inlinenoexcept

Return a constant iterator to the first occupied element of the underlying container.

See also
begin() for details.

◆ cend()

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>>>
auto gul14::SlidingBufferExposed< ElementT, fixed_capacity, Container >::cend ( ) const -> const_iterator
inlinenoexcept

Return a constant iterator to the element following the last element in the used space of the underlying container.

See also
end() for details.

◆ crbegin()

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>>>
auto gul14::SlidingBufferExposed< ElementT, fixed_capacity, Container >::crbegin ( ) const -> const_reverse_iterator
inlinenoexcept

Return a constant reverse iterator to the first used element of the reversed underlying container.

It corresponds to the last element of the non-reversed container.

See begin() and end() for details on what is accessed.

◆ crend()

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>>>
auto gul14::SlidingBufferExposed< ElementT, fixed_capacity, Container >::crend ( ) const -> const_reverse_iterator
inlinenoexcept

Return a constant iterator to the last element of the reversed underlying container.

See begin() and end() for details on what is accessed.

◆ end()

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>>>
auto gul14::SlidingBufferExposed< ElementT, fixed_capacity, Container >::end ( ) -> iterator
inlinenoexcept

Return an iterator to the element following the last element in the used space of the underlying container.

If the container is empty, the returned iterator is equal to begin().

This element acts as a placeholder; attempting to access it results in undefined behavior.

The iterator accesses the underlying container in its native order. If the elements are stored in contiguous fashion (if only push_back() or only push_front() were used to add them), end() returns an iterator pointing past the last occupied element. If the elements are non-contiguous (which can happen if push_front() and push_back() were mixed and the buffer is not yet full), end() simply points past the last element of the container and the range [begin(), end()] may enclose default-constructed elements.

◆ rbegin()

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>>>
auto gul14::SlidingBufferExposed< ElementT, fixed_capacity, Container >::rbegin ( ) -> reverse_iterator
inlinenoexcept

Return a reverse iterator to the first used element of the reversed underlying container.

It corresponds to the last element of the non-reversed container.

See begin() and end() for details on what is accessed.

◆ rend()

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>>>
auto gul14::SlidingBufferExposed< ElementT, fixed_capacity, Container >::rend ( ) -> reverse_iterator
inlinenoexcept

Return an iterator to the last element of the reversed underlying container.

See begin() and end() for details on what is accessed.

◆ reserve()

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>>>
auto gul14::SlidingBufferExposed< ElementT, fixed_capacity, Container >::reserve ( size_type  size,
ShrinkBehavior  shrink_behavior = ShrinkBehavior::keep_front_elements 
) -> void
inline

Resize the container (identical to resize()).

See also
resize()

◆ resize()

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>>>
auto gul14::SlidingBufferExposed< ElementT, fixed_capacity, Container >::resize ( size_type  new_capacity,
ShrinkBehavior  shrink_behavior = ShrinkBehavior::keep_front_elements 
) -> void
inline

Resize the container.

Only possible if the underlying container is a std::vector.

  • Shrinking: The excess elements are dropped according to shrink_behavior.
  • Growing: The capacity changes, but the (used) size does not. It will grow gradually when elements are pushed, as in the startup phase.
Parameters
new_capacityNew capacity (maximum size) of the sliding buffer.
shrink_behaviorSpecify the ShrinkBehavior.
Note
Think twice when shrinking the buffer: The default shrink_behavior (ShrinkBehavior::keep_front_elements) is transparent only if exclusively push_front() was used to add elements. If push_back() was used, resize() without a second argument discards the most recent elements; in these cases, make sure to specify ShrinkBehavior::keep_back_elements.

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