Implement custom barebones circular buffer

This commit is contained in:
GHOSCHT 2023-03-25 18:09:47 +01:00
parent 3ff75471f6
commit e76f9e8d93

View file

@ -0,0 +1,21 @@
#pragma once
#include <Arduino.h>
#include <etl/array.h>
namespace util {
template <typename T, size_t size> class CircularBuffer {
public:
T &peek() { return buffer[index]; }
/// @brief Warning: Does not deconstruct entry! If necessary use
/// etl::circular_buffer instead!
T &pop() {
return buffer[index];
index = (index + 1) % buffer.size();
}
private:
etl::array<T, size> buffer;
size_t index;
};
} // namespace util