1#ifndef CIRCULARBUFFER_HH
2#define CIRCULARBUFFER_HH
11template<
typename T,
size_t MAXSIZE>
20 buffer[first] = element;
25 buffer[first] = std::move(element);
29 buffer[last] = element;
34 buffer[last] = std::move(element);
51 auto tmp = first + pos;
57 [[nodiscard]]
constexpr const T&
operator[](
size_t pos)
const {
61 [[nodiscard]]
constexpr T&
front() {
65 [[nodiscard]]
constexpr const T&
front()
const {
69 [[nodiscard]]
constexpr T&
back() {
71 return buffer[prev(last)];
73 [[nodiscard]]
constexpr const T&
back()
const {
77 [[nodiscard]]
constexpr bool empty()
const {
78 return (first == last);
80 [[nodiscard]]
constexpr bool full()
const {
81 return (first == next(last));
83 [[nodiscard]]
constexpr size_t size()
const {
85 return MAXSIZE + 1 - first + last;
96 [[nodiscard]]
constexpr size_t next(
size_t a)
const {
97 return (a != MAXSIZE) ? a + 1 : 0;
99 [[nodiscard]]
constexpr size_t prev(
size_t a)
const {
100 return (a != 0) ? a - 1 : MAXSIZE;
106 std::array<T, MAXSIZE + 1> buffer;
constexpr bool full() const
constexpr void push_back(T &&element)
constexpr const T & front() const
constexpr T & operator[](size_t pos)
constexpr CircularBuffer()=default
constexpr bool empty() const
constexpr void push_front(const T &element)
constexpr size_t size() const
constexpr T & pop_front()
constexpr void push_front(T &&element)
constexpr const T & operator[](size_t pos) const
constexpr const T & back() const
constexpr void push_back(const T &element)
This file implemented 3 utility functions: