My Project
Classes | Public Types | Public Member Functions | Friends | List of all members
tim::circular_buffer::CircularBuffer< T, Allocator > Struct Template Reference

A sequence container that encapsulates a resizable ring/circular buffer. More...

#include <tim/circular-buffer/CircularBuffer.hpp>

Inheritance diagram for tim::circular_buffer::CircularBuffer< T, Allocator >:

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 CircularBufferoperator= (const CircularBuffer &other)
 Copy assignment operator. Replaces the contents with a copy of the contents of other. More...
 
constexpr CircularBufferoperator= (CircularBuffer &&other) noexcept(propagate_on_container_move_assignment||is_always_equal)
 
constexpr CircularBufferoperator= (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...
 

Detailed Description

template<class T, class Allocator>
struct tim::circular_buffer::CircularBuffer< T, Allocator >

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.

Template Parameters
TThe type of the elements.
AllocatorAn 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.
Note
The requirements that are imposed on the elements depend on the actual operations performed on the container. Generally, it is required that element type meets the requirements of Erasable, but many member functions impose stricter requirements. This container (but not its members) can be instantiated with an incomplete element type if the allocator satisfies the allocator completeness requirements.
CircularBuffer is an AllocatorAwareContainer.

Constructor & Destructor Documentation

◆ ~CircularBuffer()

template<class T , class Allocator >
constexpr tim::circular_buffer::CircularBuffer< T, Allocator >::~CircularBuffer ( )
inlineconstexpr

Destroys all elements in the container and releases all memory allocated.

◆ CircularBuffer() [1/15]

template<class T , class Allocator >
constexpr tim::circular_buffer::CircularBuffer< T, Allocator >::CircularBuffer ( const Allocator &  al)
inlineconstexprnoexcept

Constructs an empty container with the given allocator alloc.

Parameters
alThe allocator to construct the new buffer with.

◆ CircularBuffer() [2/15]

template<class T , class Allocator >
template<class TagType , std::enable_if_t< detail::is_one_of_v< TagType, tags::PreserveBufferLayout, tags::PreserveBufferCapacity, tags::Optimized >, bool > = true>
constexpr tim::circular_buffer::CircularBuffer< T, Allocator >::CircularBuffer ( TagType  tag,
const CircularBuffer< T, Allocator > &  other,
const Allocator &  al 
)
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'.

Parameters
tagTag object controlling how the copy operation is to take place; one of tags::optimized, tags::preserve_layout, or tags::preserve_capacity.
otherThe circular buffer whose contents are to be copied.
alThe allocator to construct the new buffer with.

◆ CircularBuffer() [3/15]

template<class T , class Allocator >
template<class TagType , std::enable_if_t< detail::is_one_of_v< TagType, tags::PreserveBufferLayout, tags::PreserveBufferCapacity, tags::Optimized > > = true>
constexpr tim::circular_buffer::CircularBuffer< T, Allocator >::CircularBuffer ( TagType  tag,
const CircularBuffer< T, Allocator > &  other 
)
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()'.

Parameters
tagTag object controlling how the copy operation is to take place; one of tags::optimized, tags::preserve_layout, or tags::preserve_capacity.
otherThe circular buffer whose contents are to be copied.

◆ CircularBuffer() [4/15]

template<class T , class Allocator >
constexpr tim::circular_buffer::CircularBuffer< T, Allocator >::CircularBuffer ( const CircularBuffer< T, Allocator > &  other,
const Allocator &  al 
)
inlineconstexpr

Constructs a copy of 'other' with the given allocator 'al' as if by calling 'CircularBuffer(tags::optimized, other, al)'.

Parameters
tagTag object controlling how the copy operation is to take place; one of tags::optimized, tags::preserve_layout, or tags::preserve_capacity.
otherThe circular buffer whose contents are to be copied.

◆ CircularBuffer() [5/15]

template<class T , class Allocator >
constexpr tim::circular_buffer::CircularBuffer< T, Allocator >::CircularBuffer ( CircularBuffer< T, Allocator > &&  other)
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().

Parameters
otherThe circular buffer whose contents are to be moved.

◆ CircularBuffer() [6/15]

template<class T , class Allocator >
template<class TagType , std::enable_if_t< detail::is_one_of_v< TagType, tags::PreserveBufferLayout, tags::PreserveBufferCapacity, tags::Optimized > > = true>
constexpr tim::circular_buffer::CircularBuffer< T, Allocator >::CircularBuffer ( TagType  tag,
CircularBuffer< T, Allocator > &&  other 
)
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'.

Parameters
tagTag object controlling how the copy operation is to take place; one of tags::optimized, tags::preserve_layout, or tags::preserve_capacity.
otherThe circular buffer whose contents are to be moved.
Note
In practice, the 'tag' argument is ignored as the 'optimized' path is the same as the layout-preserving path and no memory is allocated.
This overload exists primarily to support perfect-forwarding in conjunction with the non-moving version.

◆ CircularBuffer() [7/15]

template<class T , class Allocator >
template<class TagType , std::enable_if_t< detail::is_one_of_v< TagType, tags::PreserveBufferLayout, tags::PreserveBufferCapacity, tags::Optimized > > = true>
constexpr tim::circular_buffer::CircularBuffer< T, Allocator >::CircularBuffer ( TagType  tag,
CircularBuffer< T, Allocator > &&  other,
const Allocator &  al 
)
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'.

Parameters
tagTag object controlling how the copy operation is to take place; one of tags::optimized, tags::preserve_layout, or tags::preserve_capacity.
otherThe circular buffer whose contents are to be moved.
alThe allocator to use for the new buffer.

◆ CircularBuffer() [8/15]

template<class T , class Allocator >
constexpr tim::circular_buffer::CircularBuffer< T, Allocator >::CircularBuffer ( CircularBuffer< T, Allocator > &&  other,
const Allocator &  alloc 
)
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.

Parameters
otherThe circular buffer whose contents are to be moved.
alThe allocator to use for the new buffer.

◆ CircularBuffer() [9/15]

template<class T , class Allocator >
constexpr tim::circular_buffer::CircularBuffer< T, Allocator >::CircularBuffer ( shape_type  shape,
const Allocator &  al 
)
inlineconstexprnoexcept

Shape constructor.

Constructs an empty buffer with a predefined 'capacity()' and 'begin_index()'

Parameters
shapeThe shape object definining the initial layout of the new buffer.
alThe allocator to use for the new buffer.

◆ CircularBuffer() [10/15]

template<class T , class Allocator >
constexpr tim::circular_buffer::CircularBuffer< T, Allocator >::CircularBuffer ( std::initializer_list< T >  init,
const Allocator &  alloc = Allocator() 
)
inlineconstexpr

Initializer list constructor.

Constructs the container with the contents of the initializer list 'init'.

Parameters
initThe initializer list whose contents are used to initialize the buffer.
alThe allocator to use for the new buffer.

◆ CircularBuffer() [11/15]

template<class T , class Allocator >
tim::circular_buffer::CircularBuffer< T, Allocator >::CircularBuffer ( size_type  count,
const value_type &  value,
const Allocator &  alloc = Allocator() 
)
inlineexplicit

Constructs the container with 'count' copies of elements with value 'value'.

Parameters
countThe number of elements to construct.
valueThe object whose value is used to initialize the new elements.
alThe allocator to use for the new buffer.

◆ CircularBuffer() [12/15]

template<class T , class Allocator >
constexpr tim::circular_buffer::CircularBuffer< T, Allocator >::CircularBuffer ( size_type  count,
const Allocator &  alloc = Allocator() 
)
inlineexplicitconstexpr

Constructs the container with 'count' default-consrtucted elements.

Parameters
countThe number of elements to construct.
alThe allocator to use for the new buffer.

◆ CircularBuffer() [13/15]

template<class T , class Allocator >
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 tim::circular_buffer::CircularBuffer< T, Allocator >::CircularBuffer ( It  first,
It  last,
const Allocator &  alloc = Allocator() 
)
inlineconstexpr

Constructs the container with the contents of the range [first, last).

Parameters
firstIterator to the first element in the range to construct the buffer from.
lastIterator to the past-the-end element in the range to construct the buffer from.
alThe allocator to use for the new buffer.

◆ CircularBuffer() [14/15]

template<class T , class Allocator >
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 tim::circular_buffer::CircularBuffer< T, Allocator >::CircularBuffer ( It  first,
It  last,
const Allocator &  alloc = Allocator() 
)
inlineconstexpr

Constructs the container with the contents of the range [first, last).

Parameters
firstIterator to the first element in the range to construct the buffer from.
lastIterator to the past-the-end element in the range to construct the buffer from.
alThe allocator to use for the new buffer.

◆ CircularBuffer() [15/15]

template<class T , class Allocator >
constexpr tim::circular_buffer::CircularBuffer< T, Allocator >::CircularBuffer ( const CircularBuffer< T, Allocator > &  other)
inlineconstexpr

Copy constructor. Constructs the container with the copy of the contents of other.

Parameters
otherCircularBuffer whose contents are to be copied.
Note
The copy constructor does not necessarily preserve the layout or capacity of the 'other'. If you require this behavior, consider using the tagged copy constructor.

Member Function Documentation

◆ append() [1/2]

template<class T , class Allocator >
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 tim::circular_buffer::CircularBuffer< T, Allocator >::append ( It  first,
It  last 
)
inlineconstexpr

Adds elements in the range [first, last) to the end of the container, as if by calling 'v.insert(v.end(), first, last)'.

Parameters
firstIterator to the first element in the range of values to append.
lastThe past-the-end iterator for the range of values to append.
Note
If an exception is thrown while copying elements in the range [first, last) to their destination location in the container, there are no effects.
If T's move constructor is not noexcept and T is not CopyInsertable into *this, the throwing move constructor will be used. If it throws, the guarantee is waived and the effects are unspecified.

◆ append() [2/2]

template<class T , class Allocator >
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 tim::circular_buffer::CircularBuffer< T, Allocator >::append ( It  first,
It  last 
)
inlineconstexpr

Adds elements in the range [first, last) to the end of the container, as if by calling 'insert(end(), first, last)'.

Parameters
firstIterator to the first element in the range of values to append.
lastThe past-the-end iterator for the range of values to append.
Note
If an exception is thrown while copying elements in the range [first, last) to their destination location in the container, there are no effects.
If T's move constructor is not noexcept and T is not CopyInsertable into *this, the throwing move constructor will be used. If it throws, the guarantee is waived and the effects are unspecified.

◆ assign() [1/3]

template<class T , class Allocator >
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 tim::circular_buffer::CircularBuffer< T, Allocator >::assign ( It  first,
It  last 
)
inlineconstexpr

Replaces the contents with copies of those in the range [first, last).

Parameters
firstIterator to the first value in the range of elements to be copied.
lastIterator to one past the last value in the range of elements to be copied.
Note
The behavior is undefined if either argument is an iterator into *this.

◆ assign() [2/3]

template<class T , class Allocator >
constexpr void tim::circular_buffer::CircularBuffer< T, Allocator >::assign ( size_type  count,
const T &  value 
)
inlineconstexpr

Replaces the contents with count copies of value value.

Parameters
countThe number of elements to assign.
valueThe object to copy-initialize the new elements from.

◆ assign() [3/3]

template<class T , class Allocator >
constexpr void tim::circular_buffer::CircularBuffer< T, Allocator >::assign ( std::initializer_list< T >  ilist)
inlineconstexpr

Replaces the contents with the elements from the initializer list 'init'.

Parameters
initThe initializer list whose contents are used to assign the buffer.

◆ at() [1/2]

template<class T , class Allocator >
constexpr reference tim::circular_buffer::CircularBuffer< T, Allocator >::at ( size_type  index)
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.

Parameters
indexThe index into the logical buffer of the element to access.

◆ at() [2/2]

template<class T , class Allocator >
constexpr const_reference tim::circular_buffer::CircularBuffer< T, Allocator >::at ( size_type  index) const
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.

Parameters
indexThe index into the logical buffer of the element to access.

◆ back() [1/2]

template<class T , class Allocator >
constexpr reference tim::circular_buffer::CircularBuffer< T, Allocator >::back ( )
inlineconstexpr

Returns a mutable reference to the last element in the container.

Calling back on an empty container is undefined.

◆ back() [2/2]

template<class T , class Allocator >
constexpr const_reference tim::circular_buffer::CircularBuffer< T, Allocator >::back ( ) const
inlineconstexpr

Returns a const reference to the last element in the container.

Calling back on an empty container is undefined.

◆ cend()

template<class T , class Allocator >
constexpr const_iterator tim::circular_buffer::CircularBuffer< T, Allocator >::cend ( ) const
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.

◆ clear()

template<class T , class Allocator >
constexpr void tim::circular_buffer::CircularBuffer< T, Allocator >::clear ( )
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.

◆ crbegin()

template<class T , class Allocator >
constexpr const_reverse_iterator tim::circular_buffer::CircularBuffer< T, Allocator >::crbegin ( ) const
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().

◆ crend()

template<class T , class Allocator >
constexpr const_reverse_iterator tim::circular_buffer::CircularBuffer< T, Allocator >::crend ( ) const
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.

◆ emplace()

template<class T , class Allocator >
template<class ... Args>
constexpr iterator tim::circular_buffer::CircularBuffer< T, Allocator >::emplace ( const_iterator  pos,
Args &&...  args 
)
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().

Parameters
posIterator before which the content will be inserted. pos may be the end() iterator.
argsArguments with which the new element is to be constructed.
Note
The element is constructed through std::allocator_traits::construct, which typically uses placement-new to construct the element in-place at a location provided by the container. However, if the required location has been occupied by an existing element, the inserted element is constructed at another location at first, and then move assigned into the required location.
The arguments args... are forwarded to the constructor as std::forward<Args>(args).... args... may directly or indirectly refer to a value in the container.
If the new size() is greater than capacity(), or if begin_index() after calling this function is greater than before the call, all iterators and references are invalidated. Otherwise, only the iterators and references before the insertion point remain valid. The past-the-end iterator is also invalidated.

◆ emplace_back()

template<class T , class Allocator >
template<class ... Args>
constexpr reference tim::circular_buffer::CircularBuffer< T, Allocator >::emplace_back ( Args &&...  args)
inlineconstexpr

Emplaces the given element at the past-the-end position in the buffer.

Parameters
argsArguments with which the new element is to be constructed.
Note
The element is constructed through std::allocator_traits::construct, which typically uses placement-new to construct the element in-place.
The arguments args... are forwarded to the constructor as std::forward<Args>(args).... args... may directly or indirectly refer to a value in the container.
If the new size() is greater than capacity(), all iterators and references are invalidated. Otherwise, only the iterators and references before the insertion point remain valid. The past-the-end iterator is also invalidated.

◆ emplace_front()

template<class T , class Allocator >
template<class ... Args>
constexpr reference tim::circular_buffer::CircularBuffer< T, Allocator >::emplace_front ( Args &&...  args)
inlineconstexpr

Emplaces the given element at the beginning of the buffer.

Parameters
argsArguments with which the new element is to be constructed.
Note
The element is constructed through std::allocator_traits::construct, which typically uses placement-new to construct the element in-place.
The arguments args... are forwarded to the constructor as std::forward<Args>(args).... args... may directly or indirectly refer to a value in the container.
If the new size() is greater than capacity(), or if begin_index() after calling this function is greater than before the call, all iterators and references are invalidated.

◆ emplace_move_back()

template<class T , class Allocator >
template<class ... Args>
constexpr iterator tim::circular_buffer::CircularBuffer< T, Allocator >::emplace_move_back ( const_iterator  pos,
Args &&...  args 
)
inlineconstexpr

Emplaces the given element before pos. Elements in the range [pos, end()) are moved to make room for the to-be-inserted range.

Parameters
posIterator before which the content will be inserted. pos may be the end() iterator.
argsArguments with which the new element is to be constructed.
Note
The element is constructed through std::allocator_traits::construct, which typically uses placement-new to construct the element in-place at a location provided by the container. However, if the required location has been occupied by an existing element, the inserted element is constructed at another location at first, and then move assigned into the required location.
The arguments args... are forwarded to the constructor as std::forward<Args>(args).... args... may directly or indirectly refer to a value in the container.
If the new size() is greater than capacity() all iterators and references are invalidated. Otherwise, only the iterators and references before the insertion point remain valid. The past-the-end iterator is also invalidated.

◆ emplace_move_front()

template<class T , class Allocator >
template<class ... Args>
constexpr iterator tim::circular_buffer::CircularBuffer< T, Allocator >::emplace_move_front ( const_iterator  pos,
Args &&...  args 
)
inlineconstexpr

Emplaces the given element before pos. Elements in the range [begin(), pos) are moved to make room for the to-be-inserted range.

Parameters
posIterator before which the content will be inserted. pos may be the end() iterator.
argsArguments with which the new element is to be constructed.
Note
The element is constructed through std::allocator_traits::construct, which typically uses placement-new to construct the element in-place at a location provided by the container. However, if the required location has been occupied by an existing element, the inserted element is constructed at another location at first, and then move assigned into the required location.
The arguments args... are forwarded to the constructor as std::forward<Args>(args).... args... may directly or indirectly refer to a value in the container.
If the new size() is greater than capacity(), or if begin_index() after calling this function is greater than before the call, all iterators and references are invalidated. Otherwise, only the iterators and references after the insertion point remain valid.

◆ empty()

template<class T , class Allocator >
constexpr bool tim::circular_buffer::CircularBuffer< T, Allocator >::empty ( ) const
inlineconstexprnoexcept

Checks if the container has no elements, i.e. whether begin() == end().

Returns
true if the container is empty, false otherwise

◆ end() [1/2]

template<class T , class Allocator >
constexpr const_iterator tim::circular_buffer::CircularBuffer< T, Allocator >::end ( ) const
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.

◆ end() [2/2]

template<class T , class Allocator >
constexpr iterator tim::circular_buffer::CircularBuffer< T, Allocator >::end ( )
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.

◆ end_index()

template<class T , class Allocator >
constexpr size_type tim::circular_buffer::CircularBuffer< T, Allocator >::end_index ( ) const
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().

◆ erase() [1/2]

template<class T , class Allocator >
constexpr iterator tim::circular_buffer::CircularBuffer< T, Allocator >::erase ( const_iterator  pos)
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.

Parameters
posIterator to the to-be-erased element.

◆ erase() [2/2]

template<class T , class Allocator >
constexpr iterator tim::circular_buffer::CircularBuffer< T, Allocator >::erase ( const_iterator  start,
const_iterator  stop 
)
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'.

Parameters
firstIterator to beginning of the to-be-erased erased.
lastIterator past the last element of the to-be-erased erased.

◆ erase_if()

template<class T , class Allocator >
template<class Pred >
constexpr size_type tim::circular_buffer::CircularBuffer< T, Allocator >::erase_if ( Pred  pred)
inlineconstexpr

Erases all elements for which 'pred' returns true.

Parameters
predPredicate function object which returns 'true' for elements that should be erased.
Note
After calling this function, the values of begin_index() and end_index() are unspecified.
The expression pred(v) must be convertible to bool for every argument v of type (possibly const) T, regardless of value category, and must not modify v. Thus, a parameter type of T& is not allowed, nor is T unless for T a move is equivalent to a copy.

◆ erase_move_back() [1/2]

template<class T , class Allocator >
constexpr iterator tim::circular_buffer::CircularBuffer< T, Allocator >::erase_move_back ( const_iterator  pos)
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.

Parameters
posIterator to the to-be-erased element.

◆ erase_move_back() [2/2]

template<class T , class Allocator >
constexpr iterator tim::circular_buffer::CircularBuffer< T, Allocator >::erase_move_back ( const_iterator  start,
const_iterator  stop 
)
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'.

Parameters
firstIterator to beginning of the to-be-erased erased.
lastIterator past the last element of the to-be-erased erased.

◆ erase_move_front() [1/2]

template<class T , class Allocator >
constexpr iterator tim::circular_buffer::CircularBuffer< T, Allocator >::erase_move_front ( const_iterator  pos)
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.

Parameters
posIterator to the to-be-erased element.

◆ erase_move_front() [2/2]

template<class T , class Allocator >
constexpr iterator tim::circular_buffer::CircularBuffer< T, Allocator >::erase_move_front ( const_iterator  start,
const_iterator  stop 
)
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'.

Parameters
firstIterator to beginning of the to-be-erased erased.
lastIterator past the last element of the to-be-erased erased.

◆ front() [1/2]

template<class T , class Allocator >
constexpr reference tim::circular_buffer::CircularBuffer< T, Allocator >::front ( )
inlineconstexpr

Returns a mutable reference to the first element in the container.

Calling front on an empty container is undefined.

◆ front() [2/2]

template<class T , class Allocator >
constexpr const_reference tim::circular_buffer::CircularBuffer< T, Allocator >::front ( ) const
inlineconstexpr

Returns a const reference to the first element in the container.

Calling front on an empty container is undefined.

◆ insert() [1/4]

template<class T , class Allocator >
template<class It >
constexpr iterator tim::circular_buffer::CircularBuffer< T, Allocator >::insert ( const_iterator  pos,
It  first,
It  last 
)
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.

Parameters
posIterator before which the content will be inserted. pos may be the end() iterator.
firstIterator to the first value in the range of elements to be inserted.
lastIterator to one past the last value in the range of elements to be inserted.

◆ insert() [2/4]

template<class T , class Allocator >
constexpr iterator tim::circular_buffer::CircularBuffer< T, Allocator >::insert ( const_iterator  pos,
size_type  count,
const T &  value 
)
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.

Parameters
posIterator before which the content will be inserted. pos may be the end() iterator.
countThe number of elements to insert.
valueThe value of the inserted elements.

◆ insert() [3/4]

template<class T , class Allocator >
constexpr iterator tim::circular_buffer::CircularBuffer< T, Allocator >::insert ( const_iterator  pos,
std::initializer_list< T >  ilist 
)
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().

Parameters
posIterator before which the content will be inserted. pos may be the end() iterator.
ilistinitializer list containing the elements to be inserted.

◆ insert() [4/4]

template<class T , class Allocator >
template<class U , std::enable_if_t< std::is_same_v< T, std::remove_cvref_t< U > >, bool > = true>
constexpr iterator tim::circular_buffer::CircularBuffer< T, Allocator >::insert ( const_iterator  pos,
U &&  value 
)
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.

Parameters
posIterator before which the content will be inserted. pos may be the end() iterator.
valueThe value to insert.

◆ insert_move_back() [1/5]

template<class T , class Allocator >
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 tim::circular_buffer::CircularBuffer< T, Allocator >::insert_move_back ( const_iterator  pos,
It  first,
It  last 
)
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.

Parameters
posIterator before which the content will be inserted. pos may be the end() iterator.
firstIterator to the first value in the range of elements to be inserted.
lastIterator to one past the last value in the range of elements to be inserted.
Note
If reallocation occurs, the values of begin_index() and end_index() are unspecified.

◆ insert_move_back() [2/5]

template<class T , class Allocator >
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 tim::circular_buffer::CircularBuffer< T, Allocator >::insert_move_back ( const_iterator  pos,
It  first,
It  last 
)
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.

Parameters
posIterator before which the content will be inserted. pos may be the end() iterator.
firstIterator to the first value in the range of elements to be inserted.
lastIterator to one past the last value in the range of elements to be inserted.
Note
If reallocation occurs, the values of begin_index() and end_index() are unspecified.

◆ insert_move_back() [3/5]

template<class T , class Allocator >
constexpr iterator tim::circular_buffer::CircularBuffer< T, Allocator >::insert_move_back ( const_iterator  pos,
size_type  count,
const T &  value 
)
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).

Parameters
posIterator before which the content will be inserted. pos may be the end() iterator.
countThe number of elements to insert.
valueThe value of the inserted elements.
Note
If reallocation occurs, the values of begin_index() and end_index() are unspecified.

◆ insert_move_back() [4/5]

template<class T , class Allocator >
constexpr iterator tim::circular_buffer::CircularBuffer< T, Allocator >::insert_move_back ( const_iterator  pos,
std::initializer_list< T >  ilist 
)
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).

Parameters
posIterator before which the content will be inserted. pos may be the end() iterator.
ilistInitializer list containing the elements to be inserted.
Note
If reallocation occurs, the values of begin_index() and end_index() are unspecified.

◆ insert_move_back() [5/5]

template<class T , class Allocator >
template<class U , std::enable_if_t< std::is_same_v< T, std::remove_cvref_t< U > >, bool > = true>
constexpr iterator tim::circular_buffer::CircularBuffer< T, Allocator >::insert_move_back ( const_iterator  pos,
U &&  value 
)
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).

Parameters
posIterator before which the content will be inserted. pos may be the end() iterator.
valueThe value to insert.
Note
If reallocation occurs, the values of begin_index() and end_index() are unspecified.

◆ insert_move_front() [1/5]

template<class T , class Allocator >
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 tim::circular_buffer::CircularBuffer< T, Allocator >::insert_move_front ( const_iterator  pos,
It  first,
It  last 
)
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.

Parameters
posIterator before which the content will be inserted. pos may be the end() iterator.
firstIterator to the first value in the range of elements to be inserted.
lastIterator to one past the last value in the range of elements to be inserted.
Note
If reallocation occurs, the values of begin_index() and end_index() are unspecified.

◆ insert_move_front() [2/5]

template<class T , class Allocator >
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 tim::circular_buffer::CircularBuffer< T, Allocator >::insert_move_front ( const_iterator  pos,
It  first,
It  last 
)
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.

Parameters
posIterator before which the content will be inserted. pos may be the end() iterator.
firstIterator to the first value in the range of elements to be inserted.
lastIterator to one past the last value in the range of elements to be inserted.
Note
If reallocation occurs, the values of begin_index() and end_index() are unspecified.

◆ insert_move_front() [3/5]

template<class T , class Allocator >
constexpr iterator tim::circular_buffer::CircularBuffer< T, Allocator >::insert_move_front ( const_iterator  pos,
size_type  count,
const T &  value 
)
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.

Parameters
posIterator before which the content will be inserted. pos may be the end() iterator.
countThe number of elements to insert.
valueThe value of the inserted elements.
Note
If reallocation occurs, the values of begin_index() and end_index() are unspecified.

◆ insert_move_front() [4/5]

template<class T , class Allocator >
constexpr iterator tim::circular_buffer::CircularBuffer< T, Allocator >::insert_move_front ( const_iterator  pos,
std::initializer_list< T >  ilist 
)
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.

Parameters
posIterator before which the content will be inserted. pos may be the end() iterator.
ilistInitializer list containing the elements to be inserted.
Note
If reallocation occurs, the values of begin_index() and end_index() are unspecified.

◆ insert_move_front() [5/5]

template<class T , class Allocator >
template<class U , std::enable_if_t< std::is_same_v< T, std::remove_cvref_t< U > >, bool > = true>
constexpr iterator tim::circular_buffer::CircularBuffer< T, Allocator >::insert_move_front ( const_iterator  pos,
U &&  value 
)
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.

Parameters
posIterator before which the content will be inserted. pos may be the end() iterator.
valueThe value to insert.
Note
If reallocation occurs, the values of begin_index() and end_index() are unspecified.

◆ max_size()

template<class T , class Allocator >
constexpr size_type tim::circular_buffer::CircularBuffer< T, Allocator >::max_size ( ) const
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.

Note
This value typically reflects the theoretical limit on the size of the container, at most std::numeric_limits<difference_type>::max().
At runtime, the size of the container may be limited to a value smaller than max_size() by the amount of RAM available.

◆ operator=() [1/3]

template<class T , class Allocator >
constexpr CircularBuffer & tim::circular_buffer::CircularBuffer< T, Allocator >::operator= ( CircularBuffer< T, Allocator > &&  other)
inlineconstexprnoexcept
Parameters

◆ operator=() [2/3]

template<class T , class Allocator >
constexpr CircularBuffer & tim::circular_buffer::CircularBuffer< T, Allocator >::operator= ( const CircularBuffer< T, Allocator > &  other)
inlineconstexpr

Copy assignment operator. Replaces the contents with a copy of the contents of other.

Parameters
otherCircularBuffer whose contents are to be copied.
Note
If std::allocator_traits<allocator_type>::propagate_on_container_copy_assignment::value is true, the allocator of *this is replaced by a copy of that of other. If the allocator of *this after assignment would compare unequal to its old value, the old allocator is used to deallocate the memory, then the new allocator is used to allocate it before copying the elements. Otherwise, the memory owned by *this may be reused when possible. In any case, the elements originally belong to *this may be either destroyed or replaced by element-wise copy-assignment.

◆ operator=() [3/3]

template<class T , class Allocator >
constexpr CircularBuffer & tim::circular_buffer::CircularBuffer< T, Allocator >::operator= ( std::initializer_list< T >  init)
inlineconstexpr

Replaces the contents with those identified by initializer list 'init'.

Parameters
initThe initializer list whose contents are used to initialize the buffer.

◆ operator[]() [1/2]

template<class T , class Allocator >
constexpr reference tim::circular_buffer::CircularBuffer< T, Allocator >::operator[] ( size_type  index)
inlineconstexpr

Returns a mutable reference to the element at specified location 'index'. No bounds checking is performed.

Parameters
indexThe index into the logical buffer of the element to access.

◆ operator[]() [2/2]

template<class T , class Allocator >
constexpr const_reference tim::circular_buffer::CircularBuffer< T, Allocator >::operator[] ( size_type  index) const
inlineconstexpr

Returns a const reference to the element at specified location 'index'. No bounds checking is performed.

Parameters
indexThe index into the logical buffer of the element to access.

◆ pop_back()

template<class T , class Allocator >
constexpr void tim::circular_buffer::CircularBuffer< T, Allocator >::pop_back ( )
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.

◆ pop_back_n()

template<class T , class Allocator >
constexpr void tim::circular_buffer::CircularBuffer< T, Allocator >::pop_back_n ( size_type  count)
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.

◆ pop_front()

template<class T , class Allocator >
constexpr void tim::circular_buffer::CircularBuffer< T, Allocator >::pop_front ( )
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.

◆ pop_front_n()

template<class T , class Allocator >
constexpr void tim::circular_buffer::CircularBuffer< T, Allocator >::pop_front_n ( size_type  count)
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.

◆ prepend() [1/2]

template<class T , class Allocator >
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 tim::circular_buffer::CircularBuffer< T, Allocator >::prepend ( It  first,
It  last 
)
inlineconstexpr

Adds elements in the range [first, last) to the beginning of the container, as if by calling 'insert(begin(), first, last)'.

Parameters
firstIterator to the first element in the range of values to prepend.
lastThe past-the-end iterator for the range of values to prepend.
Note
If an exception is thrown while copying elements in the range [first, last) to their destination location in the container, there are no effects.
If T's move constructor is not noexcept and T is not CopyInsertable into *this, the throwing move constructor will be used. If it throws, the guarantee is waived and the effects are unspecified.
If the new size() is greater than capacity(), or if the new begin_index() is greater than its previous value, then all iterators and references are invalidated.

◆ prepend() [2/2]

template<class T , class Allocator >
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 tim::circular_buffer::CircularBuffer< T, Allocator >::prepend ( It  first,
It  last 
)
inlineconstexpr

Adds elements in the range [first, last) to the beginning of the container, as if by calling 'insert(begin(), first, last)'.

Parameters
firstIterator to the first element in the range of values to prepend.
lastThe past-the-end iterator for the range of values to prepend.
Note
If an exception is thrown while copying elements in the range [first, last) to their destination location in the container, there are no effects.
If T's move constructor is not noexcept and T is not CopyInsertable into *this, the throwing move constructor will be used. If it throws, the guarantee is waived and the effects are unspecified.
If the new size() is greater than capacity(), or if the new begin_index() is greater than its previous value, then all iterators and references are invalidated.

◆ push_back() [1/2]

template<class T , class Allocator >
constexpr void tim::circular_buffer::CircularBuffer< T, Allocator >::push_back ( const T &  value)
inlineconstexpr

Appends the given element value to the end of the container. The new element is initialized as a copy of value.

Parameters
valueThe value of the element to append.
Note
T must meet the requirements of CopyInsertable in order to use overload.
If the new size() is greater than capacity() then all iterators and references (including the past-the-end iterator) are invalidated. Otherwise only the past-the-end iterator is invalidated.

◆ push_back() [2/2]

template<class T , class Allocator >
constexpr void tim::circular_buffer::CircularBuffer< T, Allocator >::push_back ( T &&  value)
inlineconstexpr

Appends the given element value to the end of the container. 'value' is moved into the new element.

Parameters
valueThe value of the element to append.
Note
T must meet the requirements of MoveInsertable in order to use overload.
If the new size() is greater than capacity() then all iterators and references (including the past-the-end iterator) are invalidated. Otherwise only the past-the-end iterator is invalidated.
If an exception is thrown (which can be due to Allocator::allocate() or element copy/move constructor/assignment), this function has no effect (strong exception guarantee).
If T's move constructor is not noexcept and T is not CopyInsertable into *this, the implementation will use the throwing move constructor. If it throws, the guarantee is waived and the effects are unspecified.

◆ push_front() [1/2]

template<class T , class Allocator >
constexpr void tim::circular_buffer::CircularBuffer< T, Allocator >::push_front ( const T &  value)
inlineconstexpr

Prepends the given element value to the beginning of the container. The new element is initialized as a copy of value.

Parameters
valueThe value of the element to prepend.
Note
T must meet the requirements of CopyInsertable in order to use overload.
If the new size() is greater than capacity(), or if the new begin_index() is greater than its previous value, then all iterators and references are invalidated. Otherwise no iterators are invalidated.

◆ push_front() [2/2]

template<class T , class Allocator >
constexpr void tim::circular_buffer::CircularBuffer< T, Allocator >::push_front ( T &&  value)
inlineconstexpr

Prepends the given element value to the beginning of the container. The new element is initialized as a copy of value.

Parameters
valueThe value of the element to prepend.
Note
T must meet the requirements of CopyInsertable in order to use overload.
If the new size() is greater than capacity(), or if the new begin_index() is greater than its previous value, then all iterators and references are invalidated. Otherwise no iterators are invalidated.
If an exception is thrown (which can be due to Allocator::allocate() or element copy/move constructor/assignment), this function has no effect (strong exception guarantee).
If T's move constructor is not noexcept and T is not CopyInsertable into *this, the implementation will use the throwing move constructor. If it throws, the guarantee is waived and the effects are unspecified.

◆ rbegin() [1/2]

template<class T , class Allocator >
constexpr const_reverse_iterator tim::circular_buffer::CircularBuffer< T, Allocator >::rbegin ( ) const
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().

◆ rbegin() [2/2]

template<class T , class Allocator >
constexpr reverse_iterator tim::circular_buffer::CircularBuffer< T, Allocator >::rbegin ( )
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().

◆ rend() [1/2]

template<class T , class Allocator >
constexpr const_reverse_iterator tim::circular_buffer::CircularBuffer< T, Allocator >::rend ( ) const
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.

◆ rend() [2/2]

template<class T , class Allocator >
constexpr reverse_iterator tim::circular_buffer::CircularBuffer< T, Allocator >::rend ( )
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.

◆ reserve()

template<class T , class Allocator >
constexpr void tim::circular_buffer::CircularBuffer< T, Allocator >::reserve ( size_type  new_cap)
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.

Parameters
new_capNew capacity of the buffer.
Note
Calls to this overload always preserve the value of begin_index(); that is the extra capacity is always added on the end of the buffer.
See reserve_front() and reserve(size_type, size_type) for alternatives.

◆ resize() [1/2]

template<class T , class Allocator >
constexpr void tim::circular_buffer::CircularBuffer< T, Allocator >::resize ( size_type  count)
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.

Parameters
countThe new size of the container.
Note
T must meet the requirements of MoveInsertable and DefaultInsertable in order to use overload. If an exception is thrown, this function has no effect (strong exception guarantee).
If T's move constructor is not noexcept and T is not CopyInsertable into *this, the throwing move constructor will be used. If it throws, the guarantee is waived and the effects are unspecified.

◆ resize() [2/2]

template<class T , class Allocator >
constexpr void tim::circular_buffer::CircularBuffer< T, Allocator >::resize ( size_type  count,
const T &  value 
)
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.

Parameters
countThe new size of the container.
valueThe value to initialize the new elements with.
Note
T must meet the requirements of MoveInsertable and DefaultInsertable in order to use overload.
If an exception is thrown, this function has no effect (strong exception guarantee).

◆ resize_front() [1/2]

template<class T , class Allocator >
constexpr void tim::circular_buffer::CircularBuffer< T, Allocator >::resize_front ( size_type  count)
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.

Parameters
countThe new size of the container.
Note
T must meet the requirements of MoveInsertable and DefaultInsertable in order to use overload. If an exception is thrown, this function has no effect (strong exception guarantee).
If T's move constructor is not noexcept and T is not CopyInsertable into *this, the throwing move constructor will be used. If it throws, the guarantee is waived and the effects are unspecified.

◆ resize_front() [2/2]

template<class T , class Allocator >
constexpr void tim::circular_buffer::CircularBuffer< T, Allocator >::resize_front ( size_type  count,
const T &  value 
)
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.

Parameters
countThe new size of the container.
valueThe value to initialize the new elements with.
Note
T must meet the requirements of MoveInsertable and DefaultInsertable in order to use overload.
If an exception is thrown, this function has no effect (strong exception guarantee).

◆ shift_left()

template<class T , class Allocator >
constexpr void tim::circular_buffer::CircularBuffer< T, Allocator >::shift_left ( size_type  count)
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

Parameters
countThe number of elements to shift the buffer left by.
Note
If T is MoveInsertible and std::is_nothrow_move_constructible_v<T> is true, and std::is_nothrow_move_assignable_v<T> is true, this function throws only those exceptions thrown when move-constructing objects of type T using std::allocator_traits<Allocator>::construct(). Otherwise if T is MoveInsertible and CopyInsertible but has a throwing move constructor or move assignment operator, elements are shifted using copy construction and copy assignment. In both of the above two cases, the strong exception guarantee is maintained. Otherwise, if T is not CopyInsertible, the strong exception gaurantee is waived; elements are shifted using move construction and move assignment, but if an exception is thrown, the buffer will be left in a valid but unspecified state.
This function does not allocate, all data movement is done in-place.
This function makes O(this->size()) calls to T's move/copy constructor and assignment operator.

◆ shift_right()

template<class T , class Allocator >
constexpr void tim::circular_buffer::CircularBuffer< T, Allocator >::shift_right ( size_type  count)
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

Parameters
countThe number of elements to shift the buffer right by.
Note
If T is MoveInsertible and std::is_nothrow_move_constructible_v<T> is true, and std::is_nothrow_move_assignable_v<T> is true, this function throws only those exceptions thrown when move-constructing objects of type T using std::allocator_traits<Allocator>::construct(). Otherwise if T is MoveInsertible and CopyInsertible but has a throwing move constructor or move assignment operator, elements are shifted using copy construction and copy assignment. In both of the above two cases, the strong exception guarantee is maintained. Otherwise, if T is not CopyInsertible, the strong exception gaurantee is waived; elements are shifted using move construction and move assignment, but if an exception is thrown, the buffer will be left in a valid but unspecified state.
This function does not allocate, all data movement is done in-place.
This function makes O(this->size()) calls to T's move/copy constructor and assignment operator.

◆ shrink_to_fit()

template<class T , class Allocator >
constexpr void tim::circular_buffer::CircularBuffer< T, Allocator >::shrink_to_fit ( )
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.

Note
If an exception is thrown other than by T's move constructor, there are no effects.

◆ swap()

template<class T , class Allocator >
constexpr void tim::circular_buffer::CircularBuffer< T, Allocator >::swap ( CircularBuffer< T, Allocator > &  other)
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.

Parameters
otherThe container to exchange the contents with.
Note
If std::allocator_traits<allocator_type>::propagate_on_container_swap::value is true, then the allocators are exchanged using an unqualified call to non-member swap. Otherwise, they are not swapped (and if get_allocator() != other.get_allocator(), the behavior is undefined).

Friends And Related Function Documentation

◆ operator!=

template<class T , class Allocator >
constexpr friend bool operator!= ( const CircularBuffer< T, Allocator > &  l,
const CircularBuffer< T, Allocator > &  r 
)
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.

Parameters
lThe first container whose contents will be compared.
rThe second container whose contents will be compared.
Returns
false if the contents of the buffers are equal, true otherwise

◆ operator==

template<class T , class Allocator >
constexpr friend bool operator== ( const CircularBuffer< T, Allocator > &  l,
const CircularBuffer< T, Allocator > &  r 
)
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.

Parameters
lThe first container whose contents will be compared.
rThe second container whose contents will be compared.
Returns
true if the contents of the buffers are equal, false otherwise

◆ swap

template<class T , class Allocator >
constexpr friend void swap ( CircularBuffer< T, Allocator > &  l,
CircularBuffer< T, Allocator > &  r 
)
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.

Parameters
lThe first container whose contents will be exchanged.
rThe second container whose contents will be exchanged.
Note
If std::allocator_traits<allocator_type>::propagate_on_container_swap::value is true, then the allocators are exchanged using an unqualified call to non-member swap. Otherwise, they are not swapped (and if get_allocator() != other.get_allocator(), the behavior is undefined).

The documentation for this struct was generated from the following file: