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; }
32 if (currentStoredEvents >= MaxElements)
37 _queueData[currentStoredEvents] = e;
39 currentStoredEvents++;
47 Optional(T val) : _hasValue(
true), _value(val) {}
48 bool has_value()
const {
return _hasValue; }
49 T value()
const {
return _hasValue ? _value : T(); }
52 bool _hasValue =
false;
61 if (currentStoredEvents <= 0)
65 const Element toReturn = _queueData[0];
68 for (
size_t i = 1; i < currentStoredEvents; i++)
70 _queueData[i - 1] = _queueData[i];
73 currentStoredEvents -= 1;
78 size_t currentStoredEvents = 0;
79 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:45
bool enqueue(const T &element)
Add an element to the queue.
Definition: queue.h:30
Optional dequeue()
Remove and return the first element from the queue, or nothing.
Definition: queue.h:59