C++ std::deque Functions

Beginner
8 min read
Updated: Nov 2026
31 function guides
Function index

About This Index

This page is the C++ std::deque Functions index. Each row links to a full guide with syntax, parameters, return value, three examples, and FAQs.

Learn what a std::deque is on /cpp/deque. Use this page when you need a specific member function such as push_front(), pop_back(), or at().

Fast at both ends.

A std::deque<T> can add and remove at the front and the back quickly, and it also allows d[i] by index. It has no capacity() or reserve(). The 31 functions are listed below.

How to Call a Deque Function

Include <deque>, create the deque, and call members with a dot:

C++
#include <deque>
#include <iostream>

std::deque<int> d = {20, 30};

d.push_front(10);          // 10 20 30
d.push_back(40);           // 10 20 30 40
int first  = d.front();    // 10
int second = d.at(1);      // 20, checked
d.pop_back();              // 10 20 30
std::size_t n = d.size();  // 3

C++ std::deque Functions Table

All function guides in this C++ tutorial series (31 tutorials), grouped by purpose.

Element access

3 functions

Read or change elements by position.

FunctionDescriptionTutorial
at()Read or change one element by index, with a bounds check.Try it
front()Get the first element of the deque.Try it
back()Get the last element of the deque.Try it

Capacity

5 functions

Ask about the size, or change it. A deque has no capacity() or reserve().

FunctionDescriptionTutorial
empty()Check whether the deque has no elements.Try it
size()Get the number of elements in the deque.Try it
max_size()Get the largest number of elements a deque could ever hold.Try it
resize()Change the number of elements, adding or removing at the back.Try it
shrink_to_fit()Ask the deque to release unused memory (C++11, non-binding).Try it

Modifiers

14 functions

Add, remove, or replace elements. Both ends are fast.

FunctionDescriptionTutorial
assign()Replace all elements with new ones.Try it
assign_range()Replace all elements with the items of a range (C++23).Try it
clear()Remove every element from the deque.Try it
insert()Add one or more elements at any position.Try it
insert_range()Insert a whole range at any position (C++23).Try it
erase()Remove one element or a range of elements.Try it
push_back()Add an element at the back.Try it
push_front()Add an element at the front.Try it
pop_back()Remove the last element.Try it
pop_front()Remove the first element.Try it
emplace()Build a new element in place at any position (C++11).Try it
emplace_back()Build a new element in place at the back (C++11).Try it
emplace_front()Build a new element in place at the front (C++11).Try it
swap()Exchange the content of two deques.Try it

Iterators

8 functions

Walk through the deque forwards or backwards. The c versions are read-only.

FunctionDescriptionTutorial
begin()Get an iterator to the first element.Try it
end()Get an iterator one place after the last element.Try it
cbegin()Get a read-only iterator to the first element.Try it
cend()Get a read-only iterator one place after the last element.Try it
rbegin()Get a reverse iterator to the last element.Try it
rend()Get the reverse end marker, just before the first element.Try it
crbegin()Get a read-only reverse iterator to the last element.Try it
crend()Get a read-only reverse end marker, just before the first element.Try it

Allocator

1 function

Access the memory helper object used by the deque.

FunctionDescriptionTutorial
get_allocator()Get a copy of the allocator the deque uses.Try it

Frequently Asked Questions

They are the functions you call on a std::deque object with a dot, such as d.push_front(1), d.pop_back(), d.at(2), or d.size(). They need #include <deque>.
This tutorial series covers 31: element access (at, front, back), capacity (empty, size, max_size, resize, shrink_to_fit), modifiers (assign, assign_range, clear, insert, insert_range, erase, push_back, push_front, pop_back, pop_front, emplace, emplace_back, emplace_front, swap), iterators (begin, end, cbegin, cend, rbegin, rend, crbegin, crend), and get_allocator.
A deque can add and remove at the front quickly with push_front() and pop_front(). A std::vector has no such functions, because it would have to move every element.
No. A deque grows block by block, so it has size() and max_size() but no capacity() and no reserve(). It has shrink_to_fit() as a non-binding request.
Read the C++ std::deque page first. Then open push_back(), push_front(), pop_front(), and at() from the tables below.

Start with push_front()

Add an element at the front, the one thing a vector cannot do quickly.

push_front() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful