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 unsigned N = 64u)
Constructor,N is the desired capacity of the buffer.
unsigned size() cons
Number of element currently in the buffer.
unsigned capacity() const
Maximum capacity of the buffer.
void resize(const unsigned 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 unsigned 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.