15template<
typename T,
size_t MaxElements = 10>
struct Queue
17 static_assert(MaxElements > 1,
"Queue: cannot define a one or less elements queue");
25 bool has_elements()
const {
return currentStoredEvents > 0; }
33 if (currentStoredEvents >= MaxElements)
38 _queueData[currentStoredEvents] = e;
40 currentStoredEvents++;
48 Optional(T val) : _hasValue(
true), _value(val) {}
49 bool has_value()
const {
return _hasValue; }
50 T value()
const {
return _hasValue ? _value : T(); }
53 bool _hasValue =
false;
62 if (currentStoredEvents <= 0)
66 const Element toReturn = _queueData[0];
69 for (
size_t i = 1; i < currentStoredEvents; i++)
71 _queueData[i - 1] = _queueData[i];
74 currentStoredEvents -= 1;
79 size_t currentStoredEvents = 0;
80 std::array<Element, MaxElements> _queueData;
Program scope.
Definition: control_fixed_modes.hpp:12
We need a fake optional, has the core is compiled in C++11.
Definition: queue.h:46
Optional dequeue()
Remove and return the first element from the queue, or nothing.
Definition: queue.h:60
bool enqueue(const T &element)
Add an element to the queue.
Definition: queue.h:31