46. Circular buffer

Create a data structure that represents a circular buffer of a fixed size. A circular buffer overwrites existing elements when the buffer is being filled beyond its fixed size. The class you must write should:

  • Prohibit default construction
  • Support the creation of objects with a specified size
  • Allow checking of the buffer capacity and status (empty(), full(), size(), capacity())
  • Add a new element, an operation that could potentially overwrite the oldest element in the buffer
  • Remove the oldest element from the buffer
  • Support iteration through its elements

Get The Modern C++ Challenge now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.