# <deque> <deque> # `` * * * Include the [STL](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_index.html#STL) standard header **``** to define the [container](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_lib_cont.html#Containers) template class `deque` and several supporting templates. namespace std { template class deque; // TEMPLATE FUNCTIONS template bool operator==( const deque& left, const deque& right); template bool operator!=( const deque& left, const deque& right); template bool operator<( const deque& left, const deque& right); template bool operator>( const deque& left, const deque& right); template bool operator<=( const deque& left, const deque& right); template bool operator>=( const deque& left, const deque& right); template void swap( deque& left, deque& right); } // namespace stdCopy to clipboard ## `deque` * * * **`allocator_type· assign· at· back· begin· clear· const_iterator· const_pointer· const_reference· const_reverse_iterator· deque· difference_type· empty· end· erase· front· get_allocator· insert· iterator· max_size· operator[]· pointer· pop_back· pop_front· push_back· push_front· rbegin· reference· rend· resize· reverse_iterator· size· size_type· swap· value_type`** * * * template > class deque { public: typedef Alloc allocator_type; typedef typename Alloc::pointer pointer; typedef typename Alloc::const_pointer const_pointer; typedef typename Alloc::reference reference; typedef typename Alloc::const_reference const_reference; typedef typename Alloc::value_type value_type; typedef T0 iterator; typedef T1 const_iterator; typedef T2 size_type; typedef T3 difference_type; typedef reverse_iterator const_reverse_iterator; typedef reverse_iterator reverse_iterator; deque(); explicit deque(const Alloc& al); explicit deque(size_type count); deque(size_type count, const Ty& val); deque(size_type count, const Ty& val, const Alloc& al); deque(const deque& right); template deque(InIt first, InIt last); template deque(InIt first, InIt last, const Alloc& al); iterator begin(); const_iterator begin() const; iterator end(); const_iterator end() const; reverse_iterator rbegin(); const_reverse_iterator rbegin() const; reverse_iterator rend(); const_reverse_iterator rend() const; void resize(size_type newsize); void resize(size_type newsize, Ty val); size_type size() const; size_type max_size() const; bool empty() const; Alloc get_allocator() const; reference at(size_type pos); const_reference at(size_type pos) const; reference operator[](size_type pos); const_reference operator[](size_type pos) const; reference front(); const_reference front() const; reference back(); const_reference back() const; void push_front(const Ty& val); void pop_front(); void push_back(const Ty& val); void pop_back(); template void assign(InIt first, InIt last); void assign(size_type count, const Ty& val); iterator insert(iterator where, const Ty& val); void insert(iterator where, size_type count, const Ty& val); template void insert(iterator where, InIt first, InIt last); iterator erase(iterator where); iterator erase(iterator first, iterator last); void clear(); void swap(deque& right); };Copy to clipboard The template class describes an object that controls a varying-length sequence of elements of type `Ty`. The sequence is represented in a way that permits insertion and removal of an element at either end with a single element copy (constant time). Such operations in the middle of the sequence require element copies and assignments proportional to the number of elements in the sequence (linear time). The object allocates and frees storage for the sequence it controls through a stored [allocator object](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_memory.html#allocator%20object) of class `Alloc`. Such an allocator object must have the same external interface as an object of template class [`allocator`](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_memory.html#allocator). Note that the stored allocator object is *not* copied when the container object is assigned. **Deque reallocation** occurs when a member function must insert or erase elements of the controlled 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 `begin()` or at `end()`, then all iterators become invalid, but no references that designate existing elements become invalid. - If an element is erased at `begin()` or at `end()`, then only iterators and references that designate the erased element become invalid. - Otherwise, inserting or erasing an element invalidates all iterators and references. ### `deque::allocator_type` typedef Alloc allocator_type;Copy to clipboard The type is a synonym for the template parameter `Alloc`. ### `deque::assign` template void assign(InIt first, InIt last); void assign(size_type count, const Ty& val);Copy to clipboard If `InIt` is an integer type, the first member function behaves the same as `assign((size_type)first, (Ty)last)`. Otherwise, the first member function replaces the sequence controlled by `*this` with the sequence `[first, last)`, which must *not* overlap the initial controlled sequence. The second member function replaces the sequence controlled by `*this` with a repetition of `count` elements of value `val`. ### `deque::at` const_reference at(size_type pos) const; reference at(size_type pos);Copy to clipboard The member function returns a reference to the element of the controlled sequence at position `pos`. If that position is invalid, the function throws an object of class `out_of_range`. ### `deque::back` reference back(); const_reference back() const;Copy to clipboard The member function returns a reference to the last element of the controlled sequence, which must be non-empty. ### `deque::begin` const_iterator begin() const; iterator begin();Copy to clipboard The member function returns a random-access iterator that points at the first element of the sequence (or just beyond the end of an empty sequence). ### `deque::clear` void clear();Copy to clipboard The member function calls `erase( begin(), end())`. ### `deque::const_iterator` typedef T1 const_iterator;Copy to clipboard The type describes an object that can serve as a constant random-access iterator for the controlled sequence. It is described here as a synonym for the implementation-defined type `T1`. ### `deque::const_pointer` typedef typename Alloc::const_pointer const_pointer;Copy to clipboard The type describes an object that can serve as a constant pointer to an element of the controlled sequence. ### `deque::const_reference` typedef typename Alloc::const_reference const_reference;Copy to clipboard The type describes an object that can serve as a constant reference to an element of the controlled sequence. ### `deque::const_reverse_iterator` typedef reverse_iterator const_reverse_iterator;Copy to clipboard The type describes an object that can serve as a constant reverse random-access iterator for the controlled sequence. ### `deque::deque` deque(); explicit deque(const Alloc& al); explicit deque(size_type count); deque(size_type count, const Ty& val); deque(size_type count, const Ty& val, const Alloc& al); deque(const deque& right); template deque(InIt first, InIt last); template deque(InIt first, InIt last, const Alloc& al);Copy to clipboard All constructors store an [allocator object](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_memory.html#allocator%20object) and initialize the controlled sequence. The allocator object is the argument `al`, if present. For the copy constructor, it is `right.get_allocator()`. Otherwise, it is `Alloc()`. The first two constructors specify an empty initial controlled sequence. The third constructor specifies a repetition of `count` elements of value `Ty()`. The fourth and fifth constructors specify a repetition of `count` elements of value `val`. The sixth constructor specifies a copy of the sequence controlled by `right`. If `InIt` is an integer type, the last two constructors specify a repetition of `(size_type)first` elements of value `(Ty)last`. Otherwise, the last two constructors specify the sequence `[first, last)`. ### `deque::difference_type` typedef T3 difference_type;Copy to clipboard The signed integer type describes an object that can represent the difference between the addresses of any two elements in the controlled sequence. It is described here as a synonym for the implementation-defined type `T3`. ### `deque::empty` bool empty() const;Copy to clipboard The member function returns true for an empty controlled sequence. ### `deque::end` const_iterator end() const; iterator end();Copy to clipboard The member function returns a random-access iterator that points just beyond the end of the sequence. ### `deque::erase` iterator erase(iterator where); iterator erase(iterator first, iterator last);Copy to clipboard The first member function removes the element of the controlled sequence pointed to by `where`. The second member function removes the elements of the controlled sequence in the range `[first, last)`. Both return an iterator that designates the first element remaining beyond any elements removed, or `end()` if no such element exists. Removing `N` elements causes `N` destructor calls and an assignment for each of the elements between the insertion point and the nearer end of the sequence. Removing an element at either end [invalidates](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_deque.html#invalid%20deque%20iterators) only iterators and references that designate the erased elements. Otherwise, erasing an element invalidates all iterators and references. The member functions throw an exception only if a copy operation throws an exception. ### `deque::front` reference front(); const_reference front() const;Copy to clipboard The member function returns a reference to the first element of the controlled sequence, which must be non-empty. ### `deque::get_allocator` Alloc get_allocator() const;Copy to clipboard The member function returns the stored [allocator object](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_memory.html#allocator%20object). ### `deque::insert` iterator insert(iterator where, const Ty& val); void insert(iterator where, size_type count, const Ty& val); template void insert(iterator where, InIt first, InIt last);Copy to clipboard Each of the member functions inserts, before the element pointed to by `where` in the controlled sequence, a sequence specified by the remaining operands. The first member function inserts a single element with value `val` and returns an iterator that designates the newly inserted element. The second member function inserts a repetition of `count` elements of value `val`. If `InIt` is an integer type, the last member function behaves the same as `insert(where, (size_type)first, (Ty)last)`. Otherwise, the last member function inserts the sequence `[first, last)`, which must *not* overlap the initial controlled sequence. When inserting a single element, the number of element copies is linear in the number of elements between the insertion point and the nearer end of the sequence. When inserting a single element at either end of the sequence, the amortized number of element copies is constant. When inserting `N` elements, the number of element copies is linear in `N` plus the number of elements between the insertion point and the nearer end of the sequence -- except when the template member is specialized for `InIt` an input or forward iterator, which behaves like `N` single insertions. Inserting an element at either end [invalidates](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_deque.html#invalid%20deque%20iterators) all iterators, but no references, that designate existing elements. Otherwise, inserting an element invalidates all iterators and references. If an exception is thrown during the insertion of one or more elements, and the exception is not thrown while copying an element, the container is left unaltered and the exception is rethrown. ### `deque::iterator` typedef T0 iterator;Copy to clipboard The type describes an object that can serve as a random-access iterator for the controlled sequence. It is described here as a synonym for the implementation-defined type `T0`. ### `deque::max_size` size_type max_size() const;Copy to clipboard The member function returns the length of the longest sequence that the object can control. ### `deque::operator[]` const_reference operator[](size_type pos) const; reference operator[](size_type pos);Copy to clipboard The member function returns a reference to the element of the controlled sequence at position `pos`. If that position is invalid, the behavior is undefined. ### `deque::pointer` typedef typename Alloc::pointer pointer;Copy to clipboard The type describes an object that can serve as a pointer to an element of the controlled sequence. ### `deque::pop_back` void pop_back();Copy to clipboard The member function removes the last element of the controlled sequence, which must be non-empty. Removing the element [invalidates](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_deque.html#invalid%20deque%20iterators) only iterators and references that designate the erased element. The member function never throws an exception. ### `deque::pop_front` void pop_front();Copy to clipboard The member function removes the first element of the controlled sequence, which must be non-empty. Removing the element [invalidates](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_deque.html#invalid%20deque%20iterators) only iterators and references that designate the erased element. The member function never throws an exception. ### `deque::push_back` void push_back(const Ty& val);Copy to clipboard The member function inserts an element with value `val` at the end of the controlled sequence. Inserting the element [invalidates](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_deque.html#invalid%20deque%20iterators) all iterators, but no references, to existing elements. If an exception is thrown, the container is left unaltered and the exception is rethrown. ### `deque::push_front` void push_front(const Ty& val);Copy to clipboard The member function inserts an element with value `val` at the beginning of the controlled sequence. Inserting the element [invalidates](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_deque.html#invalid%20deque%20iterators) all iterators, but no references, to existing elements. If an exception is thrown, the container is left unaltered and the exception is rethrown. ### `deque::rbegin` const_reverse_iterator rbegin() const; reverse_iterator rbegin();Copy to clipboard The member function returns a reverse iterator that points just beyond the end of the controlled sequence. Hence, it designates the beginning of the reverse sequence. ### `deque::reference` typedef typename Alloc::reference reference;Copy to clipboard The type describes an object that can serve as a reference to an element of the controlled sequence. ### `deque::rend` const_reverse_iterator rend() const; reverse_iterator rend();Copy to clipboard The member function returns a reverse iterator that points at the first element of the sequence (or just beyond the end of an empty sequence). Hence, it designates the end of the reverse sequence. ### `deque::resize` void resize(size_type newsize); void resize(size_type newsize, Ty val);Copy to clipboard The member functions both ensure that `size()` henceforth returns `newsize`. If it must make the controlled sequence longer, the first member function appends elements with value `Ty()`, while the second member function appends elements with value `val`. To make the controlled sequence shorter, both member functions call `erase(begin() + newsize, end())`. ### `deque::reverse_iterator` typedef reverse_iterator reverse_iterator;Copy to clipboard The type describes an object that can serve as a reverse random-access iterator for the controlled sequence. ### `deque::size` size_type size() const;Copy to clipboard The member function returns the length of the controlled sequence. ### `deque::size_type` typedef T2 size_type;Copy to clipboard The unsigned integer type describes an object that can represent the length of any controlled sequence. It is described here as a synonym for the implementation-defined type `T2`. ### `deque::swap` void swap(deque& right);Copy to clipboard The member function swaps the controlled sequences between `*this` and `right`. If `get_allocator() == right.get_allocator()`, it does so in constant time, it throws no exceptions, and it invalidates no references, pointers, or iterators that designate elements in the two controlled sequences. Otherwise, it performs a number of element assignments and constructor calls proportional to the number of elements in the two controlled sequences. ### `deque::value_type` typedef typename Alloc::value_type value_type;Copy to clipboard The type is a synonym for the template parameter `Ty`. ## `operator!=` template bool operator!=( const deque & left, const deque & right);Copy to clipboard The template function returns `!(left == right)`. ## `operator==` template bool operator==( const deque & left, const deque & right);Copy to clipboard The template function overloads `operator==` to compare two objects of template class [`deque`](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_deque.html#deque). The function returns `left.size() == right.size() && equal(left. begin(), left. end(), right.begin())`. ## `operator<` template bool operator<( const deque & left, const deque & right);Copy to clipboard The template function overloads `operator<` to compare two objects of template class [`deque`](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_deque.html#deque). The function returns `lexicographical_compare(left. begin(), left. end(), right.begin(), right.end())`. ## `operator<=` template bool operator<=( const deque & left, const deque & right);Copy to clipboard The template function returns `!(right < left)`. ## `operator>` template bool operator>( const deque & left, const deque & right);Copy to clipboard The template function returns `right < left`. ## `operator>=` template bool operator>=( const deque & left, const deque & right);Copy to clipboard The template function returns `!(left < right)`. ## `swap` template void swap( deque & left, deque & right);Copy to clipboard The template function executes `left.swap(right)`. * * * See also the **[Table of Contents](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_index.html#Table%20of%20Contents)** and the **[Index](https://docs.qualcomm.com/doc/80-N3040-23/topic/_cpp_index.html)**. *[Copyright](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_crit_pjp.html) © 1992-2006by P.J. Plauger. Portions derived from work[copyright](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_crit_hp.html) © 1994by Hewlett-Packard Company. All rights reserved.* Last Published: Oct 06, 2026 Previous Topic Next Topic