|
| ring_buffer () noexcept=default |
| Default constructor.
|
| ring_buffer (ring_buffer const &rhs) noexcept(std::is_nothrow_copy_constructible_v< value_type >) |
| Copy constructor.
|
ring_buffer & | operator= (ring_buffer const &rhs) noexcept(std::is_nothrow_copy_constructible_v< value_type >) |
| Copy assignment operator.
|
template<typename U> |
void | push_back (U &&value) |
| Add an element to the back of the buffer.
|
void | pop_front () noexcept |
| Remove the oldest element from the buffer.
|
reference | back () noexcept |
| Access the newest element in the buffer.
|
const_reference | back () const noexcept |
| Access the newest element in the buffer (const version)
|
reference | front () noexcept |
| Access the oldest element in the buffer.
|
const_reference | front () const noexcept |
| Access the oldest element in the buffer (const version)
|
reference | operator[] (size_type index) noexcept |
| Access an element by index.
|
const_reference | operator[] (size_type index) const noexcept |
| Access an element by index (const version)
|
iterator | begin () noexcept |
| Get an iterator to the first element.
|
iterator | end () noexcept |
| Get an iterator to the end of the buffer.
|
const_iterator | cbegin () const noexcept |
| Get a const iterator to the first element.
|
const_iterator | cend () const noexcept |
| Get a const iterator to the end of the buffer.
|
bool | empty () const noexcept |
| Check if the buffer is empty.
|
bool | full () const noexcept |
| Check if the buffer is full.
|
size_type | capacity () const noexcept |
| Get the capacity of the buffer.
|
void | clear () noexcept |
| Clear all elements from the buffer.
|
| ~ring_buffer () |
| Destructor.
|
template<typename T, size_t N, bool Overwrite>
class qb::ring_buffer< T, N, Overwrite >
A fixed-size ring buffer (circular buffer) implementation.
- Template Parameters
-
T | The type of elements stored in the ring buffer |
N | The capacity of the ring buffer |
Overwrite | Whether to overwrite old elements when the buffer is full (defaults to true) |
Ring buffer is a circular data structure with a fixed size that can efficiently add and remove elements from either end. When the buffer is full, new elements either overwrite the oldest ones (if Overwrite=true) or are discarded (if Overwrite=false).
- Template Parameters
-
T | The type of elements stored in the ring buffer |
N | The capacity of the ring buffer |
Overwrite | Whether to overwrite old elements when the buffer is full (defaults to true) |
template<typename T, size_t N, bool Overwrite>
template<typename U>
Add an element to the back of the buffer.
If the buffer is full and Overwrite is true, the oldest element will be overwritten. If the buffer is full and Overwrite is false, the element will be discarded.
- Template Parameters
-
U | Type of the value to add |
- Parameters
-