deque Class
The Standard Template Library (STL) sequence container deque arranges elements of a given type in a linear arrangement and, like vectors, allow fast random access to any element and efficient insertion and deletion at the back of the container. However, unlike a vector, the deque class also supports efficient insertion and deletion at the front of the container.
template <
class Type,
class Allocator=allocator<Type>
>
class deque
Parameters
Type
The element data type to be stored in the deque.Allocator
The type that represents the stored allocator object that encapsulates details about the deque's allocation and deallocation of memory. This argument is optional, and the default value is allocator<Type>.
Remarks
The choice of container type should be based in general on the type of searching and inserting required by the application. Vectors should be the preferred container for managing a sequence when random access to any element is at a premium and insertions or deletions of elements are only required at the end of a sequence. The performance of the list container is superior when efficient insertions and deletions (in constant time) at any location within the sequence is at a premium. Such operations in the middle of the sequence require element copies and assignments proportional to the number of elements in the sequence (linear time).
Deque reallocation occurs when a member function must insert or erase elements of the sequence:
If an element is inserted into an empty sequence, or if an element is erased to leave an empty sequence, then iterators earlier returned by begin and end become invalid.
If an element is inserted at the first position of the deque, then all iterators, but no references, that designate existing elements become invalid.
If an element is inserted at the end of the deque, then end and all iterators, but no references, that designate existing elements become invalid.
If an element is erased at the front of the deque, only that iterator and references to the erased element become invalid.
If the last element is erased from the end of the deque, only that iterator to the final element and references to the erased element become invalid.
Otherwise, inserting or erasing an element invalidates all iterators and references.
Constructors
Constructs a deque. Several constructors are provided to set up the contents of the new deque in different ways: empty; loaded with a specified number of empty elements; contents moved or copied from another deque; contents copied or moved by using an iterator; and one element copied into the deque_Count times. Some of the constructors enable using a custom allocator to create elements. |
Typedefs
A type that represents the allocator class for the deque object. |
|
A type that provides a random-access iterator that can access and read elements in the deque as const |
|
A type that provides a pointer to an element in a deque as a const. |
|
A type that provides a reference to an element in a deque for reading and other operations as a const. |
|
A type that provides a random-access iterator that can access and read elements in the deque as const. The deque is viewed in reverse. For more information, see reverse_iterator Class |
|
A type that provides the difference between two random-access iterators that refer to elements in the same deque. |
|
A type that provides a random-access iterator that can read or modify any element in a deque. |
|
A type that provides a pointer to an element in a deque. |
|
A type that provides a reference to an element stored in a deque. |
|
A type that provides a random-access iterator that can read or modify an element in a deque. The deque is viewed in reverse order. |
|
A type that counts the number of elements in a deque. |
|
A type that represents the data type stored in a deque. |
Member Functions
Erases elements from a deque and copies a new sequence of elements to the target deque. |
|
Returns a reference to the element at a specified location in the deque. |
|
Returns a reference to the last element of the deque. |
|
Returns a random-access iterator addressing the first element in the deque. |
|
Returns a const iterator to the first element in the deque. |
|
Returns a random-access const iterator that points just beyond the end of the deque. |
|
Erases all the elements of a deque. |
|
Returns a random-access const iterator to the first element in a deque viewed in reverse order. |
|
Returns a random-access const iterator to the first element in a deque viewed in reverse order. |
|
Inserts an element constructed in place into the deque at a specified position. |
|
Adds an element constructed in place to the end of the deque. |
|
Adds an element constructed in place to the start of the deque. |
|
Returns true if the deque contains zero elements, and false if it contains one or more elements. |
|
Returns a random-access iterator that points just beyond the end of the deque. |
|
Removes an element or a range of elements in a deque from specified positions. |
|
Returns a reference to the first element in a deque. |
|
Returns a copy of the allocator object that is used to construct the deque. |
|
Inserts an element, several elements, or a range of elements into the deque at a specified position. |
|
Returns the maximum possible length of the deque. |
|
Erases the element at the end of the deque. |
|
Erases the element at the start of the deque. |
|
Adds an element to the end of the deque. |
|
Adds an element to the start of the deque. |
|
Returns a random-access iterator to the first element in a reversed deque. |
|
Returns a random-access iterator that points just beyond the last element in a reversed deque. |
|
Specifies a new size for a deque. |
|
Discards excess capacity. |
|
Returns the number of elements in the deque. |
|
Exchanges the elements of two deques. |
Operators
Returns a reference to the deque element at a specified position. |
|
Replaces the elements of the deque with a copy of another deque. |
Requirements
Header: <deque>
See Also
Reference
Thread Safety in the Standard C++ Library