CyclicBuffer

A CyclicBuffer stores can store a number of successive values. Once the buffer is full, adding a new value will overwrite the oldest value in the buffer. It can be used, for instance, to store the last N measurements from a given source.

Interface

The full class definition:

template <typename T>
CyclicBuffer<T>;

value_type
Alias for template parameter T.
CyclicBuffer<T>(const std::size_t N = 64u)
Constructor,N is the desired capacity of the buffer.
std::size_t size() cons
Number of element currently in the buffer.
std::size_t capacity() const
Maximum capacity of the buffer.
void resize(const std::size_t N)
Change the capacity of the buffer.
void clear()
Remove all elements from the buffer.
void add(const value_type x)
Add an element to the buffer.
value_type avg() const
Return the average value of all the elements in the buffer.
value_type operator[](const std::size_t index) const
Access previously stored elements. For index equal to zero, retrieve the last added element; for index equals one, return the last-but-one added element; et cetera.