3#ifndef MSD_CHANNEL_STORAGE_HPP_
4#define MSD_CHANNEL_STORAGE_HPP_
38 template <
typename Type>
41 queue_.push(std::forward<Type>(value));
52 out = std::move(queue_.front());
61 NODISCARD std::size_t
size() const noexcept {
return queue_.size(); }
90 template <
typename Type>
93 vector_.push_back(std::forward<Type>(value));
104 out = std::move(vector_.front());
105 vector_.erase(vector_.begin());
113 NODISCARD std::size_t
size() const noexcept {
return vector_.size(); }
116 std::vector<T> vector_;
126template <
typename T, std::
size_t N>
129 static_assert(N > 0,
"Capacity must be greater than zero.");
145 template <
typename Type>
148 array_[(front_ + size_) % N] = std::forward<Type>(value);
160 out = std::move(array_[front_]);
161 front_ = (front_ + 1) % N;
170 NODISCARD std::size_t
size() const noexcept {
return size_; }
173 std::array<T, N> array_{};
174 std::size_t size_{0};
175 std::size_t front_{0};
181template <
typename T, std::
size_t N>
A fixed-size circular buffer using std::array.
Definition storage.hpp:127
static constexpr std::size_t capacity
The storage capacity.
Definition storage.hpp:136
void pop_front(T &out)
Marks the front element as removed and moves it to the output.
Definition storage.hpp:158
void push_back(Type &&value)
Adds an element to the back of the array.
Definition storage.hpp:146
NODISCARD std::size_t size() const noexcept
Returns the number of elements currently stored.
Definition storage.hpp:170
NODISCARD std::size_t size() const noexcept
Returns the number of elements currently stored.
Definition storage.hpp:61
void push_back(Type &&value)
Adds an element to the back of the queue.
Definition storage.hpp:39
queue_storage(std::size_t)
Constructs the queue storage (parameter ignored, required for interface compatibility).
Definition storage.hpp:30
void pop_front(T &out)
Removes the front element from the queue and moves it to the output.
Definition storage.hpp:50
void push_back(Type &&value)
Adds an element to the back of the vector.
Definition storage.hpp:91
void pop_front(T &out)
Removes the front element from the vector and moves it to the output.
Definition storage.hpp:102
vector_storage(std::size_t capacity)
Constructs a queue storage with a given capacity.
Definition storage.hpp:82
NODISCARD std::size_t size() const noexcept
Returns the number of elements currently stored.
Definition storage.hpp:113
constexpr std::size_t array_storage< T, N >::capacity
Out-of-class definition of array_storage::capacity, required pre-C++17 when the member is odr-used.
Definition storage.hpp:182