Queue  1.0.0
A C++17 Library of various `queue` containers
circular_queue< T, Alloc > Class Template Reference

Fixed capacity, STL-style, templated circular buffer. More...

#include <circular_queue.h>

Classes

class  const_iterator
 constant iterator for the circular_queue class. More...
 
struct  const_queue_pointer
 constant pointer with parity More...
 
class  iterator
 iterator for the circular_queue class. More...
 
struct  queue_pointer
 pointer with parity More...
 

Public Types

using allocator_type = Alloc
 Type of object used to dynamically allocate memory.
 
using difference_type = ptrdiff_t
 A signed integral type, identical to:iterator_traits<iterator>::difference_type.
 
using size_type = size_t
 An unsigned integral type that can represent any non-negative value of difference_type.
 
using value_type = T
 The template parameter (T), representing the values stored in the container.
 
using pointer = T *
 For the default allocator: value_type*.
 
using const_pointer = const T *
 Type for pointer to constant T object.
 
using reference = T &
 Type for data references.
 
using const_reference = const T &
 Type for reference to constant T object.
 
using reverse_iterator = std::reverse_iterator< iterator >
 Type for reverse iterators.
 
using const_reverse_iterator = std::reverse_iterator< const_iterator >
 Type for constant reverse iterators.
 

Public Member Functions

Constructors

Methods to construct, destruct, and assign the container.

 circular_queue (size_type capacity, const allocator_type &alloc=allocator_type())
 Constructor. More...
 
 circular_queue (size_type capacity, const value_type &val, const allocator_type &alloc=allocator_type())
 fill constructor More...
 
template<class InputIterator >
 circular_queue (InputIterator first, InputIterator last, const allocator_type &alloc=allocator_type(), typename std::enable_if<!std::is_integral< InputIterator >::value >::type *=0)
 Range Constructor. More...
 
 circular_queue (std::initializer_list< value_type > il, const allocator_type &alloc=allocator_type())
 construct from initializer list More...
 
 circular_queue (const circular_queue &other)
 Copy Constructor. More...
 
 circular_queue (circular_queue &&other) noexcept
 move constructor More...
 
Destructor
virtual ~circular_queue ()
 destructor More...
 
Operators
circular_queueoperator= (const circular_queue &other)
 Assign content. More...
 
circular_queueoperator= (circular_queue &&other) noexcept
 Assign content. More...
 
circular_queueoperator= (std::initializer_list< value_type > il)
 Assign content. More...
 
reference operator[] (size_type n)
 Access element. More...
 
const_reference operator[] (size_type n) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
Iterators

Methods to construct iterators to the container.

iterator begin () noexcept
 Returns iterator to beginning. More...
 
const_iterator begin () const noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
iterator end () noexcept
 Returns iterator to end. More...
 
const_iterator end () const noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
reverse_iterator rbegin () noexcept
 Returns reverse iterator to beginning. More...
 
const_reverse_iterator rbegin () const noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
reverse_iterator rend () noexcept
 Returns reverse iterator to end. More...
 
const_reverse_iterator rend () const noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
const_iterator cbegin () const noexcept
 Returns constant iterator to beginning. More...
 
const_iterator cend () const noexcept
 Returns constant iterator to end. More...
 
const_reverse_iterator crbegin () const noexcept
 Returns constant iterator to beginning. More...
 
const_reverse_iterator crend () const noexcept
 Returns constant iterator to end. More...
 
Capacity

Methods to determine the capacity of the container

size_type size () const noexcept
 Return size. More...
 
size_type capacity () const noexcept
 Get buffer capacity. More...
 
size_type max_size () const noexcept
 Return maximum capacity. More...
 
bool empty () const noexcept
 Test whether container is empty. More...
 
bool full () const noexcept
 Test whether container is full. More...
 
void reserve (size_type n)
 Request a change in capacity. More...
 
void resize (size_type n, const value_type &val=value_type())
 Change size. More...
 
void shrink_to_fit ()
 Shrink container to fit. More...
 
Element Access

Members that provide access to individual elements contained withing the circular_queue

reference at (size_type n)
 Access element. More...
 
const_reference at (size_type n) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
reference front () noexcept
 Access first element. More...
 
const_reference front () const noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
reference back ()
 Access last element. More...
 
const_reference back () const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
Modifiers

Member functions that modify the container.

template<class InputIterator >
void assign (InputIterator first, InputIterator last)
 Assign container content range. More...
 
void assign (size_type n, const value_type &val)
 Assign container content by fill. More...
 
void assign (std::initializer_list< value_type > il)
 Assign container contents from initializer list. More...
 
void clear () noexcept
 Clear content. More...
 
void push_back (const value_type &val)
 Add element at the end. More...
 
void push_back (value_type &&val)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
void push_front (const value_type &val)
 Add element at beginning. More...
 
void push_front (value_type &&val)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
void pop_back () noexcept
 Delete last element. More...
 
void pop_front () noexcept
 Delete first element. More...
 
iterator insert (const_iterator position, const value_type &val)
 Insert (copy) single element. More...
 
iterator insert (const_iterator position, value_type &&val)
 Insert (move) single element. More...
 
iterator insert (const_iterator position, size_type n, const value_type &val)
 Insert (fill) elements. More...
 
template<class InputIterator >
iterator insert (const_iterator position, InputIterator first, InputIterator last)
 Insert (range) elements. More...
 
iterator insert (const_iterator position, std::initializer_list< value_type > il)
 Insert elements (initializer_list) More...
 
iterator erase (const_iterator position)
 Erase element. More...
 
iterator erase (const_iterator first, const_iterator last)
 Erase elements. More...
 
void swap (circular_queue &other) noexcept
 Swap content. More...
 
template<class... Args>
iterator emplace (const_iterator position, Args &&... args)
 Construct and insert element. More...
 
template<class... Args>
void emplace_front (Args &&... args)
 Construct and insert element at beginning. More...
 
template<class... Args>
void emplace_back (Args &&... args)
 Construct and insert element at the end. More...
 
Accessors

Access member objects of the container

allocator_type get_allocator () const noexcept
 Get allocator. More...
 
template<class copyFunctor >
auto copy (const_iterator first, const_iterator last, value_type *destination, copyFunctor cf) const -> decltype(cf((void *) destination,(void *) first.m_pointer.ptr,((last.m_pointer.ptr - first.m_pointer.ptr) *sizeof(value_type))))
 Copies range to destination buffer using provided copy function. More...
 

Protected Member Functions

queue_pointer increment (queue_pointer p, difference_type n) const noexcept
 increments a pointer More...
 
const_queue_pointer increment (const_queue_pointer p, difference_type n) const noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
queue_pointer decrement (queue_pointer p, difference_type n) const noexcept
 decrements a pointer More...
 
const_queue_pointer decrement (const_queue_pointer p, difference_type n, bool &parity) const noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
void reallocate (size_type n)
 moves the currently contained data to a new area with size n. More...
 
iterator swapDownTo (const_iterator position, size_type n) noexcept
 Swaps the back of the queue down to position with elements n positions away. More...
 
iterator swapUpToEnd (const_iterator position, size_type n) noexcept
 Moves the given position to the end of the queue by successively swapping it. More...
 

Protected Attributes

Alloc m_alloc
 Allocator class. NOT c-style malloc.
 
pointer m_data
 Pointer to the internal data array.
 
size_type m_capacity
 capacity of the buffer array.
 
queue_pointer m_head
 Points to the logical beginning of the buffer. No memory ownership!
 
queue_pointer m_tail
 Points to the logical end of the buffer. No memory ownership!
 

Detailed Description

template<class T, class Alloc = std::allocator<T>>
class circular_queue< T, Alloc >

Fixed capacity, STL-style, templated circular buffer.

see http://en.wikipedia.org/wiki/Circular_buffer for details of how circular buffers work.

This implementation shares many features of a double-ended queue. This structure allows for the individual elements to be accessed directly through random access iterators, with storage handled automatically by over-writing elements from the opposite end of the container as it grows. As long as elements are added consistently to EITHER the front or the back, once full, the container will expand by over-writing the oldest element. If elements are added to both sides of the buffer, the behavior is effectively user defined.

Therefore, the circular_queue provides a functionality similar to vectors, but with efficient insertion and deletion of elements also at the beginning of the sequence, and not only at its end. Also, like vectors (and unlike dequeues), all elements are stored in contiguous memory locations, and offset access IS allowed.

Both vectors and the circular_queue provide a very similar interface and can be used for similar purposes, but internally both work in quite different ways : While vectors use a single array that needs to be occasionally reallocated for growth, the elements of a circular_queue are over-written once the buffer reaches its maximum capacity, ensuring elements are inserted and accessed in constant time and with a uniform sequential interface (through iterators), as opposed to the vector's amortized constant time. This allows them to grow more efficiently under certain circumstances, especially with very long sequences, where reallocation's become more expensive, and real-time applications where stale data is not as useful as current data.

For operations that involve frequent insertion or removals of elements at positions other than the beginning or the end, circular_queues perform worse and have less consistent iterators and references than lists and forward lists.

This class can be moved very quickly (constant time). It may be slow to copy.
Container properties
Sequence
Elements in sequence containers are ordered in a strict linear sequence. Individual elements are accessed by their position in this sequence.
Fixed-capacity array
Allows direct access to any element in the sequence and provides fast addition / removal of elements at the beginning or the end of the sequence.
Allocator - aware
The container uses an allocator object to dynamically handle its storage needs.

Constructor & Destructor Documentation

◆ circular_queue() [1/6]

template<class T , class Alloc = std::allocator<T>>
circular_queue< T, Alloc >::circular_queue ( size_type  capacity,
const allocator_type alloc = allocator_type() 
)
inlineexplicit

Constructor.

Complexity: O(N) with buffer capacity (memory allocation).
Iterator Validity: N/A.
Data Races: N/A.
Exception Safety: Throws std::bad_alloc if allocation fails. In this case, no object is created.

Parameters
[in]capacitynumber of elements that can be stored in the queue.
[in]allocAllocator object. The container keeps and uses an internal copy of this allocator.

◆ circular_queue() [2/6]

template<class T , class Alloc = std::allocator<T>>
circular_queue< T, Alloc >::circular_queue ( size_type  capacity,
const value_type val,
const allocator_type alloc = allocator_type() 
)
inlineexplicit

fill constructor

Creates an array of size capacity and fills it with copies of val.
Complexity: O(N) with size.
Iterator Validity: N/A.
Data Races: N/A.
Exception Safety: Throws std::bad_alloc if allocation fails. In this case, no object is created.

Parameters
[in]valthis value will be copied into all the container elements.
[in]capacitysize of the container.
[in]allocAllocator object. The container keeps and uses an internal copy of this allocator.

◆ circular_queue() [3/6]

template<class T , class Alloc = std::allocator<T>>
template<class InputIterator >
circular_queue< T, Alloc >::circular_queue ( InputIterator  first,
InputIterator  last,
const allocator_type alloc = allocator_type(),
typename std::enable_if<!std::is_integral< InputIterator >::value >::type *  = 0 
)
inlineexplicit

Range Constructor.

Creates a container by copying the objects in the range of the InputIterators [first, last). The size and capacity of the container will be equal to the size of the range.
Complexity: O(N) with range.
Iterator Validity: No changes.
Data Races: N/A.
Exception Safety: Throws std::bad_alloc if allocation fails. In this case, no object is created.

Parameters
[in]firstiterator to the beginning of the range to copy.
[in]lastiterator to the end (one past the last element) of the range to copy.
[in]allocAllocator object. The container keeps and uses an internal copy of this allocator.

◆ circular_queue() [4/6]

template<class T , class Alloc = std::allocator<T>>
circular_queue< T, Alloc >::circular_queue ( std::initializer_list< value_type il,
const allocator_type alloc = allocator_type() 
)
inline

construct from initializer list

constructs the circular_queue by copying elements from the initializer_list. The size and capacity of the queue will be equal to the initializer_list size.
Complexity: Linear with size of il (constructions).
Iterator Validity: N/A.
Data Races: N/A.
Exception Safety: Throws std::bad_alloc if allocation fails. In this case, no object is created.

Parameters
[in]ilinitializer_list object.
[in]allocAllocator object. The container keeps and uses an internal copy of this

◆ circular_queue() [5/6]

template<class T , class Alloc = std::allocator<T>>
circular_queue< T, Alloc >::circular_queue ( const circular_queue< T, Alloc > &  other)
inline

Copy Constructor.

Creates a deep copy of another circular_queue.
Complexity: O(N) with buffer capacity (memory allocation/copy).
Iterator Validity: N/A.
Data Races: N/A.
Exception Safety: Throws std::bad_alloc if allocation fails. In this case, no object is created.

Parameters
[in]otherbuffer to be copied

◆ circular_queue() [6/6]

template<class T , class Alloc = std::allocator<T>>
circular_queue< T, Alloc >::circular_queue ( circular_queue< T, Alloc > &&  other)
inlinenoexcept

move constructor

constructs a circular_queue and obtains its resources by moving them from another instance.
Complexity: Constant.
Iterator Validity: All iterators to the other container are invalidated.
Data Races: Container other is modified.
Exception Safety: No-throw guarantee: this member function never throws exceptions.

Parameters
[in]othercircular_queue to be moved.

◆ ~circular_queue()

template<class T , class Alloc = std::allocator<T>>
virtual circular_queue< T, Alloc >::~circular_queue ( )
inlinevirtual

destructor

Yeah, you know what this is.

Member Function Documentation

◆ assign() [1/3]

template<class T , class Alloc = std::allocator<T>>
template<class InputIterator >
void circular_queue< T, Alloc >::assign ( InputIterator  first,
InputIterator  last 
)
inline

Assign container content range.

Assigns new contents to the container, replacing its current contents, and modifying its size and capacity accordingly.The new contents are elements constructed from each of the elements in the range between first and last, in the same order. The range used is [first, last).
Complexity: Linear in initial and final sizes (destructions, constructions).
Iterator Validity: All iterators are invalidated.
Data Races: The container and all elements are modified. All copied elements are accessed.
Exception Safety: Basic guarantee: if an exception is thrown, the container is in a valid state. If allocator_traits::construct is not supported with the appropriate arguments for the element constructions, or if the range specified by [first,last) is not valid, it causes undefined behavior. Throws std::length_error if first == last.

Parameters
[in]firstbeginning of the range to copy.
[in]lastend (exclusive) of the range to be copied.
See also
operator=

◆ assign() [2/3]

template<class T , class Alloc = std::allocator<T>>
void circular_queue< T, Alloc >::assign ( size_type  n,
const value_type val 
)
inline

Assign container content by fill.

Assigns new contents to the container, replacing its current contents, and modifying its size and capacity accordingly. The new contents are n elements, each initialized to a copy of val.
Complexity: Linear in initial and final sizes (destructions, constructions).
Iterator Validity: All iterators, pointers, and references are invalidated.
Data Races: The container and all elements are modified. All copied elements are accessed.
Exception Safety: Basic guarantee: if an exception is thrown, the container is in a valid state. If allocator_traits::construct is not supported with the appropriate arguments for the element constructions, or if the range specified by [first,last) is not valid, it causes undefined behavior. Throws std::length_error if first == last.

Parameters
[in]nnew container size
[in]valvalue to be copied into each element of the container.

◆ assign() [3/3]

template<class T , class Alloc = std::allocator<T>>
void circular_queue< T, Alloc >::assign ( std::initializer_list< value_type il)
inline

Assign container contents from initializer list.

Assigns new contents to the container, replacing its current contents, and modifying its size and capacity accordingly. The new contents are copies of the values passed as initializer list, in the same order.
Complexity: Linear in initial and final sizes (destructions, constructions).
Iterator Validity: All iterators, pointers and references related to this container are invalidated.
Data Races: All copied elements are accessed. The container is modified. All contained elements are modified.
Exception Safety: Basic guarantee: if an exception is thrown, the container is in a valid state. If allocator_traits::construct is not supported with the appropriate arguments for the element constructions it causes undefined behavior. If the initializer list is empty, std::length_error is thrown.

Parameters
[in]ilAn initializer_list object. The compiler will automatically construct such objects from initializer list declarators. Member type value_type is the type of the elements in the container, defined in circular_queue as an alias of its first template parameter (T).
See also
operator=

◆ at()

template<class T , class Alloc = std::allocator<T>>
reference circular_queue< T, Alloc >::at ( size_type  n)
inline

Access element.

Returns a reference to the element at position n in the container object. The function automatically checks whether n is within the bounds of valid elements in the container, throwing an out_of_range exception if it is not (i.e., if n is greater or equal than its size). This is in contrast with member operator[], that does not check against bounds.
Complexity: Constant.
Iterator Validity: .
Data Races: .
Exception Safety: .

Parameters
[in]nPosition of an element in the container. If this is greater than the container size, an exception of type out_of_range is thrown. Notice that the first element has a position of 0 (not 1). Member type size_type is an unsigned integral type.
Returns
The element at the specified position in the container. If the circular_queue object is const-qualified, the function returns a const_reference. Otherwise, it returns a reference.

◆ back()

template<class T , class Alloc = std::allocator<T>>
reference circular_queue< T, Alloc >::back ( )
inline

Access last element.

Returns a reference to the last element in the circular_queue. Unlike member end(), which returns an iterator just past this element, this function returns a direct reference. Calling this function on an empty container causes undefined behavior.
Complexity: Constant.
Iterator Validity: No changes.
Data Races: The container is accessed (neither the const nor the non-const versions modify the container). The reference returned can be used to access or modify elements. Concurrently accessing or modifying different elements is safe.
Exception Safety: If the container is not empty, the function never throws exceptions (no-throw guarantee). Otherwise, it causes undefined behavior.

Returns
A reference to the last element in the circular_queue.

◆ begin()

template<class T , class Alloc = std::allocator<T>>
iterator circular_queue< T, Alloc >::begin ( )
inlinenoexcept

Returns iterator to beginning.

Returns an iterator to the head (first element) in the container.
Complexity: Constant.
Iterator Validity: No changes.
Data Races: The container is accessed (neither the const nor the non-const versions modify the container). No contained elements are accessed by the call, but the iterator returned can be used to access or modify elements. Concurrently accessing or modifying different elements is safe.
Exception Safety: No-throw guarantee: this member function never throws exceptions. The copy construction or assignment of the returned iterator is also guaranteed to never throw.

Returns
An iterator to the beginning of the sequence container.

◆ capacity()

template<class T , class Alloc = std::allocator<T>>
size_type circular_queue< T, Alloc >::capacity ( ) const
inlinenoexcept

Get buffer capacity.

Returns the allocated size of the buffer. For the amount of the buffer in use, see size().
Complexity: Constant.
Iterator Validity: No changes.
Data Races: The container object is accessed.
Exception Safety: No-throw guarantee: This function never throws exceptions.

See also
size()
Returns
capacity of the buffer in terms of how many objects of value_type it can contain.

◆ cbegin()

template<class T , class Alloc = std::allocator<T>>
const_iterator circular_queue< T, Alloc >::cbegin ( ) const
inlinenoexcept

Returns constant iterator to beginning.

Returns a constant iterator to the head (first element) in the container. A const_iterator is an iterator that points to const content. This iterator can be increased and decreased (unless it is itself also const), just like the iterator returned by begin(), but it cannot be used to modify the contents it points to, even if the container object is not itself const.
Complexity: Constant.
Iterator Validity: No changes.
Data Races: The container is accessed (neither the const nor the non-const versions modify the container). No contained elements are accessed by the call, but the iterator returned can be used to access or modify elements. Concurrently accessing or modifying different elements is safe.
Exception Safety: No-throw guarantee: this member function never throws exceptions. The copy construction or assignment of the returned iterator is also guaranteed to never throw.

Returns
A constant iterator to the beginning of the sequence container.

◆ cend()

template<class T , class Alloc = std::allocator<T>>
const_iterator circular_queue< T, Alloc >::cend ( ) const
inlinenoexcept

Returns constant iterator to end.

Returns a constant iterator to the tail (last element) in the container.A const_iterator is an iterator that points to const content. This iterator can be increased and decreased (unless it is itself also const), just like the iterator returned by begin(), but it cannot be used to modify the contents it points to, even if the container object is not itself const.
Complexity: Constant.
Iterator Validity: No changes.
Data Races: The container is accessed (neither the const nor the non-const versions modify the container). No contained elements are accessed by the call, but the iterator returned can be used to access or modify elements. Concurrently accessing or modifying different elements is safe.
Exception Safety: No-throw guarantee: this member function never throws exceptions. The copy construction or assignment of the returned iterator is also guaranteed to never throw.

Returns
A constant iterator to the end of the sequence container.

◆ clear()

template<class T , class Alloc = std::allocator<T>>
void circular_queue< T, Alloc >::clear ( )
inlinenoexcept

Clear content.

Removes all elements from the deque (which are destroyed), leaving the container with a size of 0.
Complexity: Linear in size (destructions).
Iterator Validity: All iterators, pointers and references related to this container are invalidated.
Data Races: The container is modified. All contained elements are modified.
Exception Safety: No-throw guarantee: this member function never throws exceptions.

◆ copy()

template<class T , class Alloc = std::allocator<T>>
template<class copyFunctor >
auto circular_queue< T, Alloc >::copy ( const_iterator  first,
const_iterator  last,
value_type destination,
copyFunctor  cf 
) const -> decltype(cf((void*) destination, (void*) first.m_pointer.ptr, ((last.m_pointer.ptr - first.m_pointer.ptr) * sizeof(value_type))))
inline

Copies range to destination buffer using provided copy function.

This function overloads memcpy to handle the internal complexities of copying a circular_queue, which may or may not be wrapped. The resulting array at destination will be unwrapped in either case, meaning logical and physical index[0] will always be the same. Since this function isn't allocator or iterator aware on the destination it's use should be avoided for EVERYTHING except compatibility with C code. In the author's opinion, the ONLY use case for this function is CUDA memory.
THIS MAY NOT WORK if value_type does not exhibit bitwise copy semantics.

Parameters
[in]firstiterator to the first index to be copied.
[in]lastiterator to the last index to be copied.
[out]destinationoutput buffer where the data will be copied to.
[in]copyfunctor used to perform the memory copy. Options may include memcpy, memmove, or bound versions of cudaMemcpy, cudaMemcpyAsync. Must have a signature of copyFunctor(void* destination, void* source, size_t sizeInBytesToCopy)
Returns
forwards the return value of copyFunctor.

◆ crbegin()

template<class T , class Alloc = std::allocator<T>>
const_reverse_iterator circular_queue< T, Alloc >::crbegin ( ) const
inlinenoexcept

Returns constant iterator to beginning.

Returns a reverse iterator to the reverse beginning (last element) in the container. crbegin points to the element right before the one that would be pointed to by end(). A const_reverse_iterator is an iterator that points to const content. This iterator can be increased and decreased (unless it is itself also const), just like the iterator returned by begin(), but it cannot be used to modify the contents it points to, even if the container object is not itself const.
Complexity: Constant.
Iterator Validity: No changes.
Data Races: The container is accessed (neither the const nor the non-const versions modify the container). No contained elements are accessed by the call, but the iterator returned can be used to access or modify elements. Concurrently accessing or modifying different elements is safe.
Exception Safety: No-throw guarantee: this member function never throws exceptions. The copy construction or assignment of the returned iterator is also guaranteed to never throw.

Returns
A constant iterator to the beginning of the sequence container.

◆ crend()

template<class T , class Alloc = std::allocator<T>>
const_reverse_iterator circular_queue< T, Alloc >::crend ( ) const
inlinenoexcept

Returns constant iterator to end.

Returns a reverse iterator pointing to the theoretical element preceding the first element in the container (which is considered its reverse end). A const_reverse_iterator is an iterator that points to const content. This iterator can be increased and decreased (unless it is itself also const), just like the iterator returned by begin(), but it cannot be used to modify the contents it points to, even if the object is not itself const.
Complexity: Constant.
Iterator Validity: No changes.
Data Races: The container is accessed (neither the const nor the non-const versions modify the container). No contained elements are accessed by the call, but the iterator returned can be used to access or modify elements. Concurrently accessing or modifying different elements is safe.
Exception Safety: No-throw guarantee: this member function never throws exceptions. The copy construction or assignment of the returned iterator is also guaranteed to never throw.

Returns
A constant iterator to the end of the sequence container.

◆ decrement()

template<class T , class Alloc = std::allocator<T>>
queue_pointer circular_queue< T, Alloc >::decrement ( queue_pointer  p,
difference_type  n 
) const
inlineprotectednoexcept

decrements a pointer

Takes care of wrapping the pointer and keeping parity consistent.

Parameters
[in]ppointer to decrement. This function modifies the value of p.
[in]nnumber of elements to increment the pointer
[in]parityparity bit associated with the pointer. This function modifies the value of parity.

◆ emplace()

template<class T , class Alloc = std::allocator<T>>
template<class... Args>
iterator circular_queue< T, Alloc >::emplace ( const_iterator  position,
Args &&...  args 
)
inline

Construct and insert element.

The container is extended by inserting a new element at position. This new element is constructed in place using args as the arguments for its construction. This effectively increases the container size by one. Double-ended queues are designed to be efficient performing insertions (and removals) from either the end or the beginning of the sequence. Insertions on other positions are usually less efficient than in list or forward_list containers. See emplace_front and emplace_back for member functions that extend the container directly at the beginning or at the end. The element is constructed in-place by calling allocator_traits::construct with args forwarded.
Complexity: Linear in the number of elements between position and end().
Iterator Validity: All iterators, references, and pointers from position to end() are invalidated.
Data Races: The container is modified. It is NOT safe to concurrently access or modify elements.
Exception Safety: If position is end, there are no changes in the container in case of exception (strong guarantee). Otherwise, the container is guaranteed to end in a valid state (basic guarantee).

Parameters
[in]positionPosition in the container where the new element is inserted. Member type const_iterator is a random access iterator type that points to a constant element.
[in]argsArguments forwarded to construct the new element.
See also
emplace_front()
emplace_back()

◆ emplace_back()

template<class T , class Alloc = std::allocator<T>>
template<class... Args>
void circular_queue< T, Alloc >::emplace_back ( Args &&...  args)
inline

Construct and insert element at the end.

Inserts a new element at the end of the circular_queue, right after its current last element. This new element is constructed in place using args as the arguments for its construction. This effectively increases the container capacity by one. The element is constructed in-place by calling allocator_traits::construct with args forwarded. A similar member function exists, push_back, which either copies or moves an existing object into the container.
Complexity: Constant, if the contained object can be constructed in constant time.
Iterator Validity: The end iterator is invalidated. If the container was full before the call, the begin iterator is also invalidated. All other iterators, pointers, and references remain valid.
Data Races: The container is modified. If the container was full, the beginning element is destroyed. No other existing elements are accessed.
Exception Safety: If the container is not full, there are no side effects (strong guarantee). Otherwise, if the function throws an exception, no resources are leaked (basic guarantee), however the head of the container will be destroyed even if emplace_back throws and no new object is added to the container.

Parameters
[in]argsarguments to the constructor of the contained object.

◆ emplace_front()

template<class T , class Alloc = std::allocator<T>>
template<class... Args>
void circular_queue< T, Alloc >::emplace_front ( Args &&...  args)
inline

Construct and insert element at beginning.

Inserts a new element at the beginning of the container, right before its current first element. This new element is constructed in place using args as the arguments for its construction.This effectively increases the container size by one. The element is constructed in-place by calling allocator_traits::construct with args forwarded. A similar member function exists, push_front, which either copies or moves an existing object into the container.
Complexity: Constant.
Iterator Validity: The begin() iterator is invalidated. If the container was full before the call, the end iterator is also invalidated. All other iterators, pointers, and references remain valid.
Data Races: The container is modified. If the container was full, the last element is destroyed. No other existing elements are accessed.
Exception Safety: If the container is not full, there are no side effects (strong guarantee). Otherwise, if the function throws an exception, no resources are leaked (basic guarantee), however the head of the container will be destroyed even if emplace_back throws and no new object is added to the container.

Parameters
[in]argsarguments to the constructor of the contained object.

◆ empty()

template<class T , class Alloc = std::allocator<T>>
bool circular_queue< T, Alloc >::empty ( ) const
inlinenoexcept

Test whether container is empty.

Returns whether the container is empty (i.e. whether its size is 0).
Complexity: Constant.
Iterator Validity: No changes.
Data Races: The container object is accessed, but no elements are accessed.
Exception Safety: No-throw guarantee: This function never throws exceptions.

Returns
true if the buffer is empty, false otherwise.

◆ end()

template<class T , class Alloc = std::allocator<T>>
iterator circular_queue< T, Alloc >::end ( )
inlinenoexcept

Returns iterator to end.

Returns an iterator to the tail (last element) in the container.
Complexity: Constant.
Iterator Validity: No changes.
Data Races: The container is accessed (neither the const nor the non-const versions modify the container). No contained elements are accessed by the call, but the iterator returned can be used to access or modify elements. Concurrently accessing or modifying different elements is safe.
Exception Safety: No-throw guarantee: this member function never throws exceptions. The copy construction or assignment of the returned iterator is also guaranteed to never throw.

Returns
An iterator to the end of the sequence container.

◆ erase() [1/2]

template<class T , class Alloc = std::allocator<T>>
iterator circular_queue< T, Alloc >::erase ( const_iterator  first,
const_iterator  last 
)
inline

Erase elements.

Removes from the deque container the range of elements ([first,last)). This effectively reduces the container size by the number of elements removed, which are destroyed.
Double-ended queues are designed to be efficient removing (and inserting) elements at either the end or the beginning of the sequence. Removals on other positions are usually less efficient than in list or forward_list containers. Complexity: Linear in the distance from position to end() times the number of elements erased.
Iterator Validity: All iterators, pointers, and references to elements between position and end() are invalidated.
Data Races: If the erasure happens at the end of the sequence, only the erased elements are modified. Otherwise it is not safe to access or modify elements.
Exception Safety: If the removed elements include the the last element in the container, no exceptions are thrown (no-throw guarantee). Otherwise, the container is guaranteed to end in a valid state (basic guarantee): Copying or moving elements while relocating them may throw. Invalid ranges produce undefined behavior.

Parameters
[in]firstiterator to beginning of range to erase from the container
[in]lastiterator to one-past-last element of range to erase from the container
Returns
An iterator pointing to the new location of the element that followed the last element erased by the function call. This is the container end if the operation erased the last element in the sequence.

◆ erase() [2/2]

template<class T , class Alloc = std::allocator<T>>
iterator circular_queue< T, Alloc >::erase ( const_iterator  position)
inline

Erase element.

Removes from deque container a single element (position). This effectively reduces the container size by the number of elements removed, which are destroyed.
Double-ended queues are designed to be efficient removing (and inserting) elements at either the end or the beginning of the sequence. Removals on other positions are usually less efficient than in list or forward_list containers. Complexity: Linear in the distance from position to end().
Iterator Validity: All iterators, pointers, and references to elements between position and end() are invalidated.
Data Races: If the erasure happens at the end of the sequence, only the erased elements are modified. Otherwise it is not safe to access or modify elements.
Exception Safety: If the removed elements include the the last element in the container, no exceptions are thrown (no-throw guarantee). Otherwise, the container is guaranteed to end in a valid state (basic guarantee): Copying or moving elements while relocating them may throw. Invalid ranges produce undefined behavior.

Parameters
[in]positionIterator pointing to a single element to be removed from the container.
Returns
An iterator pointing to the new location of the element that followed the last element erased by the function call. This is the container end if the operation erased the last element in the sequence.

◆ front()

template<class T , class Alloc = std::allocator<T>>
reference circular_queue< T, Alloc >::front ( )
inlinenoexcept

Access first element.

Returns a reference to the first element in the circular_queue. Unlike member begin(), which returns an iterator to this same element, this function returns a direct reference. Calling this function on an empty container causes undefined behavior.
Complexity: Constant.
Iterator Validity: No changes.
Data Races: The container is accessed (neither the const nor the non-const versions modify the container). The reference returned can be used to access or modify elements. Concurrently accessing or modifying different elements is safe.
Exception Safety: If the container is not empty, the function never throws exceptions (no-throw guarantee). Otherwise, it causes undefined behavior.

Returns
A reference to the first element in the circular_queue.

◆ full()

template<class T , class Alloc = std::allocator<T>>
bool circular_queue< T, Alloc >::full ( ) const
inlinenoexcept

Test whether container is full.

Returns whether the container is empty (i.e. whether its size is equal to it's capacity).
Complexity: Constant.
Iterator Validity: No changes.
Data Races: The container object is accessed, but no elements are accessed.
Exception Safety: .

Returns
bool

◆ get_allocator()

template<class T , class Alloc = std::allocator<T>>
allocator_type circular_queue< T, Alloc >::get_allocator ( ) const
inlinenoexcept

Get allocator.

Returns a copy of the allocator object associated with the container.
Complexity: Constant.
Iterator Validity: No changes.
Data Races: The container is accessed. No contained elements are accessed: concurrently accessing or modifying them is safe.
Exception Safety: No-throw guarantee: this member function never throws exceptions. Copying any instantiation of the default allocator is also guaranteed to never throw.

Returns
the allocator.

◆ increment()

template<class T , class Alloc = std::allocator<T>>
queue_pointer circular_queue< T, Alloc >::increment ( queue_pointer  p,
difference_type  n 
) const
inlineprotectednoexcept

increments a pointer

Takes care of wrapping the pointer and keeping parity consistent.

Parameters
[in]ppointer to increment. This function modifies the value of p.
[in]nnumber of elements to increment the pointer
[in]parityparity bit associated with the pointer. This function modifies the value of parity.

◆ insert() [1/5]

template<class T , class Alloc = std::allocator<T>>
iterator circular_queue< T, Alloc >::insert ( const_iterator  position,
const value_type val 
)
inline

Insert (copy) single element.

The container is extended by inserting an element before the element at the specified position. This effectively increases the container size by 1. If the container is full, the element at begin() is overwritten. Makes at most 1 copy of val.
Double-ended queues are designed to be efficient performing insertions (and removals) from either the end or the beginning of the sequence. Insertions on other positions are usually less efficient than in list or forward_list containers.
Complexity: Linear on the number of elements inserted (copy/move construction) plus an additional linear in the number of elements between position and the end of the container.
Iterator Validity: All iterators, pointers and references from position to the end of the queue are invalidated.
Data Races: The container is modified. It is not safe to concurrently access elements.
Exception Safety: The container is guaranteed to end in a valid state (basic guarantee). If allocator_traits::construct is not supported with the appropriate arguments for the element constructions, or if an invalid position or range is specified, it causes undefined behavior.

Parameters
[in]positionPosition in the container where the new elements are inserted. Iterator is a member type, defined as a random access iterator type that points to elements.
[in]valValue to be copied (or moved) to the inserted elements. Member type value_type is the type of the elements in the container, defined in deque as an alias of its first template parameter (T).
See also
push_back()
push_front()
Returns
An iterator that points to the newly inserted element.

◆ insert() [2/5]

template<class T , class Alloc = std::allocator<T>>
template<class InputIterator >
iterator circular_queue< T, Alloc >::insert ( const_iterator  position,
InputIterator  first,
InputIterator  last 
)
inline

Insert (range) elements.

The container is extended by inserting new elements before the element at the specified position. This effectively increases the container size by the amount of elements inserted. If this size is greater than the current capacity, the elements at the beginning of the queue will be over-written. This operation will cause at most capacity() copies. The range of copied values is [first, last).
Double-ended queues are designed to be efficient performing insertions (and removals) from either the end or the beginning of the sequence. Insertions on other positions are usually less efficient than in list or forward_list containers.
Complexity: Linear on the number of elements inserted (copy/move construction) plus an additional linear in the number of elements between position and the end of the container.
Iterator Validity: All iterators, pointers and references are invalidated.
Data Races: The container is modified. It is not safe to concurrently access elements.
Exception Safety: The container is guaranteed to end in a valid state (basic guarantee). If allocator_traits::construct is not supported with the appropriate arguments for the element constructions, or if an invalid position or range is specified, it causes undefined behavior.

Parameters
[in]positionthe fill will be inserted before the element at this position.
[in]firstiterator to beginning of range to insert. InputIterator can be an iterator to any type of container, as long as it is at least a forward iterator.
[in]lastiterator to one-past-end of range to insert. InputIterator can be an iterator to any type of container, as long as it is at least a forward iterator. type of the elements in the container, defined in circular_queue as an alias of its first template parameter (T).
See also
push_back()
push_front()
Returns
An iterator that points to the first of the newly inserted elements.

◆ insert() [3/5]

template<class T , class Alloc = std::allocator<T>>
iterator circular_queue< T, Alloc >::insert ( const_iterator  position,
size_type  n,
const value_type val 
)
inline

Insert (fill) elements.

The container is extended by inserting new elements before the element at the specified position. This effectively increases the container size by the amount of elements inserted. If this size is greater than the current capacity, the elements at the beginning of the queue will be over-written. This operation will cause at most n copies of val.
Double-ended queues are designed to be efficient performing insertions (and removals) from either the end or the beginning of the sequence. Insertions on other positions are usually less efficient than in list or forward_list containers.
Complexity: O(m*n) where m is the current size and m is the number of elements inserted.
Iterator Validity: All iterators, pointers and references are invalidated.
Data Races: The container is modified. It is not safe to concurrently access elements.
Exception Safety: The container is guaranteed to end in a valid state (basic guarantee). If allocator_traits::construct is not supported with the appropriate arguments for the element constructions, or if an invalid position or range is specified, it causes undefined behavior.

Parameters
[in]positionthe fill will be inserted before the element at this position.
[in]nNumber of elements to insert. Each element is initialized to a copy of val.
[in]valValue to be copied to the inserted elements. Member type value_type is the type of the elements in the container, defined in circular_queue as an alias of its first template parameter (T).
See also
push_back()
push_front()
Returns
An iterator that points to the first of the newly inserted elements.

◆ insert() [4/5]

template<class T , class Alloc = std::allocator<T>>
iterator circular_queue< T, Alloc >::insert ( const_iterator  position,
std::initializer_list< value_type il 
)
inline

Insert elements (initializer_list)

The container is extended by inserting new elements before the element at the specified position. This effectively increases the container size by the amount of elements inserted. If this size is greater than the current capacity, the elements at the beginning of the queue will be over-written. This operation will cause at most capacity() copies.
Double-ended queues are designed to be efficient performing insertions (and removals) from either the end or the beginning of the sequence. Insertions on other positions are usually less efficient than in list or forward_list containers.
Complexity: Linear on the number of elements inserted (copy/move construction) plus an additional linear in the number of elements between position and the end of the container.
Iterator Validity: All iterators, pointers and references are invalidated.
Data Races: The container is modified. It is not safe to concurrently access elements.
Exception Safety: The container is guaranteed to end in a valid state (basic guarantee). If allocator_traits::construct is not supported with the appropriate arguments for the element constructions, or if an invalid position or range is specified, it causes undefined behavior.

Parameters
[in]positionthe fill will be inserted before the element at this position.
[in]ilinitializer_list object, filled with values to insert into the container.
See also
push_back()
push_front()
Returns
An iterator that points to the first of the newly inserted elements.

◆ insert() [5/5]

template<class T , class Alloc = std::allocator<T>>
iterator circular_queue< T, Alloc >::insert ( const_iterator  position,
value_type &&  val 
)
inline

Insert (move) single element.

The container is extended by inserting an element before the element at the specified position. This effectively increases the container size by 1. If the container is full, the element at begin() is overwritten. Makes no copies of val, and val must be move-assignable.
Double-ended queues are designed to be efficient performing insertions (and removals) from either the end or the beginning of the sequence. Insertions on other positions are usually less efficient than in list or forward_list containers.
Complexity: Linear on the number of elements inserted (copy/move construction) plus an additional linear in the number of elements between position and the end of the container.
Iterator Validity: All iterators, pointers and references from position to the end of the queue are invalidated.
Data Races: The container is modified. It is not safe to concurrently access elements.
Exception Safety: The container is guaranteed to end in a valid state (basic guarantee). If allocator_traits::construct is not supported with the appropriate arguments for the element constructions, or if an invalid position or range is specified, it causes undefined behavior.

Parameters
[in]positionPosition in the container where the new elements are inserted. Iterator is a member type, defined as a random access iterator type that points to elements.
[in]valValue to be copied (or moved) to the inserted elements. Member type value_type is the type of the elements in the container, defined in deque as an alias of its first template parameter (T).
See also
push_back()
push_front()
Returns
An iterator that points to the newly inserted element.

◆ max_size()

template<class T , class Alloc = std::allocator<T>>
size_type circular_queue< T, Alloc >::max_size ( ) const
inlinenoexcept

Return maximum capacity.

Returns the maximum number of elements that the container can hold. This is the maximum potential capacity the container can reach due to known system or library implementation limitations, but the container is by no means guaranteed to be able to reach that capacity: it can still fail to allocate storage at any point before that capacity is reached.
Complexity: Constant.
Iterator Validity: No changes.
Data Races: The container is accessed, but no contained elements are accessed. Concurrently accessing or modifying them is safe.
Exception Safety: No-throw guarantee: This function never throws exceptions.

Returns
Maximum number of elements of type value_type that can be stored in the container.

◆ operator=() [1/3]

template<class T , class Alloc = std::allocator<T>>
circular_queue& circular_queue< T, Alloc >::operator= ( circular_queue< T, Alloc > &&  other)
inlinenoexcept

Assign content.

moves all the elements from other into the container (with other in an unspecified but valid state).
Complexity: Linear in Size (destructions).
Iterator Validity: All iterators, references and pointers related to this container before the call are invalidated.
Data Races: All copied elements are accessed. The container and all its elements are modified.
Exception Safety: Basic guarantee: if an exception is thrown, the container is in a valid state. If allocator_traits::construct is not supported with the appropriate arguments for the element constructions, or if value_type is not move assignable, it causes undefined behavior.

Parameters
[in]othercontainer to move
See also
assign()
Returns
*this

◆ operator=() [2/3]

template<class T , class Alloc = std::allocator<T>>
circular_queue& circular_queue< T, Alloc >::operator= ( const circular_queue< T, Alloc > &  other)
inline

Assign content.

copies all the elements from other into the container (with other preserving its contents).
Complexity: Linear in initial and final sizes (destructions, copy constructions).
Iterator Validity: All iterators, references and pointers related to this container before the call are invalidated.
Data Races: All copied elements are accessed. The container and all its elements are modified.
Exception Safety: Basic guarantee: if an exception is thrown, the container is in a valid state. If allocator_traits::construct is not supported with the appropriate arguments for the element constructions, or if value_type is not copy assignable, it causes undefined behavior.

Parameters
[in]othercontainer to copy
See also
Returns
*this

◆ operator=() [3/3]

template<class T , class Alloc = std::allocator<T>>
circular_queue& circular_queue< T, Alloc >::operator= ( std::initializer_list< value_type il)
inline

Assign content.

Assigns new contents to the container, replacing its current contents, and modifying its size accordingly. The new contents are copies of the values passed as initializer list, in the same order.
Complexity: Linear in initial and final sizes (destructions, constructions).
Iterator Validity: All iterators, references and pointers related to this container before the call are invalidated. Data Races: All copied elements are accessed. The container and all its elements are modified.
Exception Safety: Basic guarantee: if an exception is thrown, the container is in a valid state. If allocator_traits::construct is not supported with the appropriate arguments for the element constructions, or if value_type is not move assignable, it causes undefined behavior.

Parameters
[in]ilinitializer list object.
Returns
circular_queue&

◆ operator[]()

template<class T , class Alloc = std::allocator<T>>
reference circular_queue< T, Alloc >::operator[] ( size_type  n)
inline

Access element.

Returns a reference to the element at position n in the container. A similar member function, at(), has the same behavior as this operator function, except that at() is bound-checked and signals if the requested position is out of range by throwing an out_of_range exception. Portable programs should never call this function with an argument n that is out of range, since this causes undefined behavior.
Complexity: Constant.
Iterator Validity: No changes.
Data Races: The container is accessed (neither the const nor the non-const versions modify the container). The reference returned can be used to access or modify elements. Concurrently accessing or modifying different elements is safe.
Exception Safety: If the container size is greater than n, the function never throws exceptions (no-throw guarantee). Otherwise, the behavior is undefined.

Parameters
[in]nPosition of an element in the container. Notice that the first element has a position of 0 (not 1). Member type size_type is an unsigned integral type.
Returns
The element at the specified position in the circular_queue.

◆ pop_back()

template<class T , class Alloc = std::allocator<T>>
void circular_queue< T, Alloc >::pop_back ( )
inlinenoexcept

Delete last element.

Removes the last element in the circular_queue container, effectively reducing its size by one. This destroys the removed element. Popping an empty queue results in undefined behavior.
Complexity: Constant.
Iterator Validity: The iterators, pointers and references referring to the removed element are invalidated. Iterators, pointers and references referring to other elements that have not been removed are guaranteed to keep referring to the same elements they were referring to before the call.
Data Races: The container is modified. The last element is modified. Concurrently accessing or modifying other elements is safe (although see iterator validity above).
Exception Safety: If the container is not empty, the function never throws exceptions (no-throw guarantee). Otherwise, it causes undefined behavior.

◆ pop_front()

template<class T , class Alloc = std::allocator<T>>
void circular_queue< T, Alloc >::pop_front ( )
inlinenoexcept

Delete first element.

Removes the first element in the circular_queue container, effectively reducing its size by one. This destroys the removed element. Popping an empty queue results in undefined behavior.
Complexity: Constant.
Iterator Validity: The iterators, pointers and references referring to the removed element are invalidated. Iterators, pointers and references referring to other elements that have not been removed are guaranteed to keep referring to the same elements they were referring to before the call.
Data Races: The container is modified. The first element is modified. Concurrently accessing or modifying other elements is safe (although see iterator validity above).
Exception Safety: If the container is not empty, the function never throws exceptions (no-throw guarantee). Otherwise, it causes undefined behavior.

◆ push_back()

template<class T , class Alloc = std::allocator<T>>
void circular_queue< T, Alloc >::push_back ( const value_type val)
inline

Add element at the end.

Adds a new element at the end of the container, after its current last element. The content of val is copied (or moved) to the new element. This effectively increases the container size by one. If the circular_queue is full, it will cause the element at the front of the queue to be overwritten.
Complexity: Constant.
Iterator Validity: Only the end iterator is invalidated, and all iterators, pointers and references to elements are guaranteed to keep referring to the same elements they were referring to before the call.
Data Races: The container is modified. If full, the first element in the queue is modified. Concurrently accessing or modifying other elements is safe.
Exception Safety: The container is guaranteed to end in a valid state (basic guarantee). If the element is copyable or no-throw movable, then there are no side effects (strong guarantee). If the container is not full, then there are no side effects (strong guarantee). If the container is full, and an exception occurs, the first element in the container will be destroyed. If allocator_traits::construct is not supported with val as argument, it causes undefined behavior.

Parameters
[in]valvalue to copy/move into the end of the container. Member type value_type is the type of the elements in the container, defined in vector as an alias of its first template parameter (T).

◆ push_front()

template<class T , class Alloc = std::allocator<T>>
void circular_queue< T, Alloc >::push_front ( const value_type val)
inline

Add element at beginning.

Adds a new element at the beginning of the container, right before its current first element. The content of val is copied (or moved) to the new element. This effectively increases the container size by one. If the circular_queue is full, it will cause the element at the end of the queue to be overwritten.
Complexity: Constant.
Iterator Validity: Only the begin iterator is invalidated, and all iterators, pointers and references to elements are guaranteed to keep referring to the same elements they were referring to before the call.
Data Races: The container is modified. If full, the last element in the queue is modified. Concurrently accessing or modifying other elements is safe.
Exception Safety: The container is guaranteed to end in a valid state (basic guarantee). If the element is copyable or no-throw movable, then there are no side effects (strong guarantee). If allocator_traits::construct is not supported with val as argument, it causes undefined behavior.

Parameters
[in]valvalue to copy/move into the end of the container. Member type value_type is the type of the elements in the container, defined in vector as an alias of its first template parameter (T).

◆ rbegin()

template<class T , class Alloc = std::allocator<T>>
reverse_iterator circular_queue< T, Alloc >::rbegin ( )
inlinenoexcept

Returns reverse iterator to beginning.

@function rbegin

Returns a reverse iterator to the reverse beginning (last element) in the container. rbegin points to the element right before the one that would be pointed to by end().
Complexity: Constant.
Iterator Validity: No changes.
Data Races: The container is accessed (neither the const nor the non-const versions modify the container). No contained elements are accessed by the call, but the iterator returned can be used to access or modify elements. Concurrently accessing or modifying different elements is safe.
Exception Safety: No-throw guarantee: this member function never throws exceptions. The copy construction or assignment of the returned iterator is also guaranteed to never throw.

Returns
A reverse iterator to the beginning of the sequence container.

◆ reallocate()

template<class T , class Alloc = std::allocator<T>>
void circular_queue< T, Alloc >::reallocate ( size_type  n)
inlineprotected

moves the currently contained data to a new area with size n.

O(n) complexity. Unwraps the buffer as a side effect.

Parameters
[in]nsize of new allocation

◆ rend()

template<class T , class Alloc = std::allocator<T>>
reverse_iterator circular_queue< T, Alloc >::rend ( )
inlinenoexcept

Returns reverse iterator to end.

Returns a reverse iterator pointing to the theoretical element preceding the first element in the container (which is considered its reverse end).
Complexity: Constant.
Iterator Validity: No changes.
Data Races: The container is accessed (neither the const nor the non-const versions modify the container). No contained elements are accessed by the call, but the iterator returned can be used to access or modify elements. Concurrently accessing or modifying different elements is safe.
Exception Safety: No-throw guarantee: this member function never throws exceptions. The copy construction or assignment of the returned iterator is also guaranteed to never throw.

Returns
A reverse iterator to the end of the sequence container.

◆ reserve()

template<class T , class Alloc = std::allocator<T>>
void circular_queue< T, Alloc >::reserve ( size_type  n)
inline

Request a change in capacity.

Requests that the vector capacity be at least enough to contain n elements. If n is greater than the current capacity, the function causes the container to reallocate its storage increasing its capacity to n. In all other cases, the function call does not cause a reallocation and the vector capacity is not affected.
Complexity: If a reallocation happens, linear in size at most..
Iterator Validity: If a reallocation happens, all iterators, pointers and references related to the container are invalidated. Otherwise, they all keep referring to the same elements they were referring to before the call.
Data Races: If a reallocation happens, the container and all its contained elements are modified.
Exception Safety: If no reallocations happen or if the type of the elements has either a non-throwing move constructor or a copy constructor, there are no changes in the container in case of exception (strong guarantee). Otherwise, the container is guaranteed to end in a valid state (basic guarantee). Under the basic guarantee, if this function throws, it's possible that all the container contents will be destroyed as a side-effect. The function throws bad_alloc if it fails to allocate the new size.

Parameters
[in]nMinimum capacity for the container.

◆ resize()

template<class T , class Alloc = std::allocator<T>>
void circular_queue< T, Alloc >::resize ( size_type  n,
const value_type val = value_type() 
)
inline

Change size.

Changes both the size and capacity of the container, resizing the container so that it contains n elements. If n is smaller than the current container size, the content is reduced to its first n elements, removing those beyond (and destroying them). If n is greater than the current container size, the content is expanded by inserting at the end as many elements as needed to reach a size of n. If val is specified, the new elements are initialized as copies of val, otherwise, they are value-initialized. Regardless of the value of n (except n == size()), an automatic reallocation of the allocated storage space takes place. Notice that this function changes the actual content of the container by inserting or erasing elements from it.
Complexity: Linear on the number of elements inserted/erased (constructions/destructions). If a reallocation happens, the reallocation is itself up to linear in the entire container size.
Iterator Validity: Resizing causes reallocation, and so all iterators, pointers and references related to this container are also invalidated.
Data Races: The container is modified. If a reallocation happens, all contained elements are modified.
Exception Safety: If n is less than or equal to the size of the container, the function never throws exceptions (no-throw guarantee). If n is greater and a reallocation happens, there are no changes in the container in case of exception (strong guarantee) if the type of the elements is either copyable or no-throw movable. Otherwise, if an exception is thrown, the container is left with a valid state (basic guarantee).

Parameters
[in]nNew container size, expressed in number of elements. Member type size_type is an unsigned integral type.
[in]valObject whose content is copied to the added elements in case that n is greater than the current container size. If not specified, the default constructor is used instead.

◆ shrink_to_fit()

template<class T , class Alloc = std::allocator<T>>
void circular_queue< T, Alloc >::shrink_to_fit ( )
inline

Shrink container to fit.

Requests the container to reduce its capacity to fit its size. Unlike vector, the request is binding. This will never cause a reallocation, and has no effect on the size or element contents.
Complexity: At most, linear in container size..
Iterator Validity: All iterators, pointers and references related to the container are invalidated.
Data Races: The container is modified. All contained objects are moved.
Exception Safety: If the type of the elements is either copyable or no-throw movable, there are no changes in the container in case of exception (strong guarantee). Otherwise, if an exception is thrown, the container is left with a valid state (basic guarantee).

◆ size()

template<class T , class Alloc = std::allocator<T>>
size_type circular_queue< T, Alloc >::size ( ) const
inlinenoexcept

Return size.

Returns the number of elements in the container.
Complexity: Constant.
Iterator Validity: No changes.
Data Races: The container is accessed. No contained elements are accessed: concurrently accessing or modifying them is safe.
Exception Safety: No-throw guarantee: this member function never throws exceptions..

Returns
The number of elements in the container. Member type size_type is an unsigned integral type.

◆ swap()

template<class T , class Alloc = std::allocator<T>>
void circular_queue< T, Alloc >::swap ( circular_queue< T, Alloc > &  other)
inlinenoexcept

Swap content.

Exchanges the content of the container by the content of other, which is another circular_queue object containing elements of the same type. Sizes may differ. After the call to this member function, the elements in this container are those which were in other before the call, and the elements of other are those which were in this. All iterators, references and pointers remain valid for the swapped objects. Notice that a non-member function exists with the same name, swap, overloading that algorithm with an optimization that behaves like this member function.
Complexity: Constant.
Iterator Validity: All iterators, pointers and references referring to elements in both containers remain valid, and are now referring to the same elements they referred to before the call, but in the other container, where they now iterate.
Data Races: Both the container and other are modified. No contained elements are accessed by the call.
Exception Safety: If the allocators in both containers compare equal, or if their allocator traits indicate that the allocators shall propagate, the function never throws exceptions (no-throw guarantee). Otherwise, it causes undefined behavior.

Parameters
[in]othercontainer to swap with this.

◆ swapDownTo()

template<class T , class Alloc = std::allocator<T>>
iterator circular_queue< T, Alloc >::swapDownTo ( const_iterator  position,
size_type  n 
)
inlineprotectednoexcept

Swaps the back of the queue down to position with elements n positions away.

No-throw. O(n) complexity.

Parameters
[in]positionposition to swap down to from the end
[in]nnumber of elements
Returns
iterator to position of last element swapped.

◆ swapUpToEnd()

template<class T , class Alloc = std::allocator<T>>
iterator circular_queue< T, Alloc >::swapUpToEnd ( const_iterator  position,
size_type  n 
)
inlineprotectednoexcept

Moves the given position to the end of the queue by successively swapping it.

No-throw. O(n) complexity.

Parameters
[in]positionposition to swap up to the end from
[in]nnumber of elements
Returns
iterator to position of first element swapped.

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