Template Class RingBuffer
Defined in File RingBuffer.hpp
Class Documentation
Ring (or circular) buffers are sequence containers with static sizes.
They allow for the individual elements to be accessed directly through random access iterators. They allow for insertion/deletion at either end of the buffer. Inserting to a full buffer will pop an element off the other end. Elements are not guaranteed to be stored in contiguous memory (due to the wrap around nature of the underlying buffer).
Public Types
Type of elements stored in the ring buffer.
Type of
iteratorto ring buffer element.
Type of
const_iteratorto ring buffer element.
Type of
reverse_iteratorto ring buffer element.
Type of
const_reverse_iteratorto ring buffer element.
Public Functions
Default constructor.
- Parameters
capacity – number of elements the ring buffer can hold
Default destructor.
Copy constructor.
- Parameters
other – buffer to copy
Copy assignment operator.
- Parameters
other – buffer to copy
- Returns
Buffer (by reference)
Move constructor.
- Parameters
other – buffer to move from
Move assignment operator.
- Parameters
other – buffer to move from
- Returns
Buffer (by reference)
- Returns
The number of elements in the container.
- Returns
trueif the container size is 0,falseotherwise.
- Returns
trueif the container is at capacity.
- Returns
Reference to the first element in the container.
- Returns
Constant reference to the first element in the container.
- Returns
Reference to the last element in the container.
- Returns
Constant reference to the last element in the container.
Removes the first element in the container, effectively reducing its size by one.
This destroys the removed element.
Removes the last element in the container, effectively reducing its size by one.
This destroys the removed element.
Inserts a new element at the beginning of the container, right before its current first element.
The content of value is copied to the inserted element. This effectively increases the container size by one unless the container is full in which case the element at the back of the container is removed and destroyed.
- Parameters
value – to push
Inserts a new element at the beginning of the container, right before its current first element.
The content of value is moved to the inserted element. This effectively increases the container size by one unless the container is full in which case the element at the back of the container is removed and destroyed.
- Parameters
value – to push
Inserts a new element at the end of the container, right after its current last element.
The content of value is copied to the inserted element. This effectively increases the container size by one unless the container is full in which case the element at the beginning of the container is removed and destroyed.
- Parameters
value – to push
Inserts a new element at the end of the container, right after its current last element.
The content of value is moved to the inserted element. This effectively increases the container size by one unless the container is full in which case the element at the beginning of the container is removed and destroyed.
- Parameters
value – to push
Removes from the container the range of elements in [first, last).
The range includes all the elements between first and last, including the element pointed by first but not the one pointed by last. This effectively reduces the container size by the number of elements removed, which are destroyed. Return Value: An iterator pointing to the location of the element that followed the last element erased by the function call. This is the container end if the operation erased the last element in the container. Exception: Only supports erasing elements from the beginning or end of the container. If the specified range is in the middle of the container an exception will be thrown.
- Parameters
first – the first element to remove
last – one past the last element to remove
- Returns
Element after the last element removed
If the container is empty, the returned iterator value shall not be dereferenced.
- Returns
An iterator pointing to the first element in the container.
If the container is empty, the returned iterator value shall not be dereferenced.
- Returns
A constant iterator pointing to the first element in the container.
If the container is empty, the returned iterator value shall not be dereferenced.
- Returns
A constant iterator pointing to the first element in the container.
The past-the-end element is the theoretical element that would follow the last element in the container. It does not point to any element, and thus shall not be dereferenced.
- Returns
An iterator pointing to the past-the-end element in the container.
The past-the-end element is the theoretical element that would follow the last element in the container. It does not point to any element, and thus shall not be dereferenced.
- Returns
A constant iterator pointing to the past-the-end element in the container.
The past-the-end element is the theoretical element that would follow the last element in the container. It does not point to any element, and thus shall not be dereferenced.
- Returns
A constant iterator pointing to the past-the-end element in the container.
Reverse iterators iterate backwards: increasing them moves them towards the beginning of the container. rbegin points to the element right before the one that would be pointed to by member end. If the container is empty, the returned iterator value shall not be dereferenced.
- Returns
A reverse iterator pointing to the last element in the container.
Reverse iterators iterate backwards: increasing them moves them towards the beginning of the container. rbegin points to the element right before the one that would be pointed to by member end. If the container is empty, the returned iterator value shall not be dereferenced.
- Returns
A constant reverse iterator pointing to the last element in the container.
Reverse iterators iterate backwards: increasing them moves them towards the beginning of the container. rbegin points to the element right before the one that would be pointed to by member end. If the container is empty, the returned iterator value shall not be dereferenced.
- Returns
A constant reverse iterator pointing to the last element in the container.
The before-the-beginning element is the theoretical element that would preceed the first element in the container. It does not point to any element, and thus shall not be dereferenced.
- Returns
A reverse iterator pointing to the before-the-beginning element in the container.
The before-the-beginning element is the theoretical element that would preceed the first element in the container. It does not point to any element, and thus shall not be dereferenced.
- Returns
A constant reverse iterator pointing to the before-the-beginning element in the container.
The before-the-beginning element is the theoretical element that would preceed the first element in the container. It does not point to any element, and thus shall not be dereferenced.
- Returns
A constant reverse iterator pointing to the before-the-beginning element in the container.