15#ifndef REALTIME_TOOLS__LOCK_FREE_POOLED_QUEUE_HPP_
16#define REALTIME_TOOLS__LOCK_FREE_POOLED_QUEUE_HPP_
23#include "realtime_tools/lock_free_queue.hpp"
43template <
typename T, std::
size_t Capacity>
46 static_assert(Capacity > 0,
"Capacity must be greater than zero");
52 for (std::size_t i = 0; i < Capacity; ++i) {
64 template <
typename Fill>
68 if (!free_.pop(index)) {
72 return filled_.push(index);
87 std::enable_if_t<std::is_same_v<U, T> && std::is_nothrow_move_assignable_v<U>,
int> = 0>
88 [[nodiscard]]
bool push(T && value)
90 return produce([&value](T & slot) { slot = std::move(value); });
99 template <
typename Use>
103 if (!filled_.pop(index)) {
107 return free_.push(index);
119 std::enable_if_t<std::is_same_v<U, T> && std::is_nothrow_move_assignable_v<U>,
int> = 0>
120 [[nodiscard]]
bool pop(T & out)
122 return consume([&out](T & slot) { out = std::move(slot); });
126 bool empty()
const {
return filled_.empty(); }
129 std::array<T, Capacity> slots_;