An implementation of generic, non-threadsafe circular array. More...
#include <circular_array.hpp>
Public Types | |
using | allocator_type = void |
Allocator type of the array (required in range-v3 10.0). More... | |
using | const_iterator = IndexingIterator< const CircularArray< T, N, F > > |
Constant iterator type of the array. More... | |
using | const_pointer = const value_type * |
Constant value pointer type of the arra.y. More... | |
using | const_reference = const value_type & |
Constant value reference type of the array. More... | |
using | const_reverse_iterator = std::reverse_iterator< const_iterator > |
Constant reverse iterator type of the array. More... | |
using | difference_type = std::ptrdiff_t |
Size difference type of the array. More... | |
using | iterator = IndexingIterator< CircularArray< T, N, F > > |
Iterator type of the array. More... | |
using | pointer = value_type * |
Value pointer type of the array. More... | |
using | reference = value_type & |
Value reference type of the array. More... | |
using | reverse_iterator = std::reverse_iterator< iterator > |
Reverse iterator type of the array. More... | |
using | size_type = std::size_t |
Size type of the array. More... | |
using | value_type = T |
Value type of the array. More... | |
Public Member Functions | |
constexpr reference | at (size_type index) |
Returns a reference to the array value at the given index . More... | |
constexpr const_reference | at (size_type index) const |
Returns a constant reference to the array value at the given index . More... | |
constexpr const_reference | back () const noexcept |
Returns a constant reference to the value at the back of the array. More... | |
constexpr reference | back () noexcept |
Returns a reference to the value at the back of the array. More... | |
constexpr const_iterator | begin () const noexcept |
Returns a constant iterator pointing to the front of the array. More... | |
constexpr iterator | begin () noexcept |
Returns an iterator pointing to the front of the array. More... | |
constexpr const_iterator | cbegin () const noexcept |
Returns a constant iterator pointing to the front of the array. More... | |
constexpr const_iterator | cend () const noexcept |
Returns a constant iterator pointing past the back of the array. More... | |
CircularArray ()=default | |
Default constructor. More... | |
template<typename Iterator , typename Sentinel , typename = std::enable_if_t<std::is_same_v<T, typename std::iterator_traits<Iterator>::value_type>>> | |
CircularArray (Iterator first, Sentinel last) | |
Constructs array from a pair of iterators. More... | |
template<std::size_t M> | |
CircularArray (T(&&data)[M]) | |
Constructs array from an aggregate. More... | |
void | clear () noexcept |
Clears array. More... | |
constexpr const_reverse_iterator | crbegin () const noexcept |
Returns a constant reverse iterator pointing to the back of the array. More... | |
constexpr const_reverse_iterator | crend () const noexcept |
Returns a constant reverse iterator pointing past the front of the array. More... | |
constexpr const T * | data () const noexcept |
Returns a constant pointer to the underlying array data. More... | |
constexpr T * | data () noexcept |
Returns a pointer to the underlying array data. More... | |
constexpr size_type | effective_size () const noexcept |
Returns the effective array size. More... | |
constexpr bool | empty () const noexcept |
Returns true if the array is empty, false otherwise. More... | |
constexpr const_iterator | end () const noexcept |
Returns a constant iterator pointing past the back of the array. More... | |
constexpr iterator | end () noexcept |
Returns an iterator pointing past the back of the array. More... | |
void | fill (const T &value) |
Fills array to its maximum size with a given value . More... | |
constexpr const_reference | front () const noexcept |
Returns a constant reference to the value at the front of the array. More... | |
constexpr reference | front () noexcept |
Returns a reference to the value at the front of the array. More... | |
constexpr bool | full () const noexcept |
Returns true if the array is full, false otherwise. More... | |
constexpr size_type | max_size () const noexcept |
Returns the maximum array size. More... | |
constexpr const_reference | operator[] (size_type index) const noexcept |
Returns a constant reference to the array value at the given index . More... | |
constexpr reference | operator[] (size_type index) noexcept |
Returns a reference to the array value at the given index . More... | |
template<bool Enabled = (F & CircularArrayFeatureFlags::kLayoutReversal)> | |
std::enable_if_t< Enabled > | pop_back () noexcept |
Pops a value from the back of the array. More... | |
template<bool Enabled = !(F & CircularArrayFeatureFlags::kLayoutReversal)> | |
std::enable_if_t< Enabled > | pop_front () noexcept |
Pops a value from the front of the array. More... | |
template<bool Enabled = !(F & CircularArrayFeatureFlags::kLayoutReversal)> | |
std::enable_if_t< Enabled > | push_back (value_type value) |
Pushes a value to the back of the array. More... | |
template<bool Enabled = (F & CircularArrayFeatureFlags::kLayoutReversal)> | |
std::enable_if_t< Enabled > | push_front (value_type value) |
Pushes a value at the front of the array. More... | |
constexpr const_reverse_iterator | rbegin () const noexcept |
Returns a constant reverse iterator pointing to the back of the array. More... | |
constexpr reverse_iterator | rbegin () noexcept |
Returns a reverse iterator pointing to the back of the array. More... | |
constexpr const_reverse_iterator | rend () const noexcept |
Returns a constant reverse iterator pointing past the front of the array. More... | |
constexpr reverse_iterator | rend () noexcept |
Returns a reverse iterator pointing past the front of the array. More... | |
constexpr size_type | size () const noexcept |
Returns the current array size. More... | |
template<CircularArrayFeatureFlags G> | |
void | swap (CircularArray< T, N, G > &other) noexcept(std::is_nothrow_swappable_v< T >) |
Swaps array with another. More... | |
Private Member Functions | |
constexpr size_type | head_index () const noexcept |
Private Attributes | |
std::array< T, N > | data_ |
size_type | size_ {0U} |
size_type | tail_index_ {0U} |
Friends | |
template<typename U , std::size_t M, CircularArrayFeatureFlags G> | |
class | CircularArray |
An implementation of generic, non-threadsafe circular array.
Modelled after std::array
. Its maximum size is fixed at compile-time. Most operations are O(1) but for a few that exhibit worse case O(N) (not considering the complexity of move-construction and move-assignment of array elements of type T). Additionally, it features optional indexing reversal (making it a LIFO rather than a FIFO data structure), optional back value extrapolation for constant read accesses, and optional rollover on write accesses (i.e. overwriting the oldest value when pushing to an array instance that is full).
T | Element type. It must be default constructible, move constructible, and move assignable. |
N | Maximum size. It must be a positive integer. |
F | Array feature flags, to enable optional functionality. It defaults to none. |
Definition at line 76 of file circular_array.hpp.
using beluga::CircularArray< T, N, F >::allocator_type = void |
Allocator type of the array (required in range-v3 10.0).
Definition at line 94 of file circular_array.hpp.
using beluga::CircularArray< T, N, F >::const_iterator = IndexingIterator<const CircularArray<T, N, F> > |
Constant iterator type of the array.
Definition at line 99 of file circular_array.hpp.
using beluga::CircularArray< T, N, F >::const_pointer = const value_type* |
Constant value pointer type of the arra.y.
Definition at line 91 of file circular_array.hpp.
using beluga::CircularArray< T, N, F >::const_reference = const value_type& |
Constant value reference type of the array.
Definition at line 87 of file circular_array.hpp.
using beluga::CircularArray< T, N, F >::const_reverse_iterator = std::reverse_iterator<const_iterator> |
Constant reverse iterator type of the array.
Definition at line 103 of file circular_array.hpp.
using beluga::CircularArray< T, N, F >::difference_type = std::ptrdiff_t |
Size difference type of the array.
Definition at line 83 of file circular_array.hpp.
using beluga::CircularArray< T, N, F >::iterator = IndexingIterator<CircularArray<T, N, F> > |
Iterator type of the array.
Definition at line 97 of file circular_array.hpp.
using beluga::CircularArray< T, N, F >::pointer = value_type* |
Value pointer type of the array.
Definition at line 89 of file circular_array.hpp.
using beluga::CircularArray< T, N, F >::reference = value_type& |
Value reference type of the array.
Definition at line 85 of file circular_array.hpp.
using beluga::CircularArray< T, N, F >::reverse_iterator = std::reverse_iterator<iterator> |
Reverse iterator type of the array.
Definition at line 101 of file circular_array.hpp.
using beluga::CircularArray< T, N, F >::size_type = std::size_t |
Size type of the array.
Definition at line 81 of file circular_array.hpp.
using beluga::CircularArray< T, N, F >::value_type = T |
Value type of the array.
Definition at line 79 of file circular_array.hpp.
|
default |
Default constructor.
Array will be functionally empty but storage will be default initialized.
|
inline |
Constructs array from a pair of iterators.
Functionally equivalent to repeated push_back() operations or push_front() operations in reverse if the layout reversal feature is enabled. That is, both range and array layouts match.
first | Iterator to the beginning of a range. |
last | Sentinel for the end of a range. |
std::length_error | If the range does not fit in the array (and the rollover on write feature is not enabled). |
Definition at line 126 of file circular_array.hpp.
|
inlineexplicit |
Constructs array from an aggregate.
Functionally equivalent to repeated push_back() operations or push_front() operations in reverse if the layout reversal feature is enabled. That is, both aggregate and array layouts match.
data | Aggregate data to initialize the array with. Its size must be in the [1, N] interval. |
Definition at line 163 of file circular_array.hpp.
|
inlineconstexpr |
Returns a reference to the array value at the given index
.
std::out_of_range | If index is past the array's effective size. |
Definition at line 320 of file circular_array.hpp.
|
inlineconstexpr |
Returns a constant reference to the array value at the given index
.
std::out_of_range | If index is past the array effective size. |
Definition at line 331 of file circular_array.hpp.
|
inlineconstexprnoexcept |
Returns a constant reference to the value at the back of the array.
Behavior is undefined when accessing the back of an empty array.
Definition at line 284 of file circular_array.hpp.
|
inlineconstexprnoexcept |
Returns a reference to the value at the back of the array.
Behavior is undefined when accessing the back of an empty array.
Definition at line 273 of file circular_array.hpp.
|
inlineconstexprnoexcept |
Returns a constant iterator pointing to the front of the array.
Definition at line 176 of file circular_array.hpp.
|
inlineconstexprnoexcept |
Returns an iterator pointing to the front of the array.
Definition at line 174 of file circular_array.hpp.
|
inlineconstexprnoexcept |
Returns a constant iterator pointing to the front of the array.
Definition at line 178 of file circular_array.hpp.
|
inlineconstexprnoexcept |
Returns a constant iterator pointing past the back of the array.
Definition at line 185 of file circular_array.hpp.
|
inlinenoexcept |
|
inlineconstexprnoexcept |
Returns a constant reverse iterator pointing to the back of the array.
Definition at line 192 of file circular_array.hpp.
|
inlineconstexprnoexcept |
Returns a constant reverse iterator pointing past the front of the array.
Definition at line 199 of file circular_array.hpp.
|
inlineconstexprnoexcept |
Returns a constant pointer to the underlying array data.
Note that a circular array does not feature a contiguous layout in memory. Indices and distances between them for the array do not map to its data.
Definition at line 415 of file circular_array.hpp.
|
inlineconstexprnoexcept |
Returns a pointer to the underlying array data.
Note that a circular array does not feature a contiguous layout in memory. Indices and distances between them for the array do not map to its data.
Definition at line 408 of file circular_array.hpp.
|
inlineconstexprnoexcept |
Returns the effective array size.
Nominally, the effective array size is equal to the array size. If the last value extrapolation feature is enabled, however, the effective array size can only be 0 or N, when the array is empty and when the array is non-empty respectively.
Definition at line 436 of file circular_array.hpp.
|
inlineconstexprnoexcept |
Returns true if the array is empty, false otherwise.
Definition at line 421 of file circular_array.hpp.
|
inlineconstexprnoexcept |
Returns a constant iterator pointing past the back of the array.
Definition at line 183 of file circular_array.hpp.
|
inlineconstexprnoexcept |
Returns an iterator pointing past the back of the array.
Definition at line 181 of file circular_array.hpp.
|
inline |
Fills array to its maximum size with a given value
.
Functionally equivalent to repeated push_back() operations or push_front() operations if the layout reversal feature is enabled until the array reaches its maximum size. Existing values are kept. Filling an array that is full is a no-op.
Definition at line 372 of file circular_array.hpp.
|
inlineconstexprnoexcept |
Returns a constant reference to the value at the front of the array.
Behavior is undefined when accessing the front of an empty array.
Definition at line 308 of file circular_array.hpp.
|
inlineconstexprnoexcept |
Returns a reference to the value at the front of the array.
Behavior is undefined when accessing the front of an empty array.
Definition at line 296 of file circular_array.hpp.
|
inlineconstexprnoexcept |
Returns true if the array is full, false otherwise.
Definition at line 418 of file circular_array.hpp.
|
inlineconstexprprivatenoexcept |
Definition at line 446 of file circular_array.hpp.
|
inlineconstexprnoexcept |
Returns the maximum array size.
Definition at line 427 of file circular_array.hpp.
|
inlineconstexprnoexcept |
Returns a constant reference to the array value at the given index
.
Behavior is undefined when index
is greater than or equal to the array effective size.
Definition at line 354 of file circular_array.hpp.
|
inlineconstexprnoexcept |
Returns a reference to the array value at the given index
.
Behavior is undefined when index
is greater than or equal to the array size.
Definition at line 342 of file circular_array.hpp.
|
inlinenoexcept |
Pops a value
from the back of the array.
Only available when the layout reversal feature is enabled. Behavior is undefined when popping from the back of an empty array. No destructors are invoked on the value popped.
Definition at line 254 of file circular_array.hpp.
|
inlinenoexcept |
Pops a value
from the front of the array.
Only available when the layout reversal feature is not enabled. Behavior is undefined when popping from the front of an empty array. No destructors are invoked on the value popped.
Definition at line 265 of file circular_array.hpp.
|
inline |
Pushes a value
to the back of the array.
Only available when the layout reversal feature is not enabled.
std::length_error | If the array is full and the rollover on write feature is not enabled. |
Definition at line 209 of file circular_array.hpp.
|
inline |
Pushes a value
at the front of the array.
Only available when the layout reversal feature is enabled.
std::length_error | If the array is full and the rollover on write feature is not enabled. |
Definition at line 232 of file circular_array.hpp.
|
inlineconstexprnoexcept |
Returns a constant reverse iterator pointing to the back of the array.
Definition at line 190 of file circular_array.hpp.
|
inlineconstexprnoexcept |
Returns a reverse iterator pointing to the back of the array.
Definition at line 188 of file circular_array.hpp.
|
inlineconstexprnoexcept |
Returns a constant reverse iterator pointing past the front of the array.
Definition at line 197 of file circular_array.hpp.
|
inlineconstexprnoexcept |
Returns a reverse iterator pointing past the front of the array.
Definition at line 195 of file circular_array.hpp.
|
inlineconstexprnoexcept |
Returns the current array size.
Definition at line 424 of file circular_array.hpp.
|
inlinenoexcept |
Swaps array with another.
Arrays being swapped may not necessarily have the same features enabled. This is most relevant when arrays differ in layout direction, as swapping two such arrays effectively reverses their elements.
Definition at line 393 of file circular_array.hpp.
|
friend |
Definition at line 401 of file circular_array.hpp.
|
private |
Definition at line 450 of file circular_array.hpp.
|
private |
Definition at line 452 of file circular_array.hpp.
|
private |
Definition at line 451 of file circular_array.hpp.