48 using std::runtime_error::runtime_error;
92 void push(
const T& value) {
93 data_.push_back(value);
104 T val = data_.back();
114 [[nodiscard]]
const T&
top()
const {
120 [[nodiscard]]
bool empty()
const {
return data_.empty(); }
123 [[nodiscard]] std::size_t
size()
const {
return data_.size(); }
129 std::vector<T> data_;
150template <
typename T, std::
size_t N>
163 tail_ = (tail_ + 1) % N;
175 head_ = (head_ + 1) % N;
181 [[nodiscard]]
bool empty()
const {
return size_ == 0; }
184 [[nodiscard]]
bool full()
const {
return size_ == N; }
187 [[nodiscard]] std::size_t
size()
const {
return size_; }
190 [[nodiscard]]
constexpr std::size_t
capacity()
const {
return N; }
193 std::array<T, N> buf_{};
194 std::size_t head_ = 0;
195 std::size_t tail_ = 0;
196 std::size_t size_ = 0;
219template <
typename T,
typename E = std::
string>
238 return std::holds_alternative<T>(data_);
249 [[nodiscard]]
const T&
value()
const {
return std::get<T>(data_); }
256 [[nodiscard]]
const E&
error()
const {
return std::get<E>(data_); }
260 explicit Result(T
value) : data_(std::move(
value)) {}
261 Result(ErrTag, E
error) : data_(std::move(
error)) {}
263 std::variant<T, E> data_;
Thrown when a fixed-capacity container is full.
Thrown when popping from an empty container.
Base exception for container errors.
bool is_err() const
Check if this result is an error.
bool is_ok() const
Check if this result is a success.
static Result ok(T value)
Create a success result.
const E & error() const
Unwrap the error.
const T & value() const
Unwrap the success value.
static Result err(E error)
Create an error result.
constexpr std::size_t capacity() const
Get the maximum capacity.
T read()
Read and remove the oldest value.
std::size_t size() const
Get the number of elements currently stored.
bool empty() const
Check if the buffer is empty.
bool full() const
Check if the buffer is at capacity.
void write(const T &value)
Write a value to the buffer.
A simple LIFO stack backed by std::vector.
void clear()
Remove all elements.
void push(const T &value)
Push a value onto the top of the stack.
const T & top() const
Peek at the top element without removing it.
bool empty() const
Check if the stack is empty.
T pop()
Remove and return the top element.
std::size_t size() const
Get the number of elements.