Cbeam
|
A template class representing a circular buffer. More...
#include <circular_buffer.hpp>
Public Types | |
using | value_type = T |
using | size_type = std::size_t |
using | reference = value_type& |
using | const_reference = const value_type& |
using | iterator = typename std::array<T, S>::iterator |
using | const_iterator = typename std::array<T, S>::const_iterator |
Public Member Functions | |
circular_buffer ()=default | |
Default constructor. | |
auto | begin () noexcept |
Gets an iterator to the beginning of the buffer. | |
auto | end () noexcept |
Gets an iterator to the end of the buffer. | |
std::size_t | size () const |
Gets the number of elements in the buffer. | |
std::size_t | max_size () const |
Gets the maximum number of elements the buffer can hold. | |
void | push_back (const T &t) |
Adds an element to the back of the buffer. | |
bool | empty () const noexcept |
void | clear () noexcept |
template<typename... Args> | |
void | emplace_back (Args &&... args) |
Adds an element to the back of the buffer. | |
reference | at (size_type pos) |
Accesses the element at specified location with bounds checking. | |
const_reference | at (size_type pos) const |
Accesses the element at specified location with bounds checking (const version). | |
reference | operator[] (size_type pos) |
Accesses the element at specified location without bounds checking. | |
const_reference | operator[] (size_type pos) const |
Accesses the element at specified location without bounds checking (const version). | |
reference | front () |
Accesses the first element in the buffer. | |
const_reference | front () const |
Accesses the first element in the buffer (const version). | |
reference | back () |
Accesses the last element in the buffer. | |
const_reference | back () const |
Accesses the last element in the buffer (const version). | |
A template class representing a circular buffer.
This class implements a circular buffer of fixed size. It provides basic iterator access and allows elements to be added to the back, automatically overwriting the oldest elements once the buffer is full.
T | The type of elements in the buffer. |
S | The fixed size of the buffer. |
using cbeam::container::circular_buffer< T, S >::const_iterator = typename std::array<T, S>::const_iterator |
using cbeam::container::circular_buffer< T, S >::const_reference = const value_type& |
using cbeam::container::circular_buffer< T, S >::iterator = typename std::array<T, S>::iterator |
using cbeam::container::circular_buffer< T, S >::reference = value_type& |
using cbeam::container::circular_buffer< T, S >::size_type = std::size_t |
using cbeam::container::circular_buffer< T, S >::value_type = T |
|
default |
Default constructor.
|
inline |
Accesses the element at specified location with bounds checking.
pos | The position of the element to return. |
cbeam::error::out_of_range | if pos is out of range. |
|
inline |
Accesses the element at specified location with bounds checking (const version).
pos | The position of the element to return. |
cbeam::error::out_of_range | if pos is out of range. |
|
inline |
Accesses the last element in the buffer.
|
inline |
Accesses the last element in the buffer (const version).
|
inlinenoexcept |
Gets an iterator to the beginning of the buffer.
|
inlinenoexcept |
|
inline |
Adds an element to the back of the buffer.
This method adds a new element to the back of the buffer by moving it, potentially overwriting the oldest element if the buffer is full.
args | The element to add. |
|
inlinenoexcept |
|
inlinenoexcept |
Gets an iterator to the end of the buffer.
|
inline |
Accesses the first element in the buffer.
|
inline |
Accesses the first element in the buffer (const version).
|
inline |
Gets the maximum number of elements the buffer can hold.
|
inline |
Accesses the element at specified location without bounds checking.
pos | The position of the element to return. |
|
inline |
Accesses the element at specified location without bounds checking (const version).
pos | The position of the element to return. |
|
inline |
Adds an element to the back of the buffer.
This method adds a new element to the back of the buffer, potentially overwriting the oldest element if the buffer is full.
t | The element to add. |
|
inline |
Gets the number of elements in the buffer.