Like the vector
, deque
is a linear container supporting random-access that looks very much like a dynamically-managed array. deque
is an excellent choice when working with random-access lists where insertions are common at the beginning and end of the container.
Another linear container class is the list
, which represents a list of elements that does not support random access.
Constructs a new deque. This is the default constructor.
Constructs a new deque with the specified number of copies of the specified element. With a single parameter, this constructor creates a deque containing the specified number of elements, all initialized to the default. With two parameters, this constructor creates a deque of the specified number of copies of the specified element.
Returns a reference to the stored element at the specified position. The operator[]
function will not bounds-check and has undefined behavior when accessing beyond the bounds of the deque. The at()
function will throw an out_of_range
exception when reading beyond the ends of the array.
Returns the number of elements stored in the container.
Returns whether the deque is empty. It's considered good practice to call empty
to determine whether the deque is empty rather than checking whether size()
returns zero.
Removes all elements from the deque
.
Resizes the deque by adding or removing elements from the end of the deque. The first version resizes the deque to the specified size, trimming elements from the end if the new size is smaller than the old size and padding the end with new objects if the new size is greater than the old size. The newly-added elements are constructed using the default constructor.
The second version of the function works identically to the first, except that any newly-added elements are initialized to have the same value as the parameter.
Returns an iterator to the first element in the deque.
Returns an iterator to the element one past the end of the deque. This iterator does not point to a valid element, so do not dereference it.
Appends the specified element to the back of the deque, increasing the size by one.
Removes the last element in the deque. pop_back
does not return a value, so if you want to get the value, call back
first. pop_back
does not do any bounds-checking, so make sure the deque is nonempty before calling.
Returns a reference to the last element of the deque. There is no bounds-checking, so make sure the deque is nonempty before calling.
Prepends the specified element to the front of the deque, increasing the size by one.
Removes the first element in the deque. pop_front
does not return a value, so if you want to get the value, call front
first. pop_front
does not do any bounds-checking, so make sure the deque is nonempty before calling.
Returns a reference to the first element of the deque. There is no bounds-checking, so make sure the deque is nonempty before calling.
The first version inserts the specified element at the position indicated by the specified iterator. There is no bounds-checking. The size of the container will grow by one and elements will be shifted down.
The second version inserts the specified number of copies of the specified element at the specified position.
The third version inserts the elements in the specified iterator range into the deque at the specified position. The source iterators can be of any type.
Removes elements from the deque without bounds-checking. The first version removes the element pointed at by the iterator, and the second removes all elements in the specified range.
Returns a reverse_iterator
to the last element of the deque
. reverse_iterator
s are like regular iterators except that they traverse in the opposite direction. Check for the end-of-container condition of reverse_iterator
s with rend
.
Returns a reverse_iterator
to the element one element before the start of the array. Like end
, the iterator returned by rend
does not actually reference a real element of the deque
and you should take care not to actually dereference it.
Returns the maximum number of elements the deque
can hold, which is usually the number of unique memory addresses divided by the size of the elements stored in the container.
deque
sExchanges the contents of this deque
and another deque
.
deque
content.Erases any stored content and replaces it with either the specified number of repeats of the specified elements or the elements contained in the range [start, end). In either case, the original deque
contents are deleted.