|
My Project
|
A sequence container that encapsulates a resizable ring/circular buffer. More...
#include <tim/circular-buffer/CircularBuffer.hpp>
Public Types | |
| using | value_type = T |
| using | allocator_type = Allocator |
| using | size_type = typename alloc_traits::size_type |
| using | difference_type = typename alloc_traits::difference_type |
| using | reference = value_type & |
| using | const_reference = const value_type & |
| using | pointer = typename alloc_traits::pointer |
| using | const_pointer = typename alloc_traits::const_pointer |
| using | iterator = CircularBufferIterator< T, Allocator > |
| using | const_iterator = ConstCircularBufferIterator< T, Allocator > |
| using | reverse_iterator = std::reverse_iterator< iterator > |
| using | const_reverse_iterator = std::reverse_iterator< const_iterator > |
| using | shape_type = BufferShape< size_type > |
Public Member Functions | |
| constexpr | ~CircularBuffer () |
| constexpr | CircularBuffer ()=default |
| Default constructor. Constructs an empty buffer with 0 capacity. | |
| constexpr | CircularBuffer (const Allocator &al) noexcept(std::is_nothrow_copy_constructible_v< Allocator >) |
| Constructs an empty container with the given allocator alloc. More... | |
| template<class TagType , std::enable_if_t< detail::is_one_of_v< TagType, tags::PreserveBufferLayout, tags::PreserveBufferCapacity, tags::Optimized >, bool > = true> | |
| constexpr | CircularBuffer (TagType tag, const CircularBuffer &other, const Allocator &al) |
| Constructs a copy of 'other' with the given allocator 'al' using the method specified by 'tag'. More... | |
| template<class TagType , std::enable_if_t< detail::is_one_of_v< TagType, tags::PreserveBufferLayout, tags::PreserveBufferCapacity, tags::Optimized > > = true> | |
| constexpr | CircularBuffer (TagType tag, const CircularBuffer &other) |
| Constructs a copy of 'other' using the method specified by 'tag'. More... | |
| constexpr | CircularBuffer (const CircularBuffer &other, const Allocator &al) |
| Constructs a copy of 'other' with the given allocator 'al' as if by calling 'CircularBuffer(tags::optimized, other, al)'. More... | |
| constexpr | CircularBuffer (CircularBuffer &&other) noexcept |
| Move constructor. More... | |
| template<class TagType , std::enable_if_t< detail::is_one_of_v< TagType, tags::PreserveBufferLayout, tags::PreserveBufferCapacity, tags::Optimized > > = true> | |
| constexpr | CircularBuffer (TagType tag, CircularBuffer &&other) |
| Tagged move constructor. More... | |
| template<class TagType , std::enable_if_t< detail::is_one_of_v< TagType, tags::PreserveBufferLayout, tags::PreserveBufferCapacity, tags::Optimized > > = true> | |
| constexpr | CircularBuffer (TagType tag, CircularBuffer &&other, const Allocator &al) |
| Tagged move constructor with custom allocator. More... | |
| constexpr | CircularBuffer (CircularBuffer &&other, const Allocator &alloc) noexcept |
| Move constructor with custom allocator. More... | |
| constexpr | CircularBuffer (shape_type shape, const Allocator &al) noexcept(std::is_nothrow_copy_constructible_v< Allocator >) |
| Shape constructor. More... | |
| constexpr | CircularBuffer (std::initializer_list< T > init, const Allocator &alloc=Allocator()) |
| Initializer list constructor. More... | |
| CircularBuffer (size_type count, const value_type &value, const Allocator &alloc=Allocator()) | |
| Constructs the container with 'count' copies of elements with value 'value'. More... | |
| constexpr | CircularBuffer (size_type count, const Allocator &alloc=Allocator()) |
| Constructs the container with 'count' default-consrtucted elements. More... | |
| template<class It , std::enable_if_t< std::is_convertible_v< typename std::iterator_traits< It >::iterator_category, std::forward_iterator_tag >, bool > = true> | |
| constexpr | CircularBuffer (It first, It last, const Allocator &alloc=Allocator()) |
| Constructs the container with the contents of the range [first, last). More... | |
| template<class It , std::enable_if_t< std::is_same_v< typename std::iterator_traits< It >::iterator_category, std::input_iterator_tag >, bool > = true> | |
| constexpr | CircularBuffer (It first, It last, const Allocator &alloc=Allocator()) |
| Constructs the container with the contents of the range [first, last). More... | |
| constexpr | CircularBuffer (const CircularBuffer &other) |
| Copy constructor. Constructs the container with the copy of the contents of other. More... | |
| constexpr CircularBuffer & | operator= (const CircularBuffer &other) |
| Copy assignment operator. Replaces the contents with a copy of the contents of other. More... | |
| constexpr CircularBuffer & | operator= (CircularBuffer &&other) noexcept(propagate_on_container_move_assignment||is_always_equal) |
| constexpr CircularBuffer & | operator= (std::initializer_list< T > init) |
| Replaces the contents with those identified by initializer list 'init'. More... | |
| constexpr void | assign (size_type count, const T &value) |
| Replaces the contents with count copies of value value. More... | |
| template<class It , std::enable_if_t< std::is_convertible_v< typename std::iterator_traits< It >::iterator_category, std::input_iterator_tag >, bool > = false> | |
| constexpr void | assign (It first, It last) |
| Replaces the contents with copies of those in the range [first, last). More... | |
| constexpr void | assign (std::initializer_list< T > ilist) |
| Replaces the contents with the elements from the initializer list 'init'. More... | |
| constexpr allocator_type | get_allocator () const noexcept |
| Returns the allocator associated with the container. | |
| constexpr iterator | begin () noexcept |
| Returns a mutable iterator to the first element of the buffer. | |
| constexpr const_iterator | begin () const noexcept |
| Returns a const iterator to the first element of the buffer. | |
| constexpr const_iterator | cbegin () const noexcept |
| Returns a const iterator to the first element of the buffer. | |
| constexpr iterator | end () noexcept |
| Returns a mutable iterator to the element following the last element of the buffer. More... | |
| constexpr const_iterator | end () const noexcept |
| Returns a const iterator to the element following the last element of the buffer. More... | |
| constexpr const_iterator | cend () const noexcept |
| Returns a const iterator to the element following the last element of the buffer. More... | |
| constexpr reverse_iterator | rbegin () noexcept |
| Returns a mutable reverse iterator to the first element of the reversed buffer. More... | |
| constexpr const_reverse_iterator | rbegin () const noexcept |
| Returns a const reverse iterator to the first element of the reversed buffer. More... | |
| constexpr const_reverse_iterator | crbegin () const noexcept |
| Returns a const reverse iterator to the first element of the reversed buffer. More... | |
| constexpr reverse_iterator | rend () noexcept |
| Returns a mutable reverse iterator to the element following the last element of the reversed buffer. More... | |
| constexpr const_reverse_iterator | rend () const noexcept |
| Returns a const reverse iterator to the element following the last element of the reversed buffer. More... | |
| constexpr const_reverse_iterator | crend () const noexcept |
| Returns a const reverse iterator to the element following the last element of the reversed buffer. More... | |
| constexpr reference | operator[] (size_type index) |
| Returns a mutable reference to the element at specified location 'index'. No bounds checking is performed. More... | |
| constexpr const_reference | operator[] (size_type index) const |
| Returns a const reference to the element at specified location 'index'. No bounds checking is performed. More... | |
| constexpr reference | at (size_type index) |
| Returns a mutable reference to the element at specified location 'index', with bounds checking. More... | |
| constexpr const_reference | at (size_type index) const |
| Returns a const reference to the element at specified location 'index', with bounds checking. More... | |
| constexpr const_reference | front () const |
| Returns a const reference to the first element in the container. More... | |
| constexpr reference | front () |
| Returns a mutable reference to the first element in the container. More... | |
| constexpr const_reference | back () const |
| Returns a const reference to the last element in the container. More... | |
| constexpr reference | back () |
| Returns a mutable reference to the last element in the container. More... | |
| constexpr size_type | capacity () const noexcept |
| Returns the number of elements that the container has currently allocated space for. | |
| constexpr size_type | size () const noexcept |
| Returns the number of elements in the container, i.e. std::distance(begin(), end()). | |
| constexpr bool | empty () const noexcept |
| Checks if the container has no elements, i.e. whether begin() == end(). More... | |
| constexpr size_type | max_size () const noexcept |
| Returns the maximum number of elements the container is able to hold due to system or library implementation limitations, i.e. std::distance(begin(), end()) for the largest possible container. More... | |
| constexpr size_type | begin_index () const |
| Returns the index into the raw (physical) memory buffer of the first element (the physical index of logical index 0). | |
| constexpr size_type | end_index () const |
| Returns the index into the raw memory buffer of the element following the last element in the buffer. More... | |
| constexpr void | clear () noexcept |
| Erases all elements from the container. More... | |
| constexpr void | reserve (size_type new_cap) |
| Increase the capacity of the buffer to a value that's greater or equal to new_cap. More... | |
| constexpr void | shrink_to_fit () |
| Requests the removal of unused capacity. More... | |
| template<class It , std::enable_if_t< detail::is_one_of_v< typename std::iterator_traits< It >::iterator_category, std::input_iterator_tag >, bool > = false> | |
| constexpr iterator | insert_move_back (const_iterator pos, It first, It last) |
| Inserts elements from range [first, last) before pos. Elements in the range [pos, end()) are moved to make room for the to-be-inserted range. More... | |
| template<class It , std::enable_if_t< std::is_convertible_v< typename std::iterator_traits< It >::iterator_category, std::forward_iterator_tag >, bool > = false> | |
| constexpr iterator | insert_move_back (const_iterator pos, It first, It last) |
| Inserts elements from range [first, last) before pos. Elements in the range [pos, end()) are moved to make room for the to-be-inserted range. More... | |
| template<class U , std::enable_if_t< std::is_same_v< T, std::remove_cvref_t< U > >, bool > = true> | |
| constexpr iterator | insert_move_back (const_iterator pos, U &&value) |
| Inserts the given element before pos. Elements in the range [pos, end()) are moved to make room for the to-be-inserted range. More... | |
| constexpr iterator | insert_move_back (const_iterator pos, size_type count, const T &value) |
| Inserts 'count' copies of the given element before pos. Elements in the range [pos, end()) are moved to make room for the to-be-inserted range. More... | |
| constexpr iterator | insert_move_back (const_iterator pos, std::initializer_list< T > ilist) |
| Inserts the elements from the initialize list before pos. Elements in the range [pos, end()) are moved to make room for the to-be-inserted range. More... | |
| template<class It , std::enable_if_t< detail::is_one_of_v< typename std::iterator_traits< It >::iterator_category, std::input_iterator_tag >, bool > = false> | |
| constexpr iterator | insert_move_front (const_iterator pos, It first, It last) |
| Inserts elements from range [first, last) before pos. Elements in the range [begin(), pos) are moved to make room for the to-be-inserted range. More... | |
| template<class It , std::enable_if_t< std::is_convertible_v< typename std::iterator_traits< It >::iterator_category, std::forward_iterator_tag >, bool > = false> | |
| constexpr iterator | insert_move_front (const_iterator pos, It first, It last) |
| Inserts elements from range [first, last) before pos. Elements in the range [begin(), pos) are moved to make room for the to-be-inserted range. More... | |
| template<class U , std::enable_if_t< std::is_same_v< T, std::remove_cvref_t< U > >, bool > = true> | |
| constexpr iterator | insert_move_front (const_iterator pos, U &&value) |
| Inserts the given element before pos. Elements in the range [begin(), pos) are moved to make room for the to-be-inserted ivalue. More... | |
| constexpr iterator | insert_move_front (const_iterator pos, size_type count, const T &value) |
| Inserts 'count' copies of the given element before pos. Elements in the range [begin(), pos) are moved to make room for the to-be-inserted range. More... | |
| constexpr iterator | insert_move_front (const_iterator pos, std::initializer_list< T > ilist) |
| Inserts the elements from the initialize list before pos. Elements in the range [begin(), pos) are moved to make room for the to-be-inserted range. More... | |
| template<class It > | |
| constexpr iterator | insert (const_iterator pos, It first, It last) |
| Inserts elements from range [first, last) before pos. More... | |
| constexpr iterator | insert (const_iterator pos, std::initializer_list< T > ilist) |
| Inserts the elements from the initialize list before pos. More... | |
| template<class U , std::enable_if_t< std::is_same_v< T, std::remove_cvref_t< U > >, bool > = true> | |
| constexpr iterator | insert (const_iterator pos, U &&value) |
| Inserts the given element before pos. More... | |
| constexpr iterator | insert (const_iterator pos, size_type count, const T &value) |
| Inserts 'count' copies of the given element before pos. More... | |
| template<class ... Args> | |
| constexpr iterator | emplace (const_iterator pos, Args &&... args) |
| Emplaces the given element before pos. More... | |
| template<class ... Args> | |
| constexpr iterator | emplace_move_back (const_iterator pos, Args &&... args) |
| Emplaces the given element before pos. Elements in the range [pos, end()) are moved to make room for the to-be-inserted range. More... | |
| template<class ... Args> | |
| constexpr iterator | emplace_move_front (const_iterator pos, Args &&... args) |
| Emplaces the given element before pos. Elements in the range [begin(), pos) are moved to make room for the to-be-inserted range. More... | |
| template<class ... Args> | |
| constexpr reference | emplace_back (Args &&... args) |
| Emplaces the given element at the past-the-end position in the buffer. More... | |
| template<class ... Args> | |
| constexpr reference | emplace_front (Args &&... args) |
| Emplaces the given element at the beginning of the buffer. More... | |
| constexpr iterator | erase (const_iterator pos) |
| Removes the element at 'pos'. More... | |
| constexpr iterator | erase_move_back (const_iterator pos) |
| Removes the element at 'pos'. Elements in the range [pos, end()) are shifted to occupy the erased space. More... | |
| constexpr iterator | erase_move_front (const_iterator pos) |
| Removes the element at 'pos'. Elements in the range [begin(), pos) are shifted to occupy the erased space. More... | |
| constexpr iterator | erase (const_iterator start, const_iterator stop) |
| Removes the elements in the range [first, last). More... | |
| constexpr iterator | erase_move_back (const_iterator start, const_iterator stop) |
| Removes the elements in the range [first, last). Elements in the range [last, end()) are shifted to occupy the erased space. More... | |
| constexpr iterator | erase_move_front (const_iterator start, const_iterator stop) |
| Removes the elements in the range [first, last). Elements in the range [begin(), pos) are shifted to occupy the erased space. More... | |
| template<class Pred > | |
| constexpr size_type | erase_if (Pred pred) |
| Erases all elements for which 'pred' returns true. More... | |
| constexpr void | push_back (const T &value) |
| Appends the given element value to the end of the container. The new element is initialized as a copy of value. More... | |
| constexpr void | push_back (T &&value) |
| Appends the given element value to the end of the container. 'value' is moved into the new element. More... | |
| constexpr void | push_front (const T &value) |
| Prepends the given element value to the beginning of the container. The new element is initialized as a copy of value. More... | |
| constexpr void | push_front (T &&value) |
| Prepends the given element value to the beginning of the container. The new element is initialized as a copy of value. More... | |
| constexpr void | pop_back () |
| Removes the last element of the container. More... | |
| constexpr void | pop_back_n (size_type count) |
| Removes the last 'count' elements from the container. More... | |
| constexpr void | pop_front () |
| Removes the first element of the container. More... | |
| constexpr void | pop_front_n (size_type count) |
| Removes the first 'count' elements from the container. More... | |
| constexpr void | resize (size_type count) |
| Resizes the container to contain count elements. More... | |
| constexpr void | resize (size_type count, const T &value) |
| Resizes the container to contain count elements. More... | |
| constexpr void | resize_front (size_type count) |
| Resizes the container to contain count elements. More... | |
| constexpr void | resize_front (size_type count, const T &value) |
| Resizes the container to contain count elements. More... | |
| template<class It , std::enable_if_t< detail::is_one_of_v< typename std::iterator_traits< It >::iterator_category, std::input_iterator_tag >, bool > = false> | |
| constexpr void | append (It first, It last) |
| Adds elements in the range [first, last) to the end of the container, as if by calling 'v.insert(v.end(), first, last)'. More... | |
| template<class It , std::enable_if_t< std::is_convertible_v< typename std::iterator_traits< It >::iterator_category, std::forward_iterator_tag >, bool > = false> | |
| constexpr void | append (It first, It last) |
| Adds elements in the range [first, last) to the end of the container, as if by calling 'insert(end(), first, last)'. More... | |
| template<class It , std::enable_if_t< detail::is_one_of_v< typename std::iterator_traits< It >::iterator_category, std::input_iterator_tag >, bool > = false> | |
| constexpr void | prepend (It first, It last) |
| Adds elements in the range [first, last) to the beginning of the container, as if by calling 'insert(begin(), first, last)'. More... | |
| template<class It , std::enable_if_t< std::is_convertible_v< typename std::iterator_traits< It >::iterator_category, std::forward_iterator_tag >, bool > = false> | |
| constexpr void | prepend (It first, It last) |
| Adds elements in the range [first, last) to the beginning of the container, as if by calling 'insert(begin(), first, last)'. More... | |
| constexpr void | shift_right (size_type count) |
| Modifies the underlying storage such that the starting index of the buffer is shifted right by 'count', without changing the order of the elements in the buffer. More... | |
| constexpr void | shift_left (size_type count) |
| Modifies the underlying storage such that the starting index of the buffer is shifted left by 'count', without changing the order of the elements in the buffer. More... | |
| constexpr shape_type | buffer_shape () const |
Returns a shape_type describing the layout of the buffer. | |
| constexpr void | swap (CircularBuffer &other) noexcept(propagate_on_container_swap||is_always_equal) |
| Exchanges the contents of the container with those of other. More... | |
Friends | |
| constexpr friend void | swap (CircularBuffer &l, CircularBuffer &r) noexcept(propagate_on_container_swap||is_always_equal) |
| Exchanges the contents of 'l' with those of 'r'. More... | |
| constexpr friend bool | operator== (const CircularBuffer &l, const CircularBuffer &r) |
| Checks if the contents of lhs and rhs are equal, that is, they have the same number of elements and each element in lhs compares equal with the element in rhs at the same position. More... | |
| constexpr friend bool | operator!= (const CircularBuffer &l, const CircularBuffer &r)=default |
| Checks if the contents of lhs and rhs are not equal, that is, they have a different number of elements or if any element in lhs compares not equal with the element in rhs at the same position. More... | |
A sequence container that encapsulates a resizable ring/circular buffer.
This type is similar to std::vector, supporting nearly every member function that std::vector has (with near identical semantics), except that the CircularBuffer supports additional operations and does not guarantee that its elements are stored contiguously.
The elements are stored in a contiguous underlying "physical" buffer but instead of storage always beginning at the start of the "physical" buffer, as is done with std::vector, instead the actual "logical" position of the beginning of the element storage may be at some offset into the physical buffer. Additionally, the "logical" end of the element storage may wrap around to the beginning of the "physical" buffer if the needed. This flexibility in the start and end of the buffer allows for elements to be more efficiently moved around in storage when performing certain operations. For example inserting elements near the front of a std::vector's storage, say at index 2, would require moving all elements after
index 2, whereas with CircularBuffer, only those 2 elements preceding the element at index 2 would need to be moved to make room for the insertion (assuming no reallocation takes place). This flexibility also allows for more efficient implementations of other operations, such as erasure (including a faster 'erase_if()'), prepending elements, condition. This efficiency comes at the price of CircularBuffer being larger than an efficiently-implemented std::vector by additional pointer-sized member, as well as slightly more costly traversal of the stored elements (e.g. "fat" iterators that are about the size of 3 pointers).
CircularBuffer efficiently support additional operations that std::vector does not, such as push_front()/pop_front(), and "shifting" of logical elements' positions in the physical storage.
| T | The type of the elements. |
| Allocator | An allocator that is used to acquire/release memory and to construct/destroy the elements in that memory. The type must meet the requirements of Allocator. The program is ill-formed (since C++20) if Allocator::value_type is not the same as T. |
|
inlineconstexpr |
Destroys all elements in the container and releases all memory allocated.
|
inlineconstexprnoexcept |
Constructs an empty container with the given allocator alloc.
| al | The allocator to construct the new buffer with. |
|
inlineconstexpr |
Constructs a copy of 'other' with the given allocator 'al' using the method specified by 'tag'.
If 'tag' has type 'tags::PreserveBufferLayout', then new buffer will have the same 'capacity()' and 'begin_index()' as the old buffer. If 'tag' has type 'tags::PreserveBufferCapacity', then new buffer will have the same 'capacity()' as the old buffer, with unspecified 'begin_index()'. If 'tag' has type 'tags::Optimized', then new buffer will reserve an implementation-defined amount of memory. In practice, this is only enough memory to fit the elements in 'other'.
| tag | Tag object controlling how the copy operation is to take place; one of tags::optimized, tags::preserve_layout, or tags::preserve_capacity. |
| other | The circular buffer whose contents are to be copied. |
| al | The allocator to construct the new buffer with. |
|
inlineconstexpr |
Constructs a copy of 'other' using the method specified by 'tag'.
If 'tag' has type 'tags::PreserveBufferLayout', then new buffer will have the same 'capacity()' and 'begin_index()' as the old buffer. If 'tag' has type 'tags::PreserveBufferCapacity', then new buffer will have the same 'capacity()' as the old buffer, with unspecified 'begin_index()'. If 'tag' has type 'tags::Optimized', then new buffer will reserve only enough memory to fit the elements in 'other'.
The allocator of the new buffer is determined as if by calling 'other.get_allocator().select_on_container_copy_construction()'.
| tag | Tag object controlling how the copy operation is to take place; one of tags::optimized, tags::preserve_layout, or tags::preserve_capacity. |
| other | The circular buffer whose contents are to be copied. |
|
inlineconstexpr |
Constructs a copy of 'other' with the given allocator 'al' as if by calling 'CircularBuffer(tags::optimized, other, al)'.
| tag | Tag object controlling how the copy operation is to take place; one of tags::optimized, tags::preserve_layout, or tags::preserve_capacity. |
| other | The circular buffer whose contents are to be copied. |
|
inlineconstexprnoexcept |
Move constructor.
Constructs the container with the contents of other using move semantics. Allocator is obtained by move-construction from the allocator belonging to other. After the move, other is guaranteed to be empty().
| other | The circular buffer whose contents are to be moved. |
|
inlineconstexpr |
Tagged move constructor.
Constructs the container with the contents of other using move semantics. Allocator is obtained by move-construction from the allocator belonging to other. After the move, other is guaranteed to be empty(). Move-constructs a copy of 'other' using the method specified by 'tag'. If 'tag' has type 'tags::PreserveBufferLayout', then new buffer will have the same 'capacity()' and 'begin_index()' as the old buffer. If 'tag' has type 'tags::PreserveBufferCapacity', then new buffer will have the same 'capacity()' as the old buffer, with unspecified 'begin_index()'. If 'tag' has type 'tags::Optimized', then new buffer will reserve only enough memory to fit the elements in 'other'.
| tag | Tag object controlling how the copy operation is to take place; one of tags::optimized, tags::preserve_layout, or tags::preserve_capacity. |
| other | The circular buffer whose contents are to be moved. |
|
inlineconstexpr |
Tagged move constructor with custom allocator.
Constructs the container with the contents of other using move semantics. Allocator is obtained from the parameter 'al'. After the move, other is guaranteed to be empty(). Move-constructs a copy of 'other' using the method specified by 'tag'. If the passed-in allocator is equal to the allocator used by 'other' (determined by calling operator==() or if std::allocator_traits<Allocator>::is_always_equal is true), then this overload proceeds similarly to 'CircularBuffer(TagType tag, CircularBuffer&& other)'. That is, no new memory is allocated and instead the new buffer takes ownership of the memory from 'other'. Otherwise, if the allocators are not equal, then 'al' is used to initialize the new buffer's allocator, and the elements from 'other' are moved into the new storage. If 'tag' has type 'tags::PreserveBufferLayout', then new buffer will have the same 'capacity()' and 'begin_index()' as the old buffer. If 'tag' has type 'tags::PreserveBufferCapacity', then new buffer will have the same 'capacity()' as the old buffer, with unspecified 'begin_index()'. If 'tag' has type 'tags::Optimized', then new buffer will reserve only enough memory to fit the elements in 'other'.
| tag | Tag object controlling how the copy operation is to take place; one of tags::optimized, tags::preserve_layout, or tags::preserve_capacity. |
| other | The circular buffer whose contents are to be moved. |
| al | The allocator to use for the new buffer. |
|
inlineconstexprnoexcept |
Move constructor with custom allocator.
Constructs the container with the contents of other using move semantics. Allocator is obtained from the parameter 'al'. After the move, other is guaranteed to be empty(). If the passed-in allocator is equal to the allocator used by 'other' (determined by calling operator==() or if std::allocator_traits<Allocator>::is_always_equal is true), then this overload proceeds similarly to 'CircularBuffer(CircularBuffer&& other)'. That is, no new memory is allocated and instead the new buffer takes ownership of the memory from 'other'. Otherwise, if the allocators are not equal, then 'al' is used to initialize the new buffer's allocator, and the elements from 'other' are moved into the new storage.
| other | The circular buffer whose contents are to be moved. |
| al | The allocator to use for the new buffer. |
|
inlineconstexprnoexcept |
Shape constructor.
Constructs an empty buffer with a predefined 'capacity()' and 'begin_index()'
| shape | The shape object definining the initial layout of the new buffer. |
| al | The allocator to use for the new buffer. |
|
inlineconstexpr |
Initializer list constructor.
Constructs the container with the contents of the initializer list 'init'.
| init | The initializer list whose contents are used to initialize the buffer. |
| al | The allocator to use for the new buffer. |
|
inlineexplicit |
Constructs the container with 'count' copies of elements with value 'value'.
| count | The number of elements to construct. |
| value | The object whose value is used to initialize the new elements. |
| al | The allocator to use for the new buffer. |
|
inlineexplicitconstexpr |
Constructs the container with 'count' default-consrtucted elements.
| count | The number of elements to construct. |
| al | The allocator to use for the new buffer. |
|
inlineconstexpr |
Constructs the container with the contents of the range [first, last).
| first | Iterator to the first element in the range to construct the buffer from. |
| last | Iterator to the past-the-end element in the range to construct the buffer from. |
| al | The allocator to use for the new buffer. |
|
inlineconstexpr |
Constructs the container with the contents of the range [first, last).
| first | Iterator to the first element in the range to construct the buffer from. |
| last | Iterator to the past-the-end element in the range to construct the buffer from. |
| al | The allocator to use for the new buffer. |
|
inlineconstexpr |
Copy constructor. Constructs the container with the copy of the contents of other.
| other | CircularBuffer whose contents are to be copied. |
|
inlineconstexpr |
Adds elements in the range [first, last) to the end of the container, as if by calling 'v.insert(v.end(), first, last)'.
| first | Iterator to the first element in the range of values to append. |
| last | The past-the-end iterator for the range of values to append. |
|
inlineconstexpr |
Adds elements in the range [first, last) to the end of the container, as if by calling 'insert(end(), first, last)'.
| first | Iterator to the first element in the range of values to append. |
| last | The past-the-end iterator for the range of values to append. |
|
inlineconstexpr |
Replaces the contents with copies of those in the range [first, last).
| first | Iterator to the first value in the range of elements to be copied. |
| last | Iterator to one past the last value in the range of elements to be copied. |
|
inlineconstexpr |
Replaces the contents with count copies of value value.
| count | The number of elements to assign. |
| value | The object to copy-initialize the new elements from. |
|
inlineconstexpr |
Replaces the contents with the elements from the initializer list 'init'.
| init | The initializer list whose contents are used to assign the buffer. |
|
inlineconstexpr |
Returns a mutable reference to the element at specified location 'index', with bounds checking.
If 'index' is not within the range of the container, an exception of type std::out_of_range is thrown.
| index | The index into the logical buffer of the element to access. |
|
inlineconstexpr |
Returns a const reference to the element at specified location 'index', with bounds checking.
If 'index' is not within the range of the container, an exception of type std::out_of_range is thrown.
| index | The index into the logical buffer of the element to access. |
|
inlineconstexpr |
Returns a mutable reference to the last element in the container.
Calling back on an empty container is undefined.
|
inlineconstexpr |
Returns a const reference to the last element in the container.
Calling back on an empty container is undefined.
|
inlineconstexprnoexcept |
Returns a const iterator to the element following the last element of the buffer.
This element acts as a placeholder; attempting to access it results in undefined behavior.
|
inlineconstexprnoexcept |
Erases all elements from the container.
After this call, size() returns zero. Invalidates any references, pointers, or iterators referring to contained elements. Any past-the-end iterators are also invalidated.
Leaves the capacity() of the buffer unchanged.
|
inlineconstexprnoexcept |
Returns a const reverse iterator to the first element of the reversed buffer.
It corresponds to the last element of the non-reversed buffer. If the buffer is empty, the returned iterator is equal to rend().
|
inlineconstexprnoexcept |
Returns a const reverse iterator to the element following the last element of the reversed buffer.
It corresponds to the element preceding the first element of the non-reversed buffer. This element acts as a placeholder, attempting to access it results in undefined behavior.
|
inlineconstexpr |
Emplaces the given element before pos.
If the number of elements before pos is less than the number of elements after pos, then the new value is emplaced as if by calling emplace_move_front(), otherwise they are inserted as if by emplace_move_back().
| pos | Iterator before which the content will be inserted. pos may be the end() iterator. |
| args | Arguments with which the new element is to be constructed. |
|
inlineconstexpr |
Emplaces the given element at the past-the-end position in the buffer.
| args | Arguments with which the new element is to be constructed. |
|
inlineconstexpr |
Emplaces the given element at the beginning of the buffer.
| args | Arguments with which the new element is to be constructed. |
|
inlineconstexpr |
Emplaces the given element before pos. Elements in the range [pos, end()) are moved to make room for the to-be-inserted range.
| pos | Iterator before which the content will be inserted. pos may be the end() iterator. |
| args | Arguments with which the new element is to be constructed. |
|
inlineconstexpr |
Emplaces the given element before pos. Elements in the range [begin(), pos) are moved to make room for the to-be-inserted range.
| pos | Iterator before which the content will be inserted. pos may be the end() iterator. |
| args | Arguments with which the new element is to be constructed. |
|
inlineconstexprnoexcept |
|
inlineconstexprnoexcept |
Returns a const iterator to the element following the last element of the buffer.
This element acts as a placeholder; attempting to access it results in undefined behavior.
|
inlineconstexprnoexcept |
Returns a mutable iterator to the element following the last element of the buffer.
This element acts as a placeholder; attempting to access it results in undefined behavior.
|
inlineconstexpr |
Returns the index into the raw memory buffer of the element following the last element in the buffer.
If the buffer is either empty or at capacity, this is equal to begin_index().
|
inlineconstexpr |
Removes the element at 'pos'.
If std::distance(begin(), pos) < std::distance(pos, end()) then the element is erased as if by calling erase_move_front(), otherwise the erasure proceeds as if by calling erase_move_back(). If std::distance(begin(), pos) < std::distance(pos, end()), then iterators and references at or before the point of the erasure are invalidated, otherwise iterators and references at or after the point of the erasure are invalidated. Additionally, if begin_index() after calling this function is less than its value before calling the function, then all iterators (but not necessarily references) are invalidated. The iterator pos must be valid and dereferenceable. Thus the end() iterator (which is valid, but is not dereferenceable) cannot be used as a value for pos.
| pos | Iterator to the to-be-erased element. |
|
inlineconstexpr |
Removes the elements in the range [first, last).
If std::distance(begin(), first) < std::distance(last, end()) then the element is erased as if by calling erase_move_front(), otherwise the erasure proceeds as if by calling erase_move_back(). If std::distance(begin(), first) < std::distance(last, end()), then iterators and references at or before the point of the erasure are invalidated, otherwise iterators and references at or after the point of the erasure are invalidated. Additionally, if begin_index() after calling this function is less than its value before calling the function, then all iterators (but not necessarily references) are invalidated. The iterator pos must be valid and dereferenceable. Thus the end() iterator (which is valid, but is not dereferenceable) cannot be used as a value for 'first' unless 'first == last'.
| first | Iterator to beginning of the to-be-erased erased. |
| last | Iterator past the last element of the to-be-erased erased. |
|
inlineconstexpr |
Erases all elements for which 'pred' returns true.
| pred | Predicate function object which returns 'true' for elements that should be erased. |
|
inlineconstexpr |
Removes the element at 'pos'.
Elements in the range [pos, end()) are shifted to occupy the erased space.
Iterators and references at or after the point of the erasure are invalidated. The iterator pos must be valid and dereferenceable. Thus the end() iterator (which is valid, but is not dereferenceable) cannot be used as a value for pos.
| pos | Iterator to the to-be-erased element. |
|
inlineconstexpr |
Removes the elements in the range [first, last). Elements in the range [last, end()) are shifted to occupy the erased space.
Iterators and references at or after the point of the erasure are invalidated. The iterator pos must be valid and dereferenceable. Thus the end() iterator (which is valid, but is not dereferenceable) cannot be used as a value for 'first' unless 'first == last'.
| first | Iterator to beginning of the to-be-erased erased. |
| last | Iterator past the last element of the to-be-erased erased. |
|
inlineconstexpr |
Removes the element at 'pos'.
Elements in the range [begin(), pos) are shifted to occupy the erased space.
Iterators and references at or before the point of the erasure are invalidated. Additionally, if begin_index() after calling this function is less than its value before calling the function, then all iterators (but not necessarily references) are invalidated. The iterator pos must be valid and dereferenceable. Thus the end() iterator (which is valid, but is not dereferenceable) cannot be used as a value for pos.
| pos | Iterator to the to-be-erased element. |
|
inlineconstexpr |
Removes the elements in the range [first, last). Elements in the range [begin(), pos) are shifted to occupy the erased space.
If std::distance(begin(), first) < std::distance(last, end()) then the element is erased as if by calling erase_move_front(), otherwise the erasure proceeds as if by calling erase_move_back(). If std::distance(begin(), first) < std::distance(last, end()), then iterators and references at or before the point of the erasure are invalidated, otherwise iterators and references at or after the point of the erasure are invalidated. Additionally, if begin_index() after calling this function is less than its value before calling the function, then all iterators (but not necessarily references) are invalidated. The iterator pos must be valid and dereferenceable. Thus the end() iterator (which is valid, but is not dereferenceable) cannot be used as a value for 'first' unless 'first == last'.
| first | Iterator to beginning of the to-be-erased erased. |
| last | Iterator past the last element of the to-be-erased erased. |
|
inlineconstexpr |
Returns a mutable reference to the first element in the container.
Calling front on an empty container is undefined.
|
inlineconstexpr |
Returns a const reference to the first element in the container.
Calling front on an empty container is undefined.
|
inlineconstexpr |
Inserts elements from range [first, last) before pos.
If the number of elements before pos is less than the number of elements after pos, then the new values are inserted as if by calling insert_move_front(), otherwise they are inserted as if by insert_move_back().
This overload only participates in overload resolution if InputIt qualifies as LegacyInputIterator. The behavior is undefined if first and last are iterators into *this.
| pos | Iterator before which the content will be inserted. pos may be the end() iterator. |
| first | Iterator to the first value in the range of elements to be inserted. |
| last | Iterator to one past the last value in the range of elements to be inserted. |
|
inlineconstexpr |
Inserts 'count' copies of the given element before pos.
If the number of elements before pos is less than the number of elements after pos, then the new values are inserted as if by calling insert_move_front(), otherwise they are inserted as if by insert_move_back().
This overload only participates in overload resolution if InputIt qualifies as LegacyInputIterator. The behavior is undefined if first and last are iterators into *this.
| pos | Iterator before which the content will be inserted. pos may be the end() iterator. |
| count | The number of elements to insert. |
| value | The value of the inserted elements. |
|
inlineconstexpr |
Inserts the elements from the initialize list before pos.
If the number of elements before pos is less than the number of elements after pos, then the new values are inserted as if by calling insert_move_front(), otherwise they are inserted as if by insert_move_back().
| pos | Iterator before which the content will be inserted. pos may be the end() iterator. |
| ilist | initializer list containing the elements to be inserted. |
|
inlineconstexpr |
Inserts the given element before pos.
If the number of elements before pos is less than the number of elements after pos, then the new value is inserted as if by calling insert_move_front(), otherwise they are inserted as if by insert_move_back().
This overload only participates in overload resolution if InputIt qualifies as LegacyInputIterator. The behavior is undefined if first and last are iterators into *this.
| pos | Iterator before which the content will be inserted. pos may be the end() iterator. |
| value | The value to insert. |
|
inlineconstexpr |
Inserts elements from range [first, last) before pos. Elements in the range [pos, end()) are moved to make room for the to-be-inserted range.
Note that this means the value of end_index() will change accordingly (but begin_index() will be unchanged).
This overload only participates in overload resolution if InputIt qualifies as LegacyInputIterator, but not LegacyForwardIterator.
| pos | Iterator before which the content will be inserted. pos may be the end() iterator. |
| first | Iterator to the first value in the range of elements to be inserted. |
| last | Iterator to one past the last value in the range of elements to be inserted. |
|
inlineconstexpr |
Inserts elements from range [first, last) before pos. Elements in the range [pos, end()) are moved to make room for the to-be-inserted range.
Note that this means the value of end_index() will change accordingly (but begin_index() will be unchanged).
This overload only participates in overload resolution if InputIt qualifies as LegacyForwardIterator. The behavior is undefined if first and last are iterators into *this.
| pos | Iterator before which the content will be inserted. pos may be the end() iterator. |
| first | Iterator to the first value in the range of elements to be inserted. |
| last | Iterator to one past the last value in the range of elements to be inserted. |
|
inlineconstexpr |
Inserts 'count' copies of the given element before pos. Elements in the range [pos, end()) are moved to make room for the to-be-inserted range.
Note that this means the value of end_index() will change accordingly (but begin_index() will be unchanged).
| pos | Iterator before which the content will be inserted. pos may be the end() iterator. |
| count | The number of elements to insert. |
| value | The value of the inserted elements. |
|
inlineconstexpr |
Inserts the elements from the initialize list before pos. Elements in the range [pos, end()) are moved to make room for the to-be-inserted range.
Note that this means the value of end_index() will change accordingly (but begin_index() will be unchanged).
| pos | Iterator before which the content will be inserted. pos may be the end() iterator. |
| ilist | Initializer list containing the elements to be inserted. |
|
inlineconstexpr |
Inserts the given element before pos. Elements in the range [pos, end()) are moved to make room for the to-be-inserted range.
Note that this means the value of end_index() will change accordingly (but begin_index() will be unchanged).
| pos | Iterator before which the content will be inserted. pos may be the end() iterator. |
| value | The value to insert. |
|
inlineconstexpr |
Inserts elements from range [first, last) before pos. Elements in the range [begin(), pos) are moved to make room for the to-be-inserted range.
Note that this means the value of begin_index() will change accordingly (but end_index() will be unchanged).
This overload only participates in overload resolution if InputIt qualifies as LegacyInputIterator, but not LegacyForwardIterator.
| pos | Iterator before which the content will be inserted. pos may be the end() iterator. |
| first | Iterator to the first value in the range of elements to be inserted. |
| last | Iterator to one past the last value in the range of elements to be inserted. |
|
inlineconstexpr |
Inserts elements from range [first, last) before pos. Elements in the range [begin(), pos) are moved to make room for the to-be-inserted range.
Note that this means the value of begin_index() will change accordingly.
This overload only participates in overload resolution if InputIt qualifies as LegacyForwardIterator. The behavior is undefined if first and last are iterators into *this.
| pos | Iterator before which the content will be inserted. pos may be the end() iterator. |
| first | Iterator to the first value in the range of elements to be inserted. |
| last | Iterator to one past the last value in the range of elements to be inserted. |
|
inlineconstexpr |
Inserts 'count' copies of the given element before pos. Elements in the range [begin(), pos) are moved to make room for the to-be-inserted range.
Note that this means the value of begin_index() will change accordingly.
| pos | Iterator before which the content will be inserted. pos may be the end() iterator. |
| count | The number of elements to insert. |
| value | The value of the inserted elements. |
|
inlineconstexpr |
Inserts the elements from the initialize list before pos. Elements in the range [begin(), pos) are moved to make room for the to-be-inserted range.
Note that this means the value of begin_index() will change accordingly.
| pos | Iterator before which the content will be inserted. pos may be the end() iterator. |
| ilist | Initializer list containing the elements to be inserted. |
|
inlineconstexpr |
Inserts the given element before pos. Elements in the range [begin(), pos) are moved to make room for the to-be-inserted ivalue.
Note that this means the value of begin_index() will change accordingly.
| pos | Iterator before which the content will be inserted. pos may be the end() iterator. |
| value | The value to insert. |
|
inlineconstexprnoexcept |
Returns the maximum number of elements the container is able to hold due to system or library implementation limitations, i.e. std::distance(begin(), end()) for the largest possible container.
|
inlineconstexprnoexcept |
|
inlineconstexpr |
Copy assignment operator. Replaces the contents with a copy of the contents of other.
| other | CircularBuffer whose contents are to be copied. |
|
inlineconstexpr |
Replaces the contents with those identified by initializer list 'init'.
| init | The initializer list whose contents are used to initialize the buffer. |
|
inlineconstexpr |
Returns a mutable reference to the element at specified location 'index'. No bounds checking is performed.
| index | The index into the logical buffer of the element to access. |
|
inlineconstexpr |
Returns a const reference to the element at specified location 'index'. No bounds checking is performed.
| index | The index into the logical buffer of the element to access. |
|
inlineconstexpr |
Removes the last element of the container.
Calling pop_back on an empty container results in undefined behavior. Iterators and references to the last element, as well as the end() iterator, are invalidated.
|
inlineconstexpr |
Removes the last 'count' elements from the container.
If 'count' is zero then there are no effects. If 'count' is non-zero, then calling pop_back_n on an empty container results in undefined behavior. Additionally, if 'count' is non-zero, iterators and references to the last 'count' elements, as well as the end() iterator, are invalidated.
|
inlineconstexpr |
Removes the first element of the container.
Calling pop_front on an empty container results in undefined behavior. If the new begin_index() is less than its previous value then all iterators and references are invalidated. Otherwise only iterators and references to the first element are invalidated.
|
inlineconstexpr |
Removes the first 'count' elements from the container.
If 'count' is zero then there are no effects. If 'count' is non-zero, then calling pop_front_n on an empty container results in undefined behavior. If the new begin_index() is less than its previous value then all iterators and references are invalidated. Otherwise only iterators and references to the first 'count' elements are invalidated.
|
inlineconstexpr |
Adds elements in the range [first, last) to the beginning of the container, as if by calling 'insert(begin(), first, last)'.
| first | Iterator to the first element in the range of values to prepend. |
| last | The past-the-end iterator for the range of values to prepend. |
|
inlineconstexpr |
Adds elements in the range [first, last) to the beginning of the container, as if by calling 'insert(begin(), first, last)'.
| first | Iterator to the first element in the range of values to prepend. |
| last | The past-the-end iterator for the range of values to prepend. |
|
inlineconstexpr |
Appends the given element value to the end of the container. The new element is initialized as a copy of value.
| value | The value of the element to append. |
|
inlineconstexpr |
Appends the given element value to the end of the container. 'value' is moved into the new element.
| value | The value of the element to append. |
|
inlineconstexpr |
Prepends the given element value to the beginning of the container. The new element is initialized as a copy of value.
| value | The value of the element to prepend. |
|
inlineconstexpr |
Prepends the given element value to the beginning of the container. The new element is initialized as a copy of value.
| value | The value of the element to prepend. |
|
inlineconstexprnoexcept |
Returns a const reverse iterator to the first element of the reversed buffer.
It corresponds to the last element of the non-reversed buffer. If the buffer is empty, the returned iterator is equal to rend().
|
inlineconstexprnoexcept |
Returns a mutable reverse iterator to the first element of the reversed buffer.
It corresponds to the last element of the non-reversed buffer. If the buffer is empty, the returned iterator is equal to rend().
|
inlineconstexprnoexcept |
Returns a const reverse iterator to the element following the last element of the reversed buffer.
It corresponds to the element preceding the first element of the non-reversed buffer. This element acts as a placeholder, attempting to access it results in undefined behavior.
|
inlineconstexprnoexcept |
Returns a mutable reverse iterator to the element following the last element of the reversed buffer.
It corresponds to the element preceding the first element of the non-reversed buffer. This element acts as a placeholder, attempting to access it results in undefined behavior.
|
inlineconstexpr |
Increase the capacity of the buffer to a value that's greater or equal to new_cap.
If new_cap is greater than the current capacity(), new storage is allocated, otherwise the method does nothing. reserve() does not change the size of the buffer. If new_cap is greater than capacity(), all iterators, including the past-the-end iterator, and all references to the elements are invalidated. Otherwise, no iterators or references are invalidated.
| new_cap | New capacity of the buffer. |
|
inlineconstexpr |
Resizes the container to contain count elements.
If the current size is greater than count, the container is reduced to its first count elements. If the current size is less than count, additional default-inserted elements are appended.
| count | The new size of the container. |
|
inlineconstexpr |
Resizes the container to contain count elements.
If the current size is greater than count, the container is reduced to its first count elements. If the current size is less than count, additional copies of 'value' are appended.
| count | The new size of the container. |
| value | The value to initialize the new elements with. |
|
inlineconstexpr |
Resizes the container to contain count elements.
If the current size is greater than count, the container is reduced to its last count elements. If the current size is less than count, additional default-inserted elements are prepended.
| count | The new size of the container. |
|
inlineconstexpr |
Resizes the container to contain count elements.
If the current size is greater than count, the container is reduced to its last count elements. If the current size is less than count, additional copies of 'value' are prepended.
| count | The new size of the container. |
| value | The value to initialize the new elements with. |
|
inlineconstexpr |
Modifies the underlying storage such that the starting index of the buffer is shifted left by 'count', without changing the order of the elements in the buffer.
Example: Underlying storage before shifting: [-, -, -, a, b, c, d, -, -] ^ begin_index() == 3 Underlying storage after shifting left by 2: [-, a, b, c, d, -, -, -, -] ^ begin_index() == 1
| count | The number of elements to shift the buffer left by. |
|
inlineconstexpr |
Modifies the underlying storage such that the starting index of the buffer is shifted right by 'count', without changing the order of the elements in the buffer.
Example: Underlying storage before shifting: [-, a, b, c, d, -, -, -, -] ^ begin_index() == 1 Underlying storage after shifting right by 2: [-, -, -, a, b, c, d, -, -] ^ begin_index() == 3
| count | The number of elements to shift the buffer right by. |
|
inlineconstexpr |
Requests the removal of unused capacity.
It is a non-binding request to reduce capacity() to size(). It depends on the implementation whether the request is fulfilled. If reallocation occurs, all iterators, including the past the end iterator, and all references to the elements are invalidated. If no reallocation takes place, no iterators or references are invalidated.
|
inlineconstexprnoexcept |
Exchanges the contents of the container with those of other.
Does not invoke any move, copy, or swap operations on individual elements. All iterators and references remain valid. The past-the-end iterator is invalidated.
| other | The container to exchange the contents with. |
|
friend |
Checks if the contents of lhs and rhs are not equal, that is, they have a different number of elements or if any element in lhs compares not equal with the element in rhs at the same position.
| l | The first container whose contents will be compared. |
| r | The second container whose contents will be compared. |
|
friend |
Checks if the contents of lhs and rhs are equal, that is, they have the same number of elements and each element in lhs compares equal with the element in rhs at the same position.
| l | The first container whose contents will be compared. |
| r | The second container whose contents will be compared. |
|
friend |
Exchanges the contents of 'l' with those of 'r'.
Does not invoke any move, copy, or swap operations on individual elements. All iterators and references remain valid. The past-the-end iterator is invalidated.
| l | The first container whose contents will be exchanged. |
| r | The second container whose contents will be exchanged. |