C++ std::list Functions

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

About This Index

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

Learn what a std::list is on /cpp/list. Use this page when you need a specific member function such as splice(), sort(), or remove().

A doubly linked list.

A std::list<T> inserts and erases quickly anywhere once you hold an iterator, and it has its own member sort(), merge(), splice(), remove(), unique(), and reverse(). It has no [], at(), capacity(), or reserve(). The 37 functions are listed below.

How to Call a List Function

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

C++
#include <list>
#include <iostream>

std::list<int> l = {30, 10, 20};

l.push_front(5);           // 5 30 10 20
l.push_back(40);           // 5 30 10 20 40
int first = l.front();     // 5
int last  = l.back();      // 40
l.sort();                  // 5 10 20 30 40
l.pop_back();              // 5 10 20 30
std::size_t n = l.size();  // 4

C++ std::list Functions Table

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

Element access

2 functions

Read the first or last element. A list has no [] or at(), because it has no access by index.

FunctionDescriptionTutorial
front()Read or change the first element.Try it
back()Read or change the last element.Try it

Capacity

4 functions

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

FunctionDescriptionTutorial
empty()Check whether the list has no elements.Try it
size()Get the number of elements.Try it
max_size()Get the largest number of elements a list could hold.Try it
resize()Change the number of elements.Try it

Modifiers

14 functions

Add, remove, or replace elements. Both ends are fast, and so is the middle once you hold an iterator.

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()Erase every element from the list.Try it
insert()Add one or more elements before an iterator.Try it
insert_range()Insert the items of a range before an iterator (C++23).Try it
erase()Remove one element or a range of elements by iterator.Try it
push_back()Add an element at the end of the list.Try it
push_front()Add an element at the start of the list.Try it
pop_back()Remove the last element of the list.Try it
pop_front()Remove the first element of the list.Try it
emplace()Build a new element in place before an iterator (C++11).Try it
emplace_back()Build a new last element in place (C++11).Try it
emplace_front()Build a new first element in place (C++11).Try it
swap()Exchange the contents of two lists.Try it

List operations

8 functions

Special member functions that work on the whole list: merge, move nodes, remove by value, reverse, sort, and drop duplicates.

FunctionDescriptionTutorial
merge()Merge another sorted list into this sorted list.Try it
splice()Move nodes from another list into this list without copying.Try it
splice_range()Move a range of nodes from one list into another.Try it
remove()Erase every element equal to a value.Try it
remove_if()Erase every element for which a test returns true.Try it
reverse()Reverse the order of the elements.Try it
sort()Sort the elements of the list (stable).Try it
unique()Erase repeated neighbouring elements.Try it

Iterators

8 functions

Walk through the list 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 (C++11).Try it
cend()Get a read-only iterator one place after the last element (C++11).Try it
rbegin()Get a reverse iterator to the last element.Try it
rend()Get a reverse iterator one place before the first element.Try it
crbegin()Get a read-only reverse iterator to the last element (C++11).Try it
crend()Get a read-only reverse iterator one place before the first element (C++11).Try it

Allocator

1 function

Access the memory helper object used by the list.

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

Frequently Asked Questions

They are the functions you call on a std::list object with a dot, such as l.push_front(1), l.pop_back(), l.sort(), or l.size(). They need #include <list>.
This tutorial series covers 37: element access (front, back), capacity (empty, size, max_size, resize), modifiers (assign, assign_range, clear, insert, insert_range, erase, push_back, push_front, pop_back, pop_front, emplace, emplace_back, emplace_front, swap), list operations (merge, splice, splice_range, remove, remove_if, reverse, sort, unique), iterators (begin, end, cbegin, cend, rbegin, rend, crbegin, crend), and get_allocator.
A list has member functions that relink nodes without copying elements: splice(), merge(), sort(), reverse(), remove(), and unique(). Inserting and erasing in the middle is also fast once you hold an iterator.
No. A list is made of separate nodes, so there is no access by index and no spare capacity. To reach the third element you must move an iterator forward, for example with std::next(l.begin(), 2).
Read the C++ std::list page first. Then open push_back(), push_front(), sort(), and splice() from the tables below.

Start with push_back()

Add an element at the end of a list, the first thing most programs do.

push_back() 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