Queue
1.0.0
A C++17 Library of various `queue` containers
|
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_queue & | operator= (const circular_queue &other) |
Assign content. More... | |
circular_queue & | operator= (circular_queue &&other) noexcept |
Assign content. More... | |
circular_queue & | operator= (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! | |
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.
|
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.
[in] | capacity | number of elements that can be stored in the queue. |
[in] | alloc | Allocator object. The container keeps and uses an internal copy of this allocator. |
|
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.
[in] | val | this value will be copied into all the container elements. |
[in] | capacity | size of the container. |
[in] | alloc | Allocator object. The container keeps and uses an internal copy of this allocator. |
|
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.
[in] | first | iterator to the beginning of the range to copy. |
[in] | last | iterator to the end (one past the last element) of the range to copy. |
[in] | alloc | Allocator object. The container keeps and uses an internal copy of this allocator. |
|
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.
[in] | il | initializer_list object. |
[in] | alloc | Allocator object. The container keeps and uses an internal copy of this |
|
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.
[in] | other | buffer to be copied |
|
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.
[in] | other | circular_queue to be moved. |
|
inlinevirtual |
destructor
Yeah, you know what this is.
|
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.
[in] | first | beginning of the range to copy. |
[in] | last | end (exclusive) of the range to be copied. |
|
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.
[in] | n | new container size |
[in] | val | value to be copied into each element of the container. |
|
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.
[in] | il | An 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). |
|
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: .
[in] | n | Position 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. |
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
[in] | first | iterator to the first index to be copied. |
[in] | last | iterator to the last index to be copied. |
[out] | destination | output buffer where the data will be copied to. |
[in] | copy | functor 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) |
|
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.
|
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.
|
inlineprotectednoexcept |
decrements a pointer
Takes care of wrapping the pointer and keeping parity consistent.
[in] | p | pointer to decrement. This function modifies the value of p. |
[in] | n | number of elements to increment the pointer |
[in] | parity | parity bit associated with the pointer. This function modifies the value of parity. |
|
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).
[in] | position | Position 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] | args | Arguments forwarded to construct the new element. |
|
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.
[in] | args | arguments to the constructor of the contained object. |
|
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.
[in] | args | arguments to the constructor of the contained object. |
|
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.
|
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.
|
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.
[in] | first | iterator to beginning of range to erase from the container |
[in] | last | iterator to one-past-last element of range to erase from the container |
|
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.
[in] | position | Iterator pointing to a single element to be removed from the container. |
|
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.
|
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: .
|
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.
|
inlineprotectednoexcept |
increments a pointer
Takes care of wrapping the pointer and keeping parity consistent.
[in] | p | pointer to increment. This function modifies the value of p. |
[in] | n | number of elements to increment the pointer |
[in] | parity | parity bit associated with the pointer. This function modifies the value of parity. |
|
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.
[in] | position | Position 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] | val | Value 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). |
|
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.
[in] | position | the fill will be inserted before the element at this position. |
[in] | first | iterator 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] | last | iterator 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). |
|
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.
[in] | position | the fill will be inserted before the element at this position. |
[in] | n | Number of elements to insert. Each element is initialized to a copy of val. |
[in] | val | Value 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). |
|
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.
[in] | position | the fill will be inserted before the element at this position. |
[in] | il | initializer_list object, filled with values to insert into the container. |
|
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.
[in] | position | Position 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] | val | Value 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). |
|
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.
|
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.
[in] | other | container to move |
|
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.
[in] | other | container to copy |
|
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.
[in] | il | initializer list object. |
|
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.
[in] | n | Position 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. |
|
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.
|
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.
|
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.
[in] | val | value 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). |
|
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.
[in] | val | value 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). |
|
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.
|
inlineprotected |
moves the currently contained data to a new area with size n.
O(n) complexity. Unwraps the buffer as a side effect.
[in] | n | size of new allocation |
|
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.
|
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.
[in] | n | Minimum capacity for the container. |
|
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).
[in] | n | New container size, expressed in number of elements. Member type size_type is an unsigned integral type. |
[in] | val | Object 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. |
|
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).
|
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..
|
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.
[in] | other | container to swap with this. |
|
inlineprotectednoexcept |
Swaps the back of the queue down to position with elements n positions away.
No-throw. O(n) complexity.
[in] | position | position to swap down to from the end |
[in] | n | number of elements |
|
inlineprotectednoexcept |
Moves the given position to the end of the queue by successively swapping it.
No-throw. O(n) complexity.
[in] | position | position to swap up to the end from |
[in] | n | number of elements |