1#ifndef CIRCULARBUFFER_HH
2#define CIRCULARBUFFER_HH
11template<
typename T,
size_t MAXSIZE>
20 buffer[first] = element;
25 buffer[first] = std::move(element);
27 constexpr void addBack(
const T& element) {
29 buffer[last] = element;
34 buffer[last] = std::move(element);
49 assert(pos < MAXSIZE);
50 auto tmp = first + pos;
56 [[nodiscard]]
constexpr const T&
operator[](
size_t pos)
const {
59 [[nodiscard]]
constexpr bool isEmpty()
const {
60 return (first == last);
62 [[nodiscard]]
constexpr bool isFull()
const {
63 return (first == next(last));
65 [[nodiscard]]
constexpr size_t size()
const {
67 return MAXSIZE + 1 - first + last;
74 [[nodiscard]]
constexpr size_t next(
size_t a)
const {
75 return (a != MAXSIZE) ? a + 1 : 0;
77 [[nodiscard]]
constexpr size_t prev(
size_t a)
const {
78 return (a != 0) ? a - 1 : MAXSIZE;
84 std::array<T, MAXSIZE + 1> buffer;
constexpr void addBack(const T &element)
constexpr bool isFull() const
constexpr void addBack(T &&element)
constexpr T & operator[](size_t pos)
constexpr T & removeFront()
constexpr CircularBuffer()=default
constexpr T & removeBack()
constexpr size_t size() const
constexpr void addFront(T &&element)
constexpr bool isEmpty() const
constexpr void addFront(const T &element)
constexpr const T & operator[](size_t pos) const
This file implemented 3 utility functions: