Step 5 of 5
Challenge: a ring buffer
A ring buffer (circular buffer) is a fixed-capacity queue stored in an array: the write position wraps around to the start, overwriting the oldest item when full. Audio pipelines, loggers and network stacks use them because they never allocate after construction.
capacity 4, after pushing 1..6: [5][6][3][4] oldest = 3
^head
Your turn: write template <typename T, std::size_t N> class RingBuffer with:
void push(const T& v): adds v; when full, overwrites the oldeststd::size_t size() const,bool full() constconst T& operator[](std::size_t i) const: i-th element counting from the oldestbegin()/end()so range-for visits oldest to newest (an iterator holding a buffer pointer and an index works well)