A fixed-capacity circular buffer. More...
#include <containers.hpp>
Public Member Functions | |
| RingBuffer ()=default | |
| constexpr std::size_t | capacity () const |
| Get the maximum capacity. | |
| bool | empty () const |
| Check if the buffer is empty. | |
| bool | full () const |
| Check if the buffer is at capacity. | |
| T | read () |
| Read and remove the oldest value. | |
| std::size_t | size () const |
| Get the number of elements currently stored. | |
| void | write (const T &value) |
| Write a value to the buffer. | |
A fixed-capacity circular buffer.
| T | Element type. |
| N | Maximum capacity (compile-time constant). |
Uses a head/tail index scheme:
\[ \text{next}(i) = (i + 1) \bmod N \]
full() to check before writing.Definition at line 151 of file containers.hpp.
|
default |
|
inlinenodiscardconstexpr |
|
inlinenodiscard |
Check if the buffer is empty.
Definition at line 181 of file containers.hpp.
Referenced by read().
|
inlinenodiscard |
Check if the buffer is at capacity.
Definition at line 184 of file containers.hpp.
Referenced by write().
|
inline |
Read and remove the oldest value.
| BufferUnderflow | if the buffer is empty. |
Definition at line 172 of file containers.hpp.
References empty().
|
inlinenodiscard |
Get the number of elements currently stored.
Definition at line 187 of file containers.hpp.
|
inline |
Write a value to the buffer.
| value | The value to enqueue. |
| BufferOverflow | if the buffer is full. |
Definition at line 160 of file containers.hpp.
References full().