Firmware for a device with 64KB of RAM and a defense-industry client. Runtime allocation is forbidden by a regulation nobody has read in full but everyone fears. Telemetry must go into a fixed-size ring: oldest entries get overwritten, newest survive. Write the buffer — and remember that around here new equals a formal reprimand.
Implement a fixed-capacity CircularBuffer<T> (ring buffer) with FIFO semantics, write/read, and an overwrite that replaces the oldest element when full.
Adapted from exercism/cpp (MIT).
read() returns oldest element (FIFO); throws if emptywrite() appends; throws if fulloverwrite() writes even when full, dropping the oldest elementclear() empties the buffer; empty()/full() report statewrite and overwrite when full?Keep head, tail, and size indices into a fixed-capacity array; wrap with % capacity.
overwrite when full advances head too, dropping the oldest element.
Hit Submit (or ⌘/Ctrl + ↵) — test results will show up here.