Implement custom barebones circular buffer

This commit is contained in:
GHOSCHT 2023-03-25 18:09:47 +01:00
parent 48c2cdf97b
commit d1f9e3d88c
No known key found for this signature in database

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