Task 3 : Circular Buffer

This assignment is a tricker one. Your job is to implement a circular buffer or a ring buffer. Circular buffers are First-In-First-Out buffers

Requirements

  • Must be a class (or struct).
  • Must have these constructors
    • Default
    • Copy
    • Move
    • Assignment Copy
    • Assignment Move
    • A destructor
  • Must be templated for any element type T.
  • Can either be dynamic in size (adds memory as it needs) or semi-static (fixed maximum but variable current size)
  • Methods for pushing in a new element to the front and popping the oldest from the back.
  • Introspection methods
    • Current size
    • Current capacity
    • One that returns a pointer to the first element
    • A method to check if the buffer is full
    • A method to check if the buffer is empty
  • Element access
    • at-like method with index checking
    • subscript operator overload ([])

You can manually create and destroy the memory, use smart pointers or use a container to store the underlying memory.

Optional

  • Have a custom iterator type with the relevant methods in the circular buffer for obtaining them.
  • front and and back element access.
  • Equality (==) and inequality (!=) operator overloads.
  • Output stream operator overload (>>).
  • Constructor and assignment operator overload (=) that take an std::initializer_list.
  • Uses an allocator (eg. std::allocator) to allocate memory.
  • Takes an additional template argument that correlates to a generic allocator type.
  • Takes an additional template parameter that correlates to the type of the underlying container used to for storage of elements (eg. std::vector) making the circular buffer an adaptor.

Submitting

You can use Godbolt or bpt to build and test your struct. Once you have created your implementation:

  • Clone this repo using git clone https://github.com/MonashDeepNeuron/HPP.git.
  • Create a new branch using git checkout -b triple/<your-name>.
  • Create a folder in the /submissions directory with your name.
  • Create a folder with the name of this task.
  • Copy your mini project into this directory (bpt setup, cmake scripts etc.) with a README.md or comment in the code on how to run the program (verify it still works). There is a sample header file in /templates that you can use.
  • Go to https://github.com/MonashDeepNeuron/HPP/pulls and click 'New pull request'.
  • Change the branches in the drop down so that your branch is going into main and `Create new pull request.
  • Give the pull request a title and briefly describe what you were able to implement and any struggles you had.
  • On the right side-panel, under the 'Assignees' section, click the cog and assign me.
  • Click 'Create pull request' and I'll take it from there.

Note: If you created a GodBolt instance, put the link in a comment at the top of the file (under your copy comments). This is generated by clicking the share button in the top-right-most corner of the webpage and clicking the 'short link' option.