---
name: "std::list"
section: "3cxx"
platform: "linux"
package: "libstdc++-12-doc"
version: "12.4.0-5"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/std::list/3cxx"
---

# std::list(3cxx)

A standard container with linear time access to elements, and fixed time insertion/deletion at any point in the sequence.

## NAME

std::list\< \_Tp, \_Alloc \> - A standard container with linear time access to elements, and fixed time insertion/deletion at any point in the sequence.

## SYNOPSIS

`#include <list>`

Inherits **std::\_List\_base\< \_Tp, \_Alloc \>**.

### Public Types

**typedef** \_Alloc **allocator\_type**\
 **typedef** **\_List\_const\_iterator**\< \_Tp \> **const\_iterator**\
 **typedef** \_Tp\_alloc\_traits::const\_pointer **const\_pointer**\
 **typedef** \_Tp\_alloc\_traits::const\_reference **const\_reference**\
 **typedef** **std::reverse\_iterator**\< **const\_iterator** \> **const\_reverse\_iterator**\
 **typedef** ptrdiff\_t **difference\_type**\
 **typedef** **\_List\_iterator**\< \_Tp \> **iterator**\
 **typedef** **\_Tp\_alloc\_traits::pointer** **pointer**\
 **typedef** \_Tp\_alloc\_traits::reference **reference**\
 **typedef** **std::reverse\_iterator**\< **iterator** \> **reverse\_iterator**\
 **typedef** size\_t **size\_type**\
 **typedef** \_Tp **value\_type**\

### Public Member Functions

**list** ()=**default**\
 Creates a list with no elements.  template\<**typename** **\_InputIterator** , **typename**  = std::\_RequireInputIter\<\_InputIterator\>\> **list** (**\_InputIterator** \_\_first, **\_InputIterator** \_\_last, const allocator\_type &\_\_a=allocator\_type())\
 Builds a list from a range.  **list** (const allocator\_type &\_\_a) noexcept\
 Creates a list with no elements.  **list** (const **list** &\_\_x)\
 List copy constructor.  **list** (const **list** &\_\_x, const **\_\_type\_identity\_t**\< allocator\_type \> &\_\_a)\
 **list** (**initializer\_list**\< value\_type \> **\_\_l**, const allocator\_type &\_\_a=allocator\_type())\
 Builds a list from an initializer\_list.  **list** (**list** &&)=**default**\
 List move constructor.  **list** (**list** &&\_\_x, const **\_\_type\_identity\_t**\< allocator\_type \> &\_\_a) noexcept(\_Node\_alloc\_traits::\_S\_always\_equal())\
 **list** (size\_type \_\_n, const allocator\_type &\_\_a=allocator\_type())\
 Creates a list with default constructed elements.  **list** (size\_type \_\_n, const value\_type &\_\_value, const allocator\_type &\_\_a=allocator\_type())\
 Creates a list with copies of an exemplar element.  **~list** ()=**default**\
 template\<**typename** **\_InputIterator** , **typename**  = std::\_RequireInputIter\<\_InputIterator\>\> **void** **assign** (**\_InputIterator** \_\_first, **\_InputIterator** \_\_last)\
 Assigns a range to a list.  **void** **assign** (**initializer\_list**\< value\_type \> **\_\_l**)\
 Assigns an initializer\_list to a list.  **void** **assign** (size\_type \_\_n, const value\_type &\_\_val)\
 Assigns a given value to a list.  const\_reference **back** () const noexcept\
 reference **back** () noexcept\
 **const\_iterator** **begin** () const noexcept\
 **iterator** **begin** () noexcept\
 **const\_iterator** **cbegin** () const noexcept\
 **const\_iterator** **cend** () const noexcept\
 **void** **clear** () noexcept\
 **const\_reverse\_iterator** **crbegin** () const noexcept\
 **const\_reverse\_iterator** **crend** () const noexcept\
 template\<typename... \_Args\> **iterator** **emplace** (**const\_iterator** **\_\_position**, **\_Args** &&... **\_\_args**)\
 Constructs object in list before specified iterator.  template\<typename... \_Args\> reference **emplace\_back** (**\_Args** &&... **\_\_args**)\
 template\<typename... \_Args\> reference **emplace\_front** (**\_Args** &&... **\_\_args**)\
 bool **empty** () const noexcept\
 **const\_iterator** **end** () const noexcept\
 **iterator** **end** () noexcept\
 **iterator** **erase** (**const\_iterator** \_\_first, **const\_iterator** \_\_last) noexcept\
 Remove a range of elements.  **iterator** **erase** (**const\_iterator** **\_\_position**) noexcept\
 Remove element at given position.  const\_reference **front** () const noexcept\
 reference **front** () noexcept\
 allocator\_type **get\_allocator** () const noexcept\
 Get a copy of the memory allocation object.  **iterator** **insert** (**const\_iterator** \_\_p, **initializer\_list**\< value\_type \> **\_\_l**)\
 Inserts the contents of an initializer\_list into list before specified const\_iterator.  template\<**typename** **\_InputIterator** , **typename**  = std::\_RequireInputIter\<\_InputIterator\>\> **iterator** **insert** (**const\_iterator** **\_\_position**, **\_InputIterator** \_\_first, **\_InputIterator** \_\_last)\
 Inserts a range into the list.  **iterator** **insert** (**const\_iterator** **\_\_position**, const value\_type &\_\_x)\
 Inserts given value into list before specified iterator.  **iterator** **insert** (**const\_iterator** **\_\_position**, size\_type \_\_n, const value\_type &\_\_x)\
 Inserts a number of copies of given data into the list.  **iterator** **insert** (**const\_iterator** **\_\_position**, value\_type &&\_\_x)\
 Inserts given rvalue into list before specified iterator.  size\_type **max\_size** () const noexcept\
 **void** **merge** (**list** &&\_\_x)\
 Merge sorted lists.  template\<**typename** **\_StrictWeakOrdering** \> **void** **merge** (**list** &&\_\_x, **\_StrictWeakOrdering** \_\_comp)\
 Merge sorted lists according to comparison function.  **void** **merge** (**list** &\_\_x)\
 template\<**typename** **\_StrictWeakOrdering** \> **void** **merge** (**list** &\_\_x, **\_StrictWeakOrdering** \_\_comp)\
 **list** & **operator=** (const **list** &\_\_x)\
 List assignment operator.  **list** & **operator=** (**initializer\_list**\< value\_type \> **\_\_l**)\
 List initializer list assignment operator.  **list** & **operator=** (**list** &&\_\_x) noexcept(\_Node\_alloc\_traits::\_S\_nothrow\_move())\
 List move assignment operator.  **void** **pop\_back** () noexcept\
 Removes last element.  **void** **pop\_front** () noexcept\
 Removes first element.  **void** **push\_back** (const value\_type &\_\_x)\
 Add data to the end of the list.  **void** **push\_back** (value\_type &&\_\_x)\
 **void** **push\_front** (const value\_type &\_\_x)\
 Add data to the front of the list.  **void** **push\_front** (value\_type &&\_\_x)\
 **const\_reverse\_iterator** **rbegin** () const noexcept\
 **reverse\_iterator** **rbegin** () noexcept\
 \_\_remove\_return\_type **remove** (const \_Tp &\_\_value)\
 Remove all elements equal to value.  template\<**typename** \_Predicate \> \_\_remove\_return\_type **remove\_if** (\_Predicate)\
 Remove all elements satisfying a predicate.  **const\_reverse\_iterator** **rend** () const noexcept\
 **reverse\_iterator** **rend** () noexcept\
 **void** **resize** (size\_type **\_\_new\_size**)\
 Resizes the list to the specified number of elements.  **void** **resize** (size\_type **\_\_new\_size**, const value\_type &\_\_x)\
 Resizes the list to the specified number of elements.  **void** **reverse** () noexcept\
 Reverse the elements in list.  size\_type **size** () const noexcept\
 **void** **sort** ()\
 Sort the elements.  template\<**typename** **\_StrictWeakOrdering** \> **void** **sort** (**\_StrictWeakOrdering**)\
 Sort the elements according to comparison function.  **void** **splice** (**const\_iterator** **\_\_position**, **list** &&\_\_x) noexcept\
 Insert contents of another list.  **void** **splice** (**const\_iterator** **\_\_position**, **list** &&\_\_x, **const\_iterator** \_\_first, **const\_iterator** \_\_last) noexcept\
 Insert range from another list.  **void** **splice** (**const\_iterator** **\_\_position**, **list** &&\_\_x, **const\_iterator** \_\_i) noexcept\
 Insert element from another list.  **void** **splice** (**const\_iterator** **\_\_position**, **list** &\_\_x) noexcept\
 **void** **splice** (**const\_iterator** **\_\_position**, **list** &\_\_x, **const\_iterator** \_\_first, **const\_iterator** \_\_last) noexcept\
 Insert range from another list.  **void** **splice** (**const\_iterator** **\_\_position**, **list** &\_\_x, **const\_iterator** \_\_i) noexcept\
 Insert element from another list.  **void** **swap** (**list** &\_\_x) noexcept\
 Swaps data with another list.  \_\_remove\_return\_type **unique** ()\
 Remove consecutive duplicate elements.  template\<**typename** **\_BinaryPredicate** \> \_\_remove\_return\_type **unique** (**\_BinaryPredicate**)\
 Remove consecutive elements satisfying a predicate.

### Protected Types

**typedef** **\_List\_node**\< \_Tp \> **\_Node**\

### Protected Member Functions

template\<**typename** **\_InputIterator** \> **void** **\_M\_assign\_dispatch** (**\_InputIterator** \_\_first, **\_InputIterator** \_\_last, \_\_false\_type)\
 template\<**typename** **\_Integer** \> **void** **\_M\_assign\_dispatch** (**\_Integer** \_\_n, **\_Integer** \_\_val, \_\_true\_type)\
 **void** **\_M\_check\_equal\_allocators** (**list** &\_\_x) noexcept\
 **void** **\_M\_clear** () noexcept\
 template\<typename... \_Args\> **\_Node** \* **\_M\_create\_node** (**\_Args** &&... **\_\_args**)\
 **void** **\_M\_dec\_size** (size\_t)\
 **void** **\_M\_default\_append** (size\_type \_\_n)\
 **void** **\_M\_default\_initialize** (size\_type \_\_n)\
 size\_t **\_M\_distance** (const **void** \*, const **void** \*) const\
 **void** **\_M\_erase** (**iterator** **\_\_position**) noexcept\
 **void** **\_M\_fill\_assign** (size\_type \_\_n, const value\_type &\_\_val)\
 **void** **\_M\_fill\_initialize** (size\_type \_\_n, const value\_type &\_\_x)\
 **\_Node\_alloc\_traits::pointer** **\_M\_get\_node** ()\
 const \_Node\_alloc\_type & **\_M\_get\_Node\_allocator** () const noexcept\
 \_Node\_alloc\_type & **\_M\_get\_Node\_allocator** () noexcept\
 size\_t **\_M\_get\_size** () const\
 **void** **\_M\_inc\_size** (size\_t)\
 **void** **\_M\_init** () noexcept\
 template\<**typename** **\_InputIterator** \> **void** **\_M\_initialize\_dispatch** (**\_InputIterator** \_\_first, **\_InputIterator** \_\_last, \_\_false\_type)\
 template\<**typename** **\_Integer** \> **void** **\_M\_initialize\_dispatch** (**\_Integer** \_\_n, **\_Integer** \_\_x, \_\_true\_type)\
 template\<typename... \_Args\> **void** **\_M\_insert** (**iterator** **\_\_position**, **\_Args** &&... **\_\_args**)\
 **void** **\_M\_move\_assign** (**list** &&\_\_x, **false\_type**)\
 **void** **\_M\_move\_assign** (**list** &&\_\_x, **true\_type**) noexcept\
 **void** **\_M\_move\_nodes** (**\_List\_base** &&\_\_x)\
 size\_t **\_M\_node\_count** () const\
 **void** **\_M\_put\_node** (**typename** **\_Node\_alloc\_traits::pointer** \_\_p) noexcept\
 **const\_iterator** **\_M\_resize\_pos** (size\_type &**\_\_new\_size**) const\
 **void** **\_M\_set\_size** (size\_t)\
 **void** **\_M\_transfer** (**iterator** **\_\_position**, **iterator** \_\_first, **iterator** \_\_last)\

### Static Protected Member Functions

**static** size\_t **\_S\_distance** (const **\_\_detail::\_List\_node\_base** \*\_\_first, const **\_\_detail::\_List\_node\_base** \*\_\_last)\
 **static** size\_t **\_S\_distance** (**const\_iterator**, **const\_iterator**)\

### Protected Attributes

\_List\_impl **\_M\_impl**\

## Detailed Description

### template\<typename \_Tp, typename \_Alloc = std::allocator\<\_Tp\>\>

class std::list\< \_Tp, \_Alloc \>"A standard container with linear time access to elements, and fixed time insertion/deletion at any point in the sequence.

**Template Parameters**

*\_Tp* Type of element. \
 *\_Alloc* Allocator type, defaults to allocator\<\_Tp\>.

Meets the requirements of a `container`, a `reversible container`, and a `sequence`, including the `optional sequence requirements` with the exception of `at` and `operator`\[\].

This is a *doubly* *linked* list. Traversal up and down the list requires linear time, but adding and removing elements (or *nodes*) is done in constant time, regardless of where the change takes place. Unlike std::vector and std::deque, random-access iterators are not provided, so subscripting ( \[\] ) access is not allowed. For algorithms which only need sequential access, this lack makes no difference.

Also unlike the other standard containers, std::list provides specialized algorithms unique to linked lists, such as splicing, sorting, and in-place reversal.

A couple points on memory allocation for list\<Tp\>:

First, we never actually allocate a Tp, we allocate List\_node\<Tp\>'s and trust \[20.1.5\]/4 to DTRT. This is to ensure that after elements from list\<X,Alloc1\> are spliced into list\<X,Alloc2\>, destroying the memory of the second list is a valid operation, i.e., Alloc1 giveth and Alloc2 taketh away.

Second, a list conceptually represented as

```
A <---> B <---> C <---> D
```

 is actually circular; a link exists between A and D. The list class holds (as its only data member) a private list::iterator pointing to *D*, not to *A!* To get to the head of the list, we start at the tail and move forward by one. When this member iterator's next/previous pointers refer to itself, the list is empty.

## Constructor & Destructor Documentation

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> std::list\< \_Tp, \_Alloc \>::list ()` [default]`

Creates a list with no elements.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> std::list\< \_Tp, \_Alloc \>::list (const allocator\_type & \_\_a)` [inline]`, ` [explicit]`, ` [noexcept]`

Creates a list with no elements.

**Parameters**

*\_\_a* An allocator object.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> std::list\< \_Tp, \_Alloc \>::list (size\_type \_\_n, const allocator\_type & \_\_a = `allocator_type()`)` [inline]`, ` [explicit]`

Creates a list with default constructed elements.

**Parameters**

*\_\_n* The number of elements to initially create. \
 *\_\_a* An allocator object.

This constructor fills the list with *\_\_n* default constructed elements.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> std::list\< \_Tp, \_Alloc \>::list (size\_type \_\_n, const value\_type & \_\_value, const allocator\_type & \_\_a = `allocator_type()`)` [inline]`

Creates a list with copies of an exemplar element.

**Parameters**

*\_\_n* The number of elements to initially create. \
 *\_\_value* An element to copy. \
 *\_\_a* An allocator object.

This constructor fills the list with *\_\_n* copies of *\_\_value*.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> std::list\< \_Tp, \_Alloc \>::list (const list\< \_Tp, \_Alloc \> & \_\_x)` [inline]`

List copy constructor.

**Parameters**

*\_\_x* A list of identical element and allocator types.

The newly-created list uses a copy of the allocation object used by *\_\_x* (unless the allocator traits dictate a different object).

References **std::list\< \_Tp, \_Alloc \>::begin()**, and **std::list\< \_Tp, \_Alloc \>::end()**.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> std::list\< \_Tp, \_Alloc \>::list (list\< \_Tp, \_Alloc \> &&)` [default]`

List move constructor. The newly-created list contains the exact contents of the moved instance. The contents of the moved instance are a valid, but unspecified list.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> std::list\< \_Tp, \_Alloc \>::list (initializer\_list\< value\_type \> \_\_l, const allocator\_type & \_\_a = `allocator_type()`)` [inline]`

Builds a list from an initializer\_list.

**Parameters**

*\_\_l* An initializer\_list of value\_type. \
 *\_\_a* An allocator object.

Create a list consisting of copies of the elements in the initializer\_list *\_\_l*. This is linear in \_\_l.size().

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> template\<typename \_InputIterator , typename = std::\_RequireInputIter\<\_InputIterator\>\> std::list\< \_Tp, \_Alloc \>::list (\_InputIterator \_\_first, \_InputIterator \_\_last, const allocator\_type & \_\_a = `allocator_type()`)` [inline]`

Builds a list from a range.

**Parameters**

*\_\_first* An input iterator. \
 *\_\_last* An input iterator. \
 *\_\_a* An allocator object.

Create a list consisting of copies of the elements from \[*\_\_first*,*\_\_last*). This is linear in N (where N is distance(*\_\_first*,*\_\_last*)).

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> std::list\< \_Tp, \_Alloc \>::~list ()` [default]`

No explicit dtor needed as the \_Base dtor takes care of things. The \_Base dtor only erases the elements, and note that if the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility.

## Member Function Documentation

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> template\<typename... \_Args\> \_Node \* std::list\< \_Tp, \_Alloc \>::\_M\_create\_node (\_Args &&... \_\_args)` [inline]`, ` [protected]`

**Parameters**

*\_\_args* An instance of user data.

Allocates space for a new node and constructs a copy of *\_\_args* in it.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> template\<typename \_InputIterator , typename = std::\_RequireInputIter\<\_InputIterator\>\> void std::list\< \_Tp, \_Alloc \>::assign (\_InputIterator \_\_first, \_InputIterator \_\_last)` [inline]`

Assigns a range to a list.

**Parameters**

*\_\_first* An input iterator. \
 *\_\_last* An input iterator.

This function fills a list with copies of the elements in the range \[*\_\_first*,*\_\_last*).

Note that the assignment completely changes the list and that the resulting list's size is the same as the number of elements assigned.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> void std::list\< \_Tp, \_Alloc \>::assign (initializer\_list\< value\_type \> \_\_l)` [inline]`

Assigns an initializer\_list to a list.

**Parameters**

*\_\_l* An initializer\_list of value\_type.

Replace the contents of the list with copies of the elements in the initializer\_list *\_\_l*. This is linear in \_\_l.size().

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> void std::list\< \_Tp, \_Alloc \>::assign (size\_type \_\_n, const value\_type & \_\_val)` [inline]`

Assigns a given value to a list.

**Parameters**

*\_\_n* Number of elements to be assigned. \
 *\_\_val* Value to be assigned.

This function fills a list with *\_\_n* copies of the given value. Note that the assignment completely changes the list and that the resulting list's size is the same as the number of elements assigned.

Referenced by **std::list\< \_Tp, \_Alloc \>::operator=()**.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> const\_reference std::list\< \_Tp, \_Alloc \>::back () const` [inline]`, ` [noexcept]`

Returns a read-only (constant) reference to the data at the last element of the list.

References **std::list\< \_Tp, \_Alloc \>::end()**.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> reference std::list\< \_Tp, \_Alloc \>::back ()` [inline]`, ` [noexcept]`

Returns a read/write reference to the data at the last element of the list.

References **std::list\< \_Tp, \_Alloc \>::end()**.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> const\_iterator std::list\< \_Tp, \_Alloc \>::begin () const` [inline]`, ` [noexcept]`

Returns a read-only (constant) iterator that points to the first element in the list. Iteration is done in ordinary element order.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> iterator std::list\< \_Tp, \_Alloc \>::begin ()` [inline]`, ` [noexcept]`

Returns a read/write iterator that points to the first element in the list. Iteration is done in ordinary element order.

Referenced by **std::list\< \_Tp, \_Alloc \>::list()**, **std::list\< \_Tp, \_Alloc \>::crend()**, **std::list\< \_Tp, \_Alloc \>::front()**, **std::list\< \_Tp, \_Alloc \>::front()**, **std::list\< \_Tp, \_Alloc \>::merge()**, **std::list\< \_Tp, \_Alloc \>::merge()**, **std::list\< \_Tp, \_Alloc \>::operator=()**, **std::list\< \_Tp, \_Alloc \>::pop\_front()**, **std::list\< \_Tp, \_Alloc \>::push\_front()**, **std::list\< \_Tp, \_Alloc \>::rend()**, **std::list\< \_Tp, \_Alloc \>::rend()**, and **std::list\< \_Tp, \_Alloc \>::splice()**.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> const\_iterator std::list\< \_Tp, \_Alloc \>::cbegin () const` [inline]`, ` [noexcept]`

Returns a read-only (constant) iterator that points to the first element in the list. Iteration is done in ordinary element order.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> const\_iterator std::list\< \_Tp, \_Alloc \>::cend () const` [inline]`, ` [noexcept]`

Returns a read-only (constant) iterator that points one past the last element in the list. Iteration is done in ordinary element order.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> void std::list\< \_Tp, \_Alloc \>::clear ()` [inline]`, ` [noexcept]`

Erases all the elements. Note that this function only erases the elements, and that if the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> const\_reverse\_iterator std::list\< \_Tp, \_Alloc \>::crbegin () const` [inline]`, ` [noexcept]`

Returns a read-only (constant) reverse iterator that points to the last element in the list. Iteration is done in reverse element order.

References **std::list\< \_Tp, \_Alloc \>::end()**.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> const\_reverse\_iterator std::list\< \_Tp, \_Alloc \>::crend () const` [inline]`, ` [noexcept]`

Returns a read-only (constant) reverse iterator that points to one before the first element in the list. Iteration is done in reverse element order.

References **std::list\< \_Tp, \_Alloc \>::begin()**.

### template\<typename \_Tp , typename \_Alloc \> template\<typename... \_Args\> list\< \_Tp, \_Alloc \>::iterator list::emplace (const\_iterator \_\_position, \_Args &&... \_\_args)

Constructs object in list before specified iterator.

**Parameters**

*\_\_position* A const\_iterator into the list. \
 *\_\_args* Arguments.

**Returns**

An iterator that points to the inserted data.

This function will insert an object of type T constructed with T(std::forward\<Args\>(args)...) before the specified location. Due to the nature of a list this operation can be done in constant time, and does not invalidate iterators and references.

Referenced by **std::list\< \_Tp, \_Alloc \>::insert()**.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> bool std::list\< \_Tp, \_Alloc \>::empty () const` [inline]`, ` [noexcept]`

Returns true if the list is empty. (Thus begin() would equal end().)

Referenced by **std::list\< \_Tp, \_Alloc \>::splice()**.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> const\_iterator std::list\< \_Tp, \_Alloc \>::end () const` [inline]`, ` [noexcept]`

Returns a read-only (constant) iterator that points one past the last element in the list. Iteration is done in ordinary element order.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> iterator std::list\< \_Tp, \_Alloc \>::end ()` [inline]`, ` [noexcept]`

Returns a read/write iterator that points one past the last element in the list. Iteration is done in ordinary element order.

Referenced by **std::list\< \_Tp, \_Alloc \>::list()**, **std::list\< \_Tp, \_Alloc \>::back()**, **std::list\< \_Tp, \_Alloc \>::back()**, **std::list\< \_Tp, \_Alloc \>::crbegin()**, **std::list\< \_Tp, \_Alloc \>::merge()**, **std::list\< \_Tp, \_Alloc \>::merge()**, **std::list\< \_Tp, \_Alloc \>::operator=()**, **std::list\< \_Tp, \_Alloc \>::push\_back()**, **std::list\< \_Tp, \_Alloc \>::rbegin()**, **std::list\< \_Tp, \_Alloc \>::rbegin()**, and **std::list\< \_Tp, \_Alloc \>::splice()**.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> iterator std::list\< \_Tp, \_Alloc \>::erase (const\_iterator \_\_first, const\_iterator \_\_last)` [inline]`, ` [noexcept]`

Remove a range of elements.

**Parameters**

*\_\_first* Iterator pointing to the first element to be erased. \
 *\_\_last* Iterator pointing to one past the last element to be erased.

**Returns**

An iterator pointing to the element pointed to by *last* prior to erasing (or end()).

This function will erase the elements in the range \[first,last) and shorten the list accordingly.

This operation is linear time in the size of the range and only invalidates iterators/references to the element being removed. The user is also cautioned that this function only erases the elements, and that if the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility.

References **std::list\< \_Tp, \_Alloc \>::erase()**.

### template\<typename \_Tp , typename \_Alloc \> list\< \_Tp, \_Alloc \>::iterator list::erase (const\_iterator \_\_position)` [noexcept]`

Remove element at given position.

**Parameters**

*\_\_position* Iterator pointing to element to be erased.

**Returns**

An iterator pointing to the next element (or end()).

This function will erase the element at the given position and thus shorten the list by one.

Due to the nature of a list this operation can be done in constant time, and only invalidates iterators/references to the element being removed. The user is also cautioned that this function only erases the element, and that if the element is itself a pointer, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility.

Referenced by **std::list\< \_Tp, \_Alloc \>::erase()**.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> const\_reference std::list\< \_Tp, \_Alloc \>::front () const` [inline]`, ` [noexcept]`

Returns a read-only (constant) reference to the data at the first element of the list.

References **std::list\< \_Tp, \_Alloc \>::begin()**.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> reference std::list\< \_Tp, \_Alloc \>::front ()` [inline]`, ` [noexcept]`

Returns a read/write reference to the data at the first element of the list.

References **std::list\< \_Tp, \_Alloc \>::begin()**.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> allocator\_type std::list\< \_Tp, \_Alloc \>::get\_allocator () const` [inline]`, ` [noexcept]`

Get a copy of the memory allocation object.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> iterator std::list\< \_Tp, \_Alloc \>::insert (const\_iterator \_\_p, initializer\_list\< value\_type \> \_\_l)` [inline]`

Inserts the contents of an initializer\_list into list before specified const\_iterator.

**Parameters**

*\_\_p* A const\_iterator into the list. \
 *\_\_l* An initializer\_list of value\_type.

**Returns**

An iterator pointing to the first element inserted (or \_\_position).

This function will insert copies of the data in the initializer\_list *l* into the list before the location specified by *p*.

This operation is linear in the number of elements inserted and does not invalidate iterators and references.

References **std::list\< \_Tp, \_Alloc \>::insert()**.

### template\<typename \_Tp , typename \_Alloc \> template\<typename \_InputIterator , typename \> list\< \_Tp, \_Alloc \>::iterator list::insert (const\_iterator \_\_position, \_InputIterator \_\_first, \_InputIterator \_\_last)

Inserts a range into the list.

**Parameters**

*\_\_position* A const\_iterator into the list. \
 *\_\_first* An input iterator. \
 *\_\_last* An input iterator.

**Returns**

An iterator pointing to the first element inserted (or \_\_position).

This function will insert copies of the data in the range \[*first*,*last*) into the list before the location specified by *position*.

This operation is linear in the number of elements inserted and does not invalidate iterators and references.

### template\<typename \_Tp , typename \_Alloc \> list\< \_Tp, \_Alloc \>::iterator list::insert (const\_iterator \_\_position, const value\_type & \_\_x)

Inserts given value into list before specified iterator.

**Parameters**

*\_\_position* A const\_iterator into the list. \
 *\_\_x* Data to be inserted.

**Returns**

An iterator that points to the inserted data.

This function will insert a copy of the given value before the specified location. Due to the nature of a list this operation can be done in constant time, and does not invalidate iterators and references.

Referenced by **std::list\< \_Tp, \_Alloc \>::insert()**.

### template\<typename \_Tp , typename \_Alloc \> list\< \_Tp, \_Alloc \>::iterator list::insert (const\_iterator \_\_position, size\_type \_\_n, const value\_type & \_\_x)

Inserts a number of copies of given data into the list.

**Parameters**

*\_\_position* A const\_iterator into the list. \
 *\_\_n* Number of elements to be inserted. \
 *\_\_x* Data to be inserted.

**Returns**

An iterator pointing to the first element inserted (or \_\_position).

This function will insert a specified number of copies of the given data before the location specified by *position*.

This operation is linear in the number of elements inserted and does not invalidate iterators and references.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> iterator std::list\< \_Tp, \_Alloc \>::insert (const\_iterator \_\_position, value\_type && \_\_x)` [inline]`

Inserts given rvalue into list before specified iterator.

**Parameters**

*\_\_position* A const\_iterator into the list. \
 *\_\_x* Data to be inserted.

**Returns**

An iterator that points to the inserted data.

This function will insert a copy of the given rvalue before the specified location. Due to the nature of a list this operation can be done in constant time, and does not invalidate iterators and references.

References **std::list\< \_Tp, \_Alloc \>::emplace()**, and **std::move()**.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> size\_type std::list\< \_Tp, \_Alloc \>::max\_size () const` [inline]`, ` [noexcept]`

Returns the size() of the largest possible list. \

References **\_\_gnu\_cxx::\_\_alloc\_traits\< \_Alloc, typename \>::max\_size()**.

### template\<typename \_Tp , typename \_Alloc \> void list::merge (list\< \_Tp, \_Alloc \> && \_\_x)

Merge sorted lists.

**Parameters**

*\_\_x* Sorted list to merge.

Assumes that both *\_\_x* and this list are sorted according to operator\<(). Merges elements of *\_\_x* into this list in sorted order, leaving *\_\_x* empty when complete. Elements in this list precede elements in *\_\_x* that are equal.

References **std::\_\_addressof()**, **std::list\< \_Tp, \_Alloc \>::begin()**, **std::begin()**, **std::list\< \_Tp, \_Alloc \>::end()**, and **std::end()**.

### template\<typename \_Tp , typename \_Alloc \> template\<typename \_StrictWeakOrdering \> void list::merge (list\< \_Tp, \_Alloc \> && \_\_x, \_StrictWeakOrdering \_\_comp)

Merge sorted lists according to comparison function.

**Template Parameters**

*\_StrictWeakOrdering* Comparison function defining sort order.

**Parameters**

*\_\_x* Sorted list to merge. \
 *\_\_comp* Comparison functor.

Assumes that both *\_\_x* and this list are sorted according to StrictWeakOrdering. Merges elements of *\_\_x* into this list in sorted order, leaving *\_\_x* empty when complete. Elements in this list precede elements in *\_\_x* that are equivalent according to StrictWeakOrdering().

References **std::\_\_addressof()**, **std::list\< \_Tp, \_Alloc \>::begin()**, **std::begin()**, **std::list\< \_Tp, \_Alloc \>::end()**, and **std::end()**.

### template\<typename \_Tp , typename \_Alloc \> list\< \_Tp, \_Alloc \> & list::operator= (const list\< \_Tp, \_Alloc \> & \_\_x)

List assignment operator.

**Parameters**

*\_\_x* A list of identical element and allocator types.

All the elements of *\_\_x* are copied.

Whether the allocator is copied depends on the allocator traits.

References **std::\_\_addressof()**, **std::list\< \_Tp, \_Alloc \>::begin()**, and **std::list\< \_Tp, \_Alloc \>::end()**.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> list & std::list\< \_Tp, \_Alloc \>::operator= (initializer\_list\< value\_type \> \_\_l)` [inline]`

List initializer list assignment operator.

**Parameters**

*\_\_l* An initializer\_list of value\_type.

Replace the contents of the list with copies of the elements in the initializer\_list *\_\_l*. This is linear in l.size().

References **std::list\< \_Tp, \_Alloc \>::assign()**.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> list & std::list\< \_Tp, \_Alloc \>::operator= (list\< \_Tp, \_Alloc \> && \_\_x)` [inline]`, ` [noexcept]`

List move assignment operator.

**Parameters**

*\_\_x* A list of identical element and allocator types.

The contents of *\_\_x* are moved into this list (without copying).

Afterwards *\_\_x* is a valid, but unspecified list

Whether the allocator is moved depends on the allocator traits.

References **std::move()**.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> void std::list\< \_Tp, \_Alloc \>::pop\_back ()` [inline]`, ` [noexcept]`

Removes last element. This is a typical stack operation. It shrinks the list by one. Due to the nature of a list this operation can be done in constant time, and only invalidates iterators/references to the element being removed.

Note that no data is returned, and if the last element's data is needed, it should be retrieved before pop\_back() is called.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> void std::list\< \_Tp, \_Alloc \>::pop\_front ()` [inline]`, ` [noexcept]`

Removes first element. This is a typical stack operation. It shrinks the list by one. Due to the nature of a list this operation can be done in constant time, and only invalidates iterators/references to the element being removed.

Note that no data is returned, and if the first element's data is needed, it should be retrieved before pop\_front() is called.

References **std::list\< \_Tp, \_Alloc \>::begin()**.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> void std::list\< \_Tp, \_Alloc \>::push\_back (const value\_type & \_\_x)` [inline]`

Add data to the end of the list.

**Parameters**

*\_\_x* Data to be added.

This is a typical stack operation. The function creates an element at the end of the list and assigns the given data to it. Due to the nature of a list this operation can be done in constant time, and does not invalidate iterators and references.

References **std::list\< \_Tp, \_Alloc \>::end()**.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> void std::list\< \_Tp, \_Alloc \>::push\_front (const value\_type & \_\_x)` [inline]`

Add data to the front of the list.

**Parameters**

*\_\_x* Data to be added.

This is a typical stack operation. The function creates an element at the front of the list and assigns the given data to it. Due to the nature of a list this operation can be done in constant time, and does not invalidate iterators and references.

References **std::list\< \_Tp, \_Alloc \>::begin()**.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> const\_reverse\_iterator std::list\< \_Tp, \_Alloc \>::rbegin () const` [inline]`, ` [noexcept]`

Returns a read-only (constant) reverse iterator that points to the last element in the list. Iteration is done in reverse element order.

References **std::list\< \_Tp, \_Alloc \>::end()**.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> reverse\_iterator std::list\< \_Tp, \_Alloc \>::rbegin ()` [inline]`, ` [noexcept]`

Returns a read/write reverse iterator that points to the last element in the list. Iteration is done in reverse element order.

References **std::list\< \_Tp, \_Alloc \>::end()**.

### template\<typename \_Tp , typename \_Alloc \> list\< \_Tp, \_Alloc \>::\_\_remove\_return\_type list::remove (const \_Tp & \_\_value)

Remove all elements equal to value.

**Parameters**

*\_\_value* The value to remove.

Removes every element in the list equal to *value*. Remaining elements stay in list order. Note that this function only erases the elements, and that if the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility.

References **std::begin()**, and **std::end()**.

### template\<typename \_Tp , typename \_Alloc \> template\<typename \_Predicate \> list\< \_Tp, \_Alloc \>::\_\_remove\_return\_type list::remove\_if (\_Predicate \_\_pred)

Remove all elements satisfying a predicate.

**Template Parameters**

*\_Predicate* Unary predicate function or object.

Removes every element in the list for which the predicate returns true. Remaining elements stay in list order. Note that this function only erases the elements, and that if the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility.

References **std::begin()**, and **std::end()**.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> const\_reverse\_iterator std::list\< \_Tp, \_Alloc \>::rend () const` [inline]`, ` [noexcept]`

Returns a read-only (constant) reverse iterator that points to one before the first element in the list. Iteration is done in reverse element order.

References **std::list\< \_Tp, \_Alloc \>::begin()**.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> reverse\_iterator std::list\< \_Tp, \_Alloc \>::rend ()` [inline]`, ` [noexcept]`

Returns a read/write reverse iterator that points to one before the first element in the list. Iteration is done in reverse element order.

References **std::list\< \_Tp, \_Alloc \>::begin()**.

### template\<typename \_Tp , typename \_Alloc \> void list::resize (size\_type \_\_new\_size)

Resizes the list to the specified number of elements.

**Parameters**

*\_\_new\_size* Number of elements the list should contain.

This function will resize the list to the specified number of elements. If the number is smaller than the list's current size the list is truncated, otherwise default constructed elements are appended.

References **std::end()**.

### template\<typename \_Tp , typename \_Alloc \> void list::resize (size\_type \_\_new\_size, const value\_type & \_\_x)

Resizes the list to the specified number of elements.

**Parameters**

*\_\_new\_size* Number of elements the list should contain. \
 *\_\_x* Data with which new elements should be populated.

This function will resize the list to the specified number of elements. If the number is smaller than the list's current size the list is truncated, otherwise the list is extended and new elements are populated with given data.

References **std::end()**.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> void std::list\< \_Tp, \_Alloc \>::reverse ()` [inline]`, ` [noexcept]`

Reverse the elements in list. Reverse the order of elements in the list in linear time.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> size\_type std::list\< \_Tp, \_Alloc \>::size () const` [inline]`, ` [noexcept]`

Returns the number of elements in the list. \

### template\<typename \_Tp , typename \_Alloc \> void list::sort ()

Sort the elements. Sorts the elements of this list in NlogN time. Equivalent elements remain in list order.

References **std::begin()**, **std::empty()**, and **std::end()**.

### template\<typename \_Tp , typename \_Alloc \> template\<typename \_StrictWeakOrdering \> void list::sort (\_StrictWeakOrdering \_\_comp)

Sort the elements according to comparison function. Sorts the elements of this list in NlogN time. Equivalent elements remain in list order.

References **std::begin()**, **std::empty()**, and **std::end()**.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> void std::list\< \_Tp, \_Alloc \>::splice (const\_iterator \_\_position, list\< \_Tp, \_Alloc \> && \_\_x)` [inline]`, ` [noexcept]`

Insert contents of another list.

**Parameters**

*\_\_position* Iterator referencing the element to insert before. \
 *\_\_x* Source list.

The elements of *\_\_x* are inserted in constant time in front of the element referenced by *\_\_position*. *\_\_x* becomes an empty list.

Requires this != *\_\_x*.

References **std::list\< \_Tp, \_Alloc \>::begin()**, **std::list\< \_Tp, \_Alloc \>::empty()**, and **std::list\< \_Tp, \_Alloc \>::end()**.

Referenced by **std::list\< \_Tp, \_Alloc \>::splice()**, and **std::list\< \_Tp, \_Alloc \>::splice()**.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> void std::list\< \_Tp, \_Alloc \>::splice (const\_iterator \_\_position, list\< \_Tp, \_Alloc \> && \_\_x, const\_iterator \_\_first, const\_iterator \_\_last)` [inline]`, ` [noexcept]`

Insert range from another list.

**Parameters**

*\_\_position* Const\_iterator referencing the element to insert before. \
 *\_\_x* Source list. \
 *\_\_first* Const\_iterator referencing the start of range in x. \
 *\_\_last* Const\_iterator referencing the end of range in x.

Removes elements in the range \[\_\_first,\_\_last) and inserts them before *\_\_position* in constant time.

Undefined if *\_\_position* is in \[\_\_first,\_\_last).

References **std::\_\_addressof()**.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> void std::list\< \_Tp, \_Alloc \>::splice (const\_iterator \_\_position, list\< \_Tp, \_Alloc \> && \_\_x, const\_iterator \_\_i)` [inline]`, ` [noexcept]`

Insert element from another list.

**Parameters**

*\_\_position* Const\_iterator referencing the element to insert before. \
 *\_\_x* Source list. \
 *\_\_i* Const\_iterator referencing the element to move.

Removes the element in list *\_\_x* referenced by *\_\_i* and inserts it into the current list before *\_\_position*.

References **std::\_\_addressof()**.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> void std::list\< \_Tp, \_Alloc \>::splice (const\_iterator \_\_position, list\< \_Tp, \_Alloc \> & \_\_x, const\_iterator \_\_first, const\_iterator \_\_last)` [inline]`, ` [noexcept]`

Insert range from another list.

**Parameters**

*\_\_position* Const\_iterator referencing the element to insert before. \
 *\_\_x* Source list. \
 *\_\_first* Const\_iterator referencing the start of range in x. \
 *\_\_last* Const\_iterator referencing the end of range in x.

Removes elements in the range \[\_\_first,\_\_last) and inserts them before *\_\_position* in constant time.

Undefined if *\_\_position* is in \[\_\_first,\_\_last).

References **std::move()**, and **std::list\< \_Tp, \_Alloc \>::splice()**.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> void std::list\< \_Tp, \_Alloc \>::splice (const\_iterator \_\_position, list\< \_Tp, \_Alloc \> & \_\_x, const\_iterator \_\_i)` [inline]`, ` [noexcept]`

Insert element from another list.

**Parameters**

*\_\_position* Const\_iterator referencing the element to insert before. \
 *\_\_x* Source list. \
 *\_\_i* Const\_iterator referencing the element to move.

Removes the element in list *\_\_x* referenced by *\_\_i* and inserts it into the current list before *\_\_position*.

References **std::move()**, and **std::list\< \_Tp, \_Alloc \>::splice()**.

### template\<typename \_Tp , typename \_Alloc = std::allocator\<\_Tp\>\> void std::list\< \_Tp, \_Alloc \>::swap (list\< \_Tp, \_Alloc \> & \_\_x)` [inline]`, ` [noexcept]`

Swaps data with another list.

**Parameters**

*\_\_x* A list of the same element and allocator types.

This exchanges the elements between two lists in constant time. Note that the global std::swap() function is specialized such that std::swap(l1,l2) will feed to this function.

Whether the allocators are swapped depends on the allocator traits.

### template\<typename \_Tp , typename \_Alloc \> list\< \_Tp, \_Alloc \>::\_\_remove\_return\_type list::unique ()

Remove consecutive duplicate elements. For each consecutive set of elements with the same value, remove all but the first one. Remaining elements stay in list order. Note that this function only erases the elements, and that if the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility.

References **std::begin()**, and **std::end()**.

### template\<typename \_Tp , typename \_Alloc \> template\<typename \_BinaryPredicate \> list\< \_Tp, \_Alloc \>::\_\_remove\_return\_type list::unique (\_BinaryPredicate \_\_binary\_pred)

Remove consecutive elements satisfying a predicate.

**Template Parameters**

*\_BinaryPredicate* Binary predicate function or object.

For each consecutive set of elements \[first,last) that satisfy predicate(first,i) where i is an iterator in \[first,last), remove all but the first one. Remaining elements stay in list order. Note that this function only erases the elements, and that if the elements themselves are pointers, the pointed-to memory is not touched in any way. Managing the pointer is the user's responsibility.

References **std::begin()**, and **std::end()**.

## Author

Generated automatically by Doxygen for libstdc++ from the source code.
