---
name: "std::forward_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::forward_list/3cxx"
---

# std::forward\_list(3cxx)

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

## NAME

std::forward\_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 <forward_list>`

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

### Public Types

**typedef** \_Alloc **allocator\_type**\
 **typedef** **\_Base::const\_iterator** **const\_iterator**\
 **typedef** \_Alloc\_traits::const\_pointer **const\_pointer**\
 **typedef** const value\_type & **const\_reference**\
 **typedef** std::ptrdiff\_t **difference\_type**\
 **typedef** **\_Base::iterator** **iterator**\
 **typedef** \_Alloc\_traits::pointer **pointer**\
 **typedef** value\_type & **reference**\
 **typedef** std::size\_t **size\_type**\
 **typedef** \_Tp **value\_type**\

### Public Member Functions

**forward\_list** ()=**default**\
 Creates a forward\_list with no elements.  template\<**typename** **\_InputIterator** , **typename**  = std::\_RequireInputIter\<\_InputIterator\>\> **forward\_list** (**\_InputIterator** \_\_first, **\_InputIterator** \_\_last, const \_Alloc &**\_\_al**=\_Alloc())\
 Builds a forward\_list from a range.  **forward\_list** (const \_Alloc &**\_\_al**) noexcept\
 Creates a forward\_list with no elements.  **forward\_list** (const **forward\_list** &**\_\_list**)\
 The forward\_list copy constructor.  **forward\_list** (const **forward\_list** &**\_\_list**, const **\_\_type\_identity\_t**\< \_Alloc \> &**\_\_al**)\
 Copy constructor with allocator argument.  **forward\_list** (**forward\_list** &&)=**default**\
 The forward\_list move constructor.  **forward\_list** (**forward\_list** &&**\_\_list**, const **\_\_type\_identity\_t**\< \_Alloc \> &**\_\_al**) noexcept(\_Node\_alloc\_traits::\_S\_always\_equal())\
 Move constructor with allocator argument.  **forward\_list** (size\_type \_\_n, const \_Alloc &**\_\_al**=\_Alloc())\
 Creates a forward\_list with default constructed elements.  **forward\_list** (size\_type \_\_n, const \_Tp &\_\_value, const \_Alloc &**\_\_al**=\_Alloc())\
 Creates a forward\_list with copies of an exemplar element.  **forward\_list** (**std::initializer\_list**\< \_Tp \> **\_\_il**, const \_Alloc &**\_\_al**=\_Alloc())\
 Builds a forward\_list from an initializer\_list.  **~forward\_list** () noexcept\
 The forward\_list dtor.  template\<**typename** **\_InputIterator** , **typename**  = std::\_RequireInputIter\<\_InputIterator\>\> **void** **assign** (**\_InputIterator** \_\_first, **\_InputIterator** \_\_last)\
 Assigns a range to a forward\_list.  **void** **assign** (size\_type \_\_n, const \_Tp &\_\_val)\
 Assigns a given value to a forward\_list.  **void** **assign** (**std::initializer\_list**\< \_Tp \> **\_\_il**)\
 Assigns an initializer\_list to a forward\_list.  **const\_iterator** **before\_begin** () const noexcept\
 **iterator** **before\_begin** () noexcept\
 **const\_iterator** **begin** () const noexcept\
 **iterator** **begin** () noexcept\
 **const\_iterator** **cbefore\_begin** () const noexcept\
 **const\_iterator** **cbegin** () const noexcept\
 **const\_iterator** **cend** () const noexcept\
 **void** **clear** () noexcept\
 Erases all the elements.  template\<typename... \_Args\> **iterator** **emplace\_after** (**const\_iterator** **\_\_pos**, **\_Args** &&... **\_\_args**)\
 Constructs object in forward\_list after the specified iterator.  template\<typename... \_Args\> reference **emplace\_front** (**\_Args** &&... **\_\_args**)\
 Constructs object in forward\_list at the front of the list.  bool **empty** () const noexcept\
 **const\_iterator** **end** () const noexcept\
 **iterator** **end** () noexcept\
 **iterator** **erase\_after** (**const\_iterator** **\_\_pos**)\
 Removes the element pointed to by the iterator following `pos`.  **iterator** **erase\_after** (**const\_iterator** **\_\_pos**, **const\_iterator** \_\_last)\
 Remove a range of elements.  reference **front** ()\
 const\_reference **front** () const\
 allocator\_type **get\_allocator** () const noexcept\
 Get a copy of the memory allocation object.  template\<**typename** **\_InputIterator** , **typename**  = std::\_RequireInputIter\<\_InputIterator\>\> **iterator** **insert\_after** (**const\_iterator** **\_\_pos**, **\_InputIterator** \_\_first, **\_InputIterator** \_\_last)\
 Inserts a range into the forward\_list.  **iterator** **insert\_after** (**const\_iterator** **\_\_pos**, \_Tp &&\_\_val)\
 **iterator** **insert\_after** (**const\_iterator** **\_\_pos**, const \_Tp &\_\_val)\
 Inserts given value into forward\_list after specified iterator.  **iterator** **insert\_after** (**const\_iterator** **\_\_pos**, size\_type \_\_n, const \_Tp &\_\_val)\
 Inserts a number of copies of given data into the forward\_list.  **iterator** **insert\_after** (**const\_iterator** **\_\_pos**, **std::initializer\_list**\< \_Tp \> **\_\_il**)\
 Inserts the contents of an initializer\_list into forward\_list after the specified iterator.  size\_type **max\_size** () const noexcept\
 **void** **merge** (**forward\_list** &&**\_\_list**)\
 Merge sorted lists.  template\<**typename** **\_Comp** \> **void** **merge** (**forward\_list** &&**\_\_list**, **\_Comp** \_\_comp)\
 Merge sorted lists according to comparison function.  **void** **merge** (**forward\_list** &**\_\_list**)\
 template\<**typename** **\_Comp** \> **void** **merge** (**forward\_list** &**\_\_list**, **\_Comp** \_\_comp)\
 **forward\_list** & **operator=** (const **forward\_list** &**\_\_list**)\
 The forward\_list assignment operator.  **forward\_list** & **operator=** (**forward\_list** &&**\_\_list**) noexcept(\_Node\_alloc\_traits::\_S\_nothrow\_move())\
 The forward\_list move assignment operator.  **forward\_list** & **operator=** (**std::initializer\_list**\< \_Tp \> **\_\_il**)\
 The forward\_list initializer list assignment operator.  **void** **pop\_front** ()\
 Removes first element.  **void** **push\_front** (\_Tp &&\_\_val)\
 **void** **push\_front** (const \_Tp &\_\_val)\
 Add data to the front of the forward\_list.  \_\_remove\_return\_type **remove** (const \_Tp &\_\_val)\
 Remove all elements equal to value.  template\<**typename** **\_Pred** \> \_\_remove\_return\_type **remove\_if** (**\_Pred** **\_\_pred**)\
 Remove all elements satisfying a predicate.  template\<**typename** **\_Pred** \> **auto** **remove\_if** (**\_Pred** **\_\_pred**) -\> \_\_remove\_return\_type\
 **void** **resize** (size\_type **\_\_sz**)\
 Resizes the forward\_list to the specified number of elements.  **void** **resize** (size\_type **\_\_sz**, const value\_type &\_\_val)\
 Resizes the forward\_list to the specified number of elements.  **void** **reverse** () noexcept\
 Reverse the elements in list.  **void** **sort** ()\
 Sort the elements of the list.  template\<**typename** **\_Comp** \> **void** **sort** (**\_Comp** \_\_comp)\
 Sort the forward\_list using a comparison function.  **void** **splice\_after** (**const\_iterator** **\_\_pos**, **forward\_list** &&**\_\_list**) noexcept\
 Insert contents of another forward\_list.  **void** **splice\_after** (**const\_iterator** **\_\_pos**, **forward\_list** &&**\_\_list**, **const\_iterator** \_\_i) noexcept\
 Insert element from another forward\_list.  **void** **splice\_after** (**const\_iterator** **\_\_pos**, **forward\_list** &**\_\_list**) noexcept\
 **void** **splice\_after** (**const\_iterator** **\_\_pos**, **forward\_list** &**\_\_list**, **const\_iterator** \_\_i) noexcept\
 **void** **swap** (**forward\_list** &**\_\_list**) noexcept\
 Swaps data with another forward\_list.  \_\_remove\_return\_type **unique** ()\
 Remove consecutive duplicate elements.  template\<**typename** **\_BinPred** \> \_\_remove\_return\_type **unique** (**\_BinPred** **\_\_binary\_pred**)\
 Remove consecutive elements satisfying a predicate.  template\<**typename** **\_BinPred** \> **auto** **unique** (**\_BinPred** **\_\_binary\_pred**) -\> \_\_remove\_return\_type\

**void** **splice\_after** (**const\_iterator** **\_\_pos**, **forward\_list** &&, **const\_iterator** **\_\_before**, **const\_iterator** \_\_last) noexcept\
 Insert range from another forward\_list.  **void** **splice\_after** (**const\_iterator** **\_\_pos**, **forward\_list** &, **const\_iterator** **\_\_before**, **const\_iterator** \_\_last) noexcept\
 Insert range from another forward\_list.

## Detailed Description

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

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

**Since**

C++11

**Template Parameters**

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

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

This is a *singly* *linked* list. Traversal up 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::forward\_list provides specialized algorithms unique to linked lists, such as splicing, sorting, and in-place reversal.

## Constructor & Destructor Documentation

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

Creates a forward\_list with no elements.

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

Creates a forward\_list with no elements.

**Parameters**

*\_\_al* An allocator object.

### template\<typename \_Tp , typename \_Alloc = allocator\<\_Tp\>\> std::forward\_list\< \_Tp, \_Alloc \>::forward\_list (const forward\_list\< \_Tp, \_Alloc \> & \_\_list, const \_\_type\_identity\_t\< \_Alloc \> & \_\_al)` [inline]`

Copy constructor with allocator argument.

**Parameters**

*\_\_list* Input list to copy. \
 *\_\_al* An allocator object.

### template\<typename \_Tp , typename \_Alloc = allocator\<\_Tp\>\> std::forward\_list\< \_Tp, \_Alloc \>::forward\_list (forward\_list\< \_Tp, \_Alloc \> && \_\_list, const \_\_type\_identity\_t\< \_Alloc \> & \_\_al)` [inline]`, ` [noexcept]`

Move constructor with allocator argument.

**Parameters**

*\_\_list* Input list to move. \
 *\_\_al* An allocator object.

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

Creates a forward\_list with default constructed elements.

**Parameters**

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

This constructor creates the forward\_list with *\_\_n* default constructed elements.

### template\<typename \_Tp , typename \_Alloc = allocator\<\_Tp\>\> std::forward\_list\< \_Tp, \_Alloc \>::forward\_list (size\_type \_\_n, const \_Tp & \_\_value, const \_Alloc & \_\_al = `_Alloc()`)` [inline]`

Creates a forward\_list with copies of an exemplar element.

**Parameters**

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

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

### template\<typename \_Tp , typename \_Alloc = allocator\<\_Tp\>\> template\<typename \_InputIterator , typename = std::\_RequireInputIter\<\_InputIterator\>\> std::forward\_list\< \_Tp, \_Alloc \>::forward\_list (\_InputIterator \_\_first, \_InputIterator \_\_last, const \_Alloc & \_\_al = `_Alloc()`)` [inline]`

Builds a forward\_list from a range.

**Parameters**

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

Create a forward\_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 = allocator\<\_Tp\>\> std::forward\_list\< \_Tp, \_Alloc \>::forward\_list (const forward\_list\< \_Tp, \_Alloc \> & \_\_list)` [inline]`

The forward\_list copy constructor.

**Parameters**

*\_\_list* A forward\_list of identical element and allocator types.

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

The forward\_list move constructor.

**Parameters**

*\_\_list* A forward\_list of identical element and allocator types.

The newly-created forward\_list contains the exact contents of the moved instance. The contents of the moved instance are a valid, but unspecified forward\_list.

### template\<typename \_Tp , typename \_Alloc = allocator\<\_Tp\>\> std::forward\_list\< \_Tp, \_Alloc \>::forward\_list (std::initializer\_list\< \_Tp \> \_\_il, const \_Alloc & \_\_al = `_Alloc()`)` [inline]`

Builds a forward\_list from an initializer\_list.

**Parameters**

*\_\_il* An initializer\_list of value\_type. \
 *\_\_al* An allocator object.

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

### template\<typename \_Tp , typename \_Alloc = allocator\<\_Tp\>\> std::forward\_list\< \_Tp, \_Alloc \>::~forward\_list ()` [inline]`, ` [noexcept]`

The forward\_list dtor.

## Member Function Documentation

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

Assigns a range to a forward\_list.

**Parameters**

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

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

Note that the assignment completely changes the forward\_list and that the number of elements of the resulting forward\_list is the same as the number of elements assigned.

Referenced by **std::forward\_list\< \_Tp, \_Alloc \>::assign()**, and **std::forward\_list\< \_Tp, \_Alloc \>::operator=()**.

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

Assigns a given value to a forward\_list.

**Parameters**

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

This function fills a forward\_list with *\_\_n* copies of the given value. Note that the assignment completely changes the forward\_list, and that the resulting forward\_list has \_\_n elements.

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

Assigns an initializer\_list to a forward\_list.

**Parameters**

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

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

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

### template\<typename \_Tp , typename \_Alloc = allocator\<\_Tp\>\> const\_iterator std::forward\_list\< \_Tp, \_Alloc \>::before\_begin () const` [inline]`, ` [noexcept]`

Returns a read-only (constant) iterator that points before the first element in the forward\_list. Iteration is done in ordinary element order.

### template\<typename \_Tp , typename \_Alloc = allocator\<\_Tp\>\> iterator std::forward\_list\< \_Tp, \_Alloc \>::before\_begin ()` [inline]`, ` [noexcept]`

Returns a read/write iterator that points before the first element in the forward\_list. Iteration is done in ordinary element order.

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

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

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

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

### template\<typename \_Tp , typename \_Alloc = allocator\<\_Tp\>\> const\_iterator std::forward\_list\< \_Tp, \_Alloc \>::cbefore\_begin () const` [inline]`, ` [noexcept]`

Returns a read-only (constant) iterator that points before the first element in the forward\_list. Iteration is done in ordinary element order.

Referenced by **std::forward\_list\< \_Tp, \_Alloc \>::emplace\_front()**, and **std::forward\_list\< \_Tp, \_Alloc \>::push\_front()**.

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

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

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

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

### template\<typename \_Tp , typename \_Alloc = allocator\<\_Tp\>\> void std::forward\_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 = allocator\<\_Tp\>\> template\<typename... \_Args\> iterator std::forward\_list\< \_Tp, \_Alloc \>::emplace\_after (const\_iterator \_\_pos, \_Args &&... \_\_args)` [inline]`

Constructs object in forward\_list after the specified iterator.

**Parameters**

*\_\_pos* A const\_iterator into the forward\_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)...) after the specified location. Due to the nature of a forward\_list this operation can be done in constant time, and does not invalidate iterators and references.

### template\<typename \_Tp , typename \_Alloc = allocator\<\_Tp\>\> template\<typename... \_Args\> reference std::forward\_list\< \_Tp, \_Alloc \>::emplace\_front (\_Args &&... \_\_args)` [inline]`

Constructs object in forward\_list at the front of the list.

**Parameters**

*\_\_args* Arguments.

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

References **std::forward\_list\< \_Tp, \_Alloc \>::cbefore\_begin()**, and **std::forward\_list\< \_Tp, \_Alloc \>::front()**.

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

Returns true if the forward\_list is empty. (Thus begin() would equal end().)

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

Returns a read-only iterator that points one past the last element in the forward\_list. Iteration is done in ordinary element order.

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

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

### template\<typename \_Tp , typename \_Alloc = allocator\<\_Tp\>\> iterator std::forward\_list\< \_Tp, \_Alloc \>::erase\_after (const\_iterator \_\_pos)` [inline]`

Removes the element pointed to by the iterator following `pos`.

**Parameters**

*\_\_pos* Iterator pointing before element to be erased.

**Returns**

An iterator pointing to the element following the one that was erased, or end() if no such element exists.

This function will erase the element at the given position and thus shorten the forward\_list by one.

Due to the nature of a forward\_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.

### template\<typename \_Tp , typename \_Alloc = allocator\<\_Tp\>\> iterator std::forward\_list\< \_Tp, \_Alloc \>::erase\_after (const\_iterator \_\_pos, const\_iterator \_\_last)` [inline]`

Remove a range of elements.

**Parameters**

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

**Returns**

@ \_\_last.

This function will erase the elements in the range (\_\_pos,\_\_last) and shorten the forward\_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.

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

Returns a read/write reference to the data at the first element of the forward\_list.

Referenced by **std::forward\_list\< \_Tp, \_Alloc \>::emplace\_front()**.

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

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

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

Get a copy of the memory allocation object.

### template\<typename \_Tp , typename \_Alloc \> template\<typename \_InputIterator , typename \> forward\_list\< \_Tp, \_Alloc \>::iterator forward\_list::insert\_after (const\_iterator \_\_pos, \_InputIterator \_\_first, \_InputIterator \_\_last)

Inserts a range into the forward\_list.

**Parameters**

*\_\_pos* An iterator into the forward\_list. \
 *\_\_first* An input iterator. \
 *\_\_last* An input iterator.

**Returns**

An iterator pointing to the last inserted element or *\_\_pos* if *\_\_first* == *\_\_last*.

This function will insert copies of the data in the range \[*\_\_first*,*\_\_last*) into the forward\_list after the location specified by *\_\_pos*.

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

### template\<typename \_Tp , typename \_Alloc = allocator\<\_Tp\>\> iterator std::forward\_list\< \_Tp, \_Alloc \>::insert\_after (const\_iterator \_\_pos, const \_Tp & \_\_val)` [inline]`

Inserts given value into forward\_list after specified iterator.

**Parameters**

*\_\_pos* An iterator into the forward\_list. \
 *\_\_val* Data to be inserted.

**Returns**

An iterator that points to the inserted data.

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

Referenced by **std::forward\_list\< \_Tp, \_Alloc \>::insert\_after()**.

### template\<typename \_Tp , typename \_Alloc \> forward\_list\< \_Tp, \_Alloc \>::iterator forward\_list::insert\_after (const\_iterator \_\_pos, size\_type \_\_n, const \_Tp & \_\_val)

Inserts a number of copies of given data into the forward\_list.

**Parameters**

*\_\_pos* An iterator into the forward\_list. \
 *\_\_n* Number of elements to be inserted. \
 *\_\_val* Data to be inserted.

**Returns**

An iterator pointing to the last inserted copy of *val* or *pos* if *n* == 0.

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

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

### template\<typename \_Tp , typename \_Alloc = allocator\<\_Tp\>\> iterator std::forward\_list\< \_Tp, \_Alloc \>::insert\_after (const\_iterator \_\_pos, std::initializer\_list\< \_Tp \> \_\_il)` [inline]`

Inserts the contents of an initializer\_list into forward\_list after the specified iterator.

**Parameters**

*\_\_pos* An iterator into the forward\_list. \
 *\_\_il* An initializer\_list of value\_type.

**Returns**

An iterator pointing to the last inserted element or *\_\_pos* if *\_\_il* is empty.

This function will insert copies of the data in the initializer\_list *\_\_il* into the forward\_list before the location specified by *\_\_pos*.

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

References **std::forward\_list\< \_Tp, \_Alloc \>::insert\_after()**.

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

Returns the largest possible number of elements of forward\_list.

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

### template\<typename \_Tp , typename \_Alloc = allocator\<\_Tp\>\> void std::forward\_list\< \_Tp, \_Alloc \>::merge (forward\_list\< \_Tp, \_Alloc \> && \_\_list)` [inline]`

Merge sorted lists.

**Parameters**

*\_\_list* Sorted list to merge.

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

References **std::forward\_list\< \_Tp, \_Alloc \>::merge()**, and **std::move()**.

Referenced by **std::forward\_list\< \_Tp, \_Alloc \>::merge()**.

### template\<typename \_Tp , typename \_Alloc \> template\<typename \_Comp \> void forward\_list::merge (forward\_list\< \_Tp, \_Alloc \> && \_\_list, \_Comp \_\_comp)

Merge sorted lists according to comparison function.

**Parameters**

*\_\_list* Sorted list to merge. \
 *\_\_comp* Comparison function defining sort order.

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

References **std::\_\_addressof()**, and **std::move()**.

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

The forward\_list assignment operator.

**Parameters**

*\_\_list* A forward\_list of identical element and allocator types.

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

Whether the allocator is copied depends on the allocator traits.

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

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

The forward\_list move assignment operator.

**Parameters**

*\_\_list* A forward\_list of identical element and allocator types.

The contents of *\_\_list* are moved into this forward\_list (without copying, if the allocators permit it).

Afterwards *\_\_list* is a valid, but unspecified forward\_list

Whether the allocator is moved depends on the allocator traits.

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

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

The forward\_list initializer list assignment operator.

**Parameters**

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

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

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

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

Removes first element. This is a typical stack operation. It shrinks the forward\_list by one. Due to the nature of a forward\_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.

### template\<typename \_Tp , typename \_Alloc = allocator\<\_Tp\>\> void std::forward\_list\< \_Tp, \_Alloc \>::push\_front (const \_Tp & \_\_val)` [inline]`

Add data to the front of the forward\_list.

**Parameters**

*\_\_val* Data to be added.

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

References **std::forward\_list\< \_Tp, \_Alloc \>::cbefore\_begin()**.

### template\<typename \_Tp , typename \_Alloc \> auto forward\_list::remove (const \_Tp & \_\_val)

Remove all elements equal to value.

**Parameters**

*\_\_val* The value to remove.

Removes every element in the list equal to *\_\_val*. 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.

### template\<typename \_Tp , typename \_Alloc = allocator\<\_Tp\>\> template\<typename \_Pred \> \_\_remove\_return\_type std::forward\_list\< \_Tp, \_Alloc \>::remove\_if (\_Pred \_\_pred)

Remove all elements satisfying a predicate.

**Parameters**

*\_\_pred* 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.

### template\<typename \_Tp , typename \_Alloc \> void forward\_list::resize (size\_type \_\_sz)

Resizes the forward\_list to the specified number of elements.

**Parameters**

*\_\_sz* Number of elements the forward\_list should contain.

This function will resize the forward\_list to the specified number of elements. If the number is smaller than the forward\_list's current number of elements the forward\_list is truncated, otherwise the forward\_list is extended and the new elements are default constructed.

### template\<typename \_Tp , typename \_Alloc \> void forward\_list::resize (size\_type \_\_sz, const value\_type & \_\_val)

Resizes the forward\_list to the specified number of elements.

**Parameters**

*\_\_sz* Number of elements the forward\_list should contain. \
 *\_\_val* Data with which new elements should be populated.

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

### template\<typename \_Tp , typename \_Alloc = allocator\<\_Tp\>\> void std::forward\_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 = allocator\<\_Tp\>\> void std::forward\_list\< \_Tp, \_Alloc \>::sort ()` [inline]`

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

References **std::forward\_list\< \_Tp, \_Alloc \>::sort()**.

Referenced by **std::forward\_list\< \_Tp, \_Alloc \>::sort()**.

### template\<typename \_Tp , class \_Alloc \> template\<typename \_Comp \> void forward\_list::sort (\_Comp \_\_comp)

Sort the forward\_list using a comparison function. Sorts the elements of this list in NlogN time. Equivalent elements remain in list order.

### template\<typename \_Tp , typename \_Alloc = allocator\<\_Tp\>\> void std::forward\_list\< \_Tp, \_Alloc \>::splice\_after (const\_iterator \_\_pos, forward\_list\< \_Tp, \_Alloc \> &&, const\_iterator \_\_before, const\_iterator \_\_last)` [inline]`, ` [noexcept]`

Insert range from another forward\_list.

**Parameters**

*\_\_pos* Iterator referencing the element to insert after. \
 *\_\_list* Source list. \
 *\_\_before* Iterator referencing before the start of range in list. \
 *\_\_last* Iterator referencing the end of range in list.

Removes elements in the range (\_\_before,\_\_last) and inserts them after *\_\_pos* in constant time.

Undefined if *\_\_pos* is in (\_\_before,\_\_last).

### template\<typename \_Tp , typename \_Alloc = allocator\<\_Tp\>\> void std::forward\_list\< \_Tp, \_Alloc \>::splice\_after (const\_iterator \_\_pos, forward\_list\< \_Tp, \_Alloc \> && \_\_list)` [inline]`, ` [noexcept]`

Insert contents of another forward\_list.

**Parameters**

*\_\_pos* Iterator referencing the element to insert after. \
 *\_\_list* Source list.

The elements of *list* are inserted in constant time after the element referenced by *pos*. *list* becomes an empty list.

Requires this != *x*.

### template\<typename \_Tp , typename \_Alloc \> void forward\_list::splice\_after (const\_iterator \_\_pos, forward\_list\< \_Tp, \_Alloc \> && \_\_list, const\_iterator \_\_i)` [noexcept]`

Insert element from another forward\_list.

**Parameters**

*\_\_pos* Iterator referencing the element to insert after. \
 *\_\_list* Source list. \
 *\_\_i* Iterator referencing the element before the element to move.

Removes the element in list *list* referenced by *i* and inserts it into the current list after *pos*.

### template\<typename \_Tp , typename \_Alloc = allocator\<\_Tp\>\> void std::forward\_list\< \_Tp, \_Alloc \>::splice\_after (const\_iterator \_\_pos, forward\_list\< \_Tp, \_Alloc \> &, const\_iterator \_\_before, const\_iterator \_\_last)` [inline]`, ` [noexcept]`

Insert range from another forward\_list.

**Parameters**

*\_\_pos* Iterator referencing the element to insert after. \
 *\_\_list* Source list. \
 *\_\_before* Iterator referencing before the start of range in list. \
 *\_\_last* Iterator referencing the end of range in list.

Removes elements in the range (\_\_before,\_\_last) and inserts them after *\_\_pos* in constant time.

Undefined if *\_\_pos* is in (\_\_before,\_\_last).

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

Swaps data with another forward\_list.

**Parameters**

*\_\_list* A forward\_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.

References **std::swap()**.

### template\<typename \_Tp , typename \_Alloc = allocator\<\_Tp\>\> \_\_remove\_return\_type std::forward\_list\< \_Tp, \_Alloc \>::unique ()` [inline]`

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::forward\_list\< \_Tp, \_Alloc \>::unique()**.

Referenced by **std::forward\_list\< \_Tp, \_Alloc \>::unique()**.

### template\<typename \_Tp , typename \_Alloc = allocator\<\_Tp\>\> template\<typename \_BinPred \> \_\_remove\_return\_type std::forward\_list\< \_Tp, \_Alloc \>::unique (\_BinPred \_\_binary\_pred)

Remove consecutive elements satisfying a predicate.

**Parameters**

*\_\_binary\_pred* 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.

## Author

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