14template<
typename T,
size_t MaxElements = 10>
struct Queue
16 static_assert(MaxElements > 1,
"Queue: cannot define a one or less elements queue");
24 bool has_elements()
const {
return currentStoredEvents > 0; }
26 size_t get_stored_item_count()
const {
return currentStoredEvents; }
34 if (currentStoredEvents >= MaxElements)
39 _queueData[currentStoredEvents] = e;
41 currentStoredEvents++;
49 Optional(T val) : _hasValue(
true), _value(val) {}
50 bool has_value()
const {
return _hasValue; }
51 T value()
const {
return _hasValue ? _value : T(); }
54 bool _hasValue =
false;
63 if (currentStoredEvents <= 0)
67 const Element toReturn = _queueData[0];
70 for (
size_t i = 1; i < currentStoredEvents; i++)
72 _queueData[i - 1] = _queueData[i];
75 currentStoredEvents -= 1;
80 size_t currentStoredEvents = 0;
81 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:47
bool enqueue(const T &element)
Add an element to the queue.
Definition: queue.h:32
Optional dequeue()
Remove and return the first element from the queue, or nothing.
Definition: queue.h:61