16template <
class T,
size_t N>
19 static_assert(N > 0,
"Circular buffer size cannot be zero.");
116 size_t size()
const {
return m_length; }
126 const T&
front()
const {
return (*
this)[0]; }
134 T&
back() {
return m_data[(m_front + m_length - 1) % N]; }
142 const T&
back()
const {
return m_data[(m_front + m_length - 1) % N]; }
150 m_front = ModuloDec(m_front);
152 m_data[m_front] =
value;
165 m_data[(m_front + m_length) % N] =
value;
171 m_front = ModuloInc(m_front);
181 template <
class... Args>
183 m_front = ModuloDec(m_front);
185 m_data[m_front] = T{args...};
198 template <
class... Args>
200 m_data[(m_front + m_length) % N] = T{args...};
206 m_front = ModuloInc(m_front);
217 T& temp = m_data[m_front];
218 m_front = ModuloInc(m_front);
231 return m_data[(m_front + m_length) % N];
251 return m_data[(m_front +
index) % N];
255 std::array<T, N> m_data;
268 size_t ModuloInc(
size_t index) {
return (index + 1) % N; }
275 size_t ModuloDec(
size_t index) {
\rst A contiguous memory buffer with an optional growing ability.
Definition: core.h:862
Definition: static_circular_buffer.h:49
std::forward_iterator_tag iterator_category
Definition: static_circular_buffer.h:51
const_iterator(const static_circular_buffer *buffer, size_t index)
Definition: static_circular_buffer.h:57
bool operator==(const const_iterator &) const =default
const_iterator operator++(int)
Definition: static_circular_buffer.h:64
const_iterator & operator++()
Definition: static_circular_buffer.h:60
const_reference operator*() const
Definition: static_circular_buffer.h:70
const T & const_reference
Definition: static_circular_buffer.h:55
T * pointer
Definition: static_circular_buffer.h:54
T value_type
Definition: static_circular_buffer.h:52
std::ptrdiff_t difference_type
Definition: static_circular_buffer.h:53
Definition: static_circular_buffer.h:21
iterator operator++(int)
Definition: static_circular_buffer.h:36
T value_type
Definition: static_circular_buffer.h:24
reference operator*()
Definition: static_circular_buffer.h:42
std::ptrdiff_t difference_type
Definition: static_circular_buffer.h:25
bool operator==(const iterator &) const =default
T & reference
Definition: static_circular_buffer.h:27
iterator & operator++()
Definition: static_circular_buffer.h:32
iterator(static_circular_buffer *buffer, size_t index)
Definition: static_circular_buffer.h:29
T * pointer
Definition: static_circular_buffer.h:26
std::forward_iterator_tag iterator_category
Definition: static_circular_buffer.h:23
This is a simple circular buffer so we don't need to "bucket brigade" copy old values.
Definition: static_circular_buffer.h:17
const T & back() const
Returns value at back of buffer.
Definition: static_circular_buffer.h:142
T & operator[](size_t index)
Definition: static_circular_buffer.h:245
iterator end()
Returns end iterator.
Definition: static_circular_buffer.h:85
void emplace_back(Args &&... args)
Push a new value onto the back of the buffer that is constructed with the provided constructor argume...
Definition: static_circular_buffer.h:199
void push_front(T value)
Push a new value onto the front of the buffer.
Definition: static_circular_buffer.h:149
void reset()
Empties internal buffer.
Definition: static_circular_buffer.h:237
T & back()
Returns value at back of buffer.
Definition: static_circular_buffer.h:134
T pop_back()
Pop value at back of buffer.
Definition: static_circular_buffer.h:229
T pop_front()
Pop value at front of buffer.
Definition: static_circular_buffer.h:216
void push_back(T value)
Push a new value onto the back of the buffer.
Definition: static_circular_buffer.h:164
const_iterator end() const
Returns end iterator.
Definition: static_circular_buffer.h:97
const T & operator[](size_t index) const
Definition: static_circular_buffer.h:250
const_iterator begin() const
Returns begin iterator.
Definition: static_circular_buffer.h:92
const_iterator cbegin() const
Returns begin iterator.
Definition: static_circular_buffer.h:104
const T & front() const
Returns value at front of buffer.
Definition: static_circular_buffer.h:126
void emplace_front(Args &&... args)
Push a new value onto the front of the buffer that is constructed with the provided constructor argum...
Definition: static_circular_buffer.h:182
iterator begin()
Returns begin iterator.
Definition: static_circular_buffer.h:80
const_iterator cend() const
Returns end iterator.
Definition: static_circular_buffer.h:109
size_t size() const
Returns number of elements in buffer.
Definition: static_circular_buffer.h:116
T & front()
Returns value at front of buffer.
Definition: static_circular_buffer.h:121
Definition: AprilTagFieldLayout.h:18