1 #ifndef CIRCULARBUFFER_HH
2 #define CIRCULARBUFFER_HH
10 template<
typename T,
size_t MAXSIZE>
19 buffer[first] = element;
24 buffer[first] = std::move(element);
26 constexpr
void addBack(
const T& element) {
28 buffer[last] = element;
33 buffer[last] = std::move(element);
48 assert(pos < MAXSIZE);
49 auto tmp = first + pos;
55 [[nodiscard]] constexpr
const T&
operator[](
size_t pos)
const {
58 [[nodiscard]] constexpr
bool isEmpty()
const {
59 return (first == last);
61 [[nodiscard]] constexpr
bool isFull()
const {
62 return (first == next(last));
64 [[nodiscard]] constexpr
size_t size()
const {
66 return MAXSIZE + 1 - first + last;
73 [[nodiscard]] constexpr
size_t next(
size_t a)
const {
74 return (a != MAXSIZE) ? a + 1 : 0;
76 [[nodiscard]] constexpr
size_t prev(
size_t a)
const {
77 return (a != 0) ? a - 1 : MAXSIZE;
83 T buffer[MAXSIZE + 1];
constexpr void addBack(const T &element)
constexpr const T & operator[](size_t pos) const
constexpr T & operator[](size_t pos)
constexpr bool isFull() const
constexpr void addBack(T &&element)
constexpr CircularBuffer()=default
constexpr size_t size() const
constexpr void addFront(T &&element)
constexpr bool isEmpty() const
constexpr void addFront(const T &element)
constexpr T & removeFront()
constexpr T & removeBack()
This file implemented 3 utility functions: