45 template <
typename T, std::
size_t S>
53 using iterator =
typename std::array<T, S>::iterator;
63 return _buffer.begin();
70 return _full ? _buffer.end() : _buffer.begin() + _i;
77 return _full ? S : _i;
103 bool empty() const noexcept {
return !_full && _i == 0; }
117 template <
typename... Args>
120 _buffer[_i] = T(std::forward<Args>(args)...);
139 return _buffer[(pos + (_full ? _i : 0)) % S];
153 return _buffer[(pos + (_full ? _i : 0)) % S];
161 return _buffer[(pos + (_full ? _i : 0)) % S];
169 return _buffer[(pos + (_full ? _i : 0)) % S];
176 return _buffer[_full ? _i : 0];
183 return _buffer[_full ? _i : 0];
190 return _buffer[(_i + S - 1) % S];
197 return _buffer[(_i + S - 1) % S];
201 std::array<T, S> _buffer;
std::size_t size_type
Definition circular_buffer.hpp:50
const_reference operator[](size_type pos) const
Accesses the element at specified location without bounds checking (const version).
Definition circular_buffer.hpp:167
bool empty() const noexcept
Definition circular_buffer.hpp:103
reference front()
Accesses the first element in the buffer.
Definition circular_buffer.hpp:174
auto begin() noexcept
Gets an iterator to the beginning of the buffer.
Definition circular_buffer.hpp:61
void push_back(const T &t)
Adds an element to the back of the buffer.
Definition circular_buffer.hpp:93
const_reference front() const
Accesses the first element in the buffer (const version).
Definition circular_buffer.hpp:181
const_reference at(size_type pos) const
Accesses the element at specified location with bounds checking (const version).
Definition circular_buffer.hpp:146
void clear() noexcept
Definition circular_buffer.hpp:105
T value_type
Definition circular_buffer.hpp:49
void emplace_back(Args &&... args)
Adds an element to the back of the buffer.
Definition circular_buffer.hpp:118
typename std::array< T, S >::iterator iterator
Definition circular_buffer.hpp:53
value_type & reference
Definition circular_buffer.hpp:51
const value_type & const_reference
Definition circular_buffer.hpp:52
circular_buffer()=default
Default constructor.
reference operator[](size_type pos)
Accesses the element at specified location without bounds checking.
Definition circular_buffer.hpp:159
const_reference back() const
Accesses the last element in the buffer (const version).
Definition circular_buffer.hpp:195
typename std::array< T, S >::const_iterator const_iterator
Definition circular_buffer.hpp:54
std::size_t max_size() const
Gets the maximum number of elements the buffer can hold.
Definition circular_buffer.hpp:82
reference back()
Accesses the last element in the buffer.
Definition circular_buffer.hpp:188
auto end() noexcept
Gets an iterator to the end of the buffer.
Definition circular_buffer.hpp:68
std::size_t size() const
Gets the number of elements in the buffer.
Definition circular_buffer.hpp:75
reference at(size_type pos)
Accesses the element at specified location with bounds checking.
Definition circular_buffer.hpp:132
A Cbeam-specific out_of_range error that also behaves like std::out_of_range.
Definition out_of_range.hpp:50
Offers advanced container types with unique approaches to stability and interprocess sharing....
Definition buffer.hpp:44