libstdc++: std::forward_list< _Tp, _Alloc > Class Template Reference

libstdc++

std::forward_list< _Tp, _Alloc > Class Template Reference
Containers » Sequences

`#include <forward_list>`

Inheritance diagram for std::forward_list< _Tp, _Alloc >:
[legend]

## 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
template<typename _InputIterator, typename = std::_RequireInputIter<_InputIterator>>
| forward_list (_InputIterator __first, _InputIterator __last, const _Alloc &__al=_Alloc())
| forward_list (const _Alloc &__al) noexcept
| forward_list (const forward_list &__list)
| forward_list (const forward_list &__list, const __type_identity_t< _Alloc > &__al)
| forward_list (forward_list &&)=default
| forward_list (forward_list &&__list, const __type_identity_t< _Alloc > &__al) noexcept(_Node_alloc_traits::_S_always_equal())
| forward_list (size_type __n, const _Alloc &__al=_Alloc())
| forward_list (size_type __n, const _Tp &__value, const _Alloc &__al=_Alloc())
| forward_list (std::initializer_list< _Tp > __il, const _Alloc &__al=_Alloc())
| ~forward_list () noexcept
template<typename _InputIterator, typename = std::_RequireInputIter<_InputIterator>>
void | assign (_InputIterator __first, _InputIterator __last)
void | assign (size_type __n, const _Tp &__val)
void | assign (std::initializer_list< _Tp > __il)
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
template<typename... _Args>
iterator | emplace_after (const_iterator __pos, _Args &&... __args)
template<typename... _Args>
reference | emplace_front (_Args &&... __args)
bool | empty () const noexcept
const_iterator | end () const noexcept
iterator | end () noexcept
iterator | erase_after (const_iterator __pos)
iterator | erase_after (const_iterator __pos, const_iterator __last)
reference | front ()
const_reference | front () const
allocator_type | get_allocator () const noexcept
template<typename _InputIterator, typename = std::_RequireInputIter<_InputIterator>>
iterator | insert_after (const_iterator __pos, _InputIterator __first, _InputIterator __last)
iterator | insert_after (const_iterator __pos, _Tp &&__val)
iterator | insert_after (const_iterator __pos, const _Tp &__val)
iterator | insert_after (const_iterator __pos, size_type __n, const _Tp &__val)
iterator | insert_after (const_iterator __pos, std::initializer_list< _Tp > __il)
size_type | max_size () const noexcept
void | merge (forward_list &&__list)
template<typename _Comp>
void | merge (forward_list &&__list, _Comp __comp)
void | merge (forward_list &__list)
template<typename _Comp>
void | merge (forward_list &__list, _Comp __comp)
forward_list & | operator= (const forward_list &__list)
forward_list & | operator= (forward_list &&__list) noexcept(_Node_alloc_traits::_S_nothrow_move())
forward_list & | operator= (std::initializer_list< _Tp > __il)
void | pop_front ()
void | push_front (_Tp &&__val)
void | push_front (const _Tp &__val)
__remove_return_type | remove (const _Tp &__val)
template<typename _Pred>
__remove_return_type | remove_if (_Pred __pred)
void | resize (size_type __sz)
void | resize (size_type __sz, const value_type &__val)
void | reverse () noexcept
void | sort ()
template<typename _Comp>
void | sort (_Comp __comp)
void | splice_after (const_iterator __pos, forward_list &&__list) noexcept
void | splice_after (const_iterator __pos, forward_list &&__list, const_iterator __i) noexcept
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
__remove_return_type | unique ()
template<typename _BinPred>
__remove_return_type | unique (_BinPred __binary_pred)
void | splice_after (const_iterator __pos, forward_list &&, const_iterator __before, const_iterator __last) noexcept
void | splice_after (const_iterator __pos, forward_list &, const_iterator __before, const_iterator __last) noexcept

## 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.

Definition at line 767 of file forward_list.h.

## Member Typedef Documentation

## ◆ allocator_type

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

typedef _Alloc std::forward_list< _Tp, _Alloc >::allocator_type

Definition at line 796 of file forward_list.h.

## ◆ const_iterator

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

typedef _Base::const_iterator std::forward_list< _Tp, _Alloc >::const_iterator

Definition at line 793 of file forward_list.h.

## ◆ const_pointer

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

typedef _Alloc_traits::const_pointer std::forward_list< _Tp, _Alloc >::const_pointer

Definition at line 788 of file forward_list.h.

## ◆ const_reference

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

typedef const value_type& std::forward_list< _Tp, _Alloc >::const_reference

Definition at line 790 of file forward_list.h.

## ◆ difference_type

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

typedef std::ptrdiff_t std::forward_list< _Tp, _Alloc >::difference_type

Definition at line 795 of file forward_list.h.

## ◆ iterator

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

typedef _Base::iterator std::forward_list< _Tp, _Alloc >::iterator

Definition at line 792 of file forward_list.h.

## ◆ pointer

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

typedef _Alloc_traits::pointer std::forward_list< _Tp, _Alloc >::pointer

Definition at line 787 of file forward_list.h.

## ◆ reference

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

typedef value_type& std::forward_list< _Tp, _Alloc >::reference

Definition at line 789 of file forward_list.h.

## ◆ size_type

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

typedef std::size_t std::forward_list< _Tp, _Alloc >::size_type

Definition at line 794 of file forward_list.h.

## ◆ value_type

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

typedef _Tp std::forward_list< _Tp, _Alloc >::value_type

Definition at line 786 of file forward_list.h.

## Constructor & Destructor Documentation

## ◆ forward_list() [1/10]

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

std::forward_list< _Tp, _Alloc >::forward_list | ( |  | ) |
| default

Creates a forward_list with no elements.

Referenced by insert_after(), insert_after(), merge(), operator=(), remove(), remove_if(), resize(), resize(), sort(), splice_after(), and unique().

## ◆ forward_list() [2/10]

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

std::forward_list< _Tp, _Alloc >::forward_list | ( | const _Alloc & | __al | ) |
| inlineexplicitnoexcept

Creates a forward_list with no elements.

Parameters

  __al | An allocator object.

Definition at line 810 of file forward_list.h.

## ◆ forward_list() [3/10]

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.

Definition at line 819 of file forward_list.h.

## ◆ forward_list() [4/10]

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 )
| inlinenoexcept

Move constructor with allocator argument.

Parameters

  __list | Input list to move.
  __al | An allocator object.

Definition at line 848 of file forward_list.h.

## ◆ forward_list() [5/10]

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

std::forward_list< _Tp, _Alloc >::forward_list | ( | size_type | __n,
|  | const _Alloc & | __al = _Alloc() )
| inlineexplicit

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.

Definition at line 864 of file forward_list.h.

## ◆ forward_list() [6/10]

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.

Definition at line 877 of file forward_list.h.

## ◆ forward_list() [7/10]

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)).

Definition at line 894 of file forward_list.h.

## ◆ forward_list() [8/10]

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.

Definition at line 928 of file forward_list.h.

## ◆ forward_list() [9/10]

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.

## ◆ forward_list() [10/10]

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

Definition at line 952 of file forward_list.h.

## ◆ ~forward_list()

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

std::forward_list< _Tp, _Alloc >::~forward_list | ( |  | ) |
| inlinenoexcept

The forward_list dtor.

Definition at line 960 of file forward_list.h.

## Member Function Documentation

## ◆ assign() [1/3]

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.

Definition at line 1047 of file forward_list.h.

Referenced by std::forward_list< _Tp, polymorphic_allocator< _Tp > >::assign(), operator=(), std::forward_list< _Tp, polymorphic_allocator< _Tp > >::operator=(), and std::forward_list< _Tp, polymorphic_allocator< _Tp > >::operator=().

## ◆ assign() [2/3]

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.

Definition at line 1120 of file forward_list.h.

## ◆ assign() [3/3]

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

Definition at line 1156 of file forward_list.h.

## ◆ before_begin() [1/2]

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

const_iterator std::forward_list< _Tp, _Alloc >::before_begin | ( |  | ) | const
| inlinenoexcept

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

Definition at line 1182 of file forward_list.h.

## ◆ before_begin() [2/2]

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

iterator std::forward_list< _Tp, _Alloc >::before_begin | ( |  | ) |
| inlinenoexcept

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

Definition at line 1172 of file forward_list.h.

Referenced by std::forward_list< _Tp, polymorphic_allocator< _Tp > >::assign(), std::forward_list< _Tp, polymorphic_allocator< _Tp > >::assign(), insert_after(), insert_after(), resize(), and resize().

## ◆ begin() [1/2]

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

const_iterator std::forward_list< _Tp, _Alloc >::begin | ( |  | ) | const
| inlinenoexcept

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

Definition at line 1201 of file forward_list.h.

## ◆ begin() [2/2]

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

iterator std::forward_list< _Tp, _Alloc >::begin | ( |  | ) |
| inlinenoexcept

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

Definition at line 1191 of file forward_list.h.

Referenced by std::forward_list< _Tp, polymorphic_allocator< _Tp > >::assign(), std::forward_list< _Tp, polymorphic_allocator< _Tp > >::assign(), and unique().

## ◆ cbefore_begin()

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

const_iterator std::forward_list< _Tp, _Alloc >::cbefore_begin | ( |  | ) | const
| inlinenoexcept

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

Definition at line 1241 of file forward_list.h.

Referenced by std::forward_list< _Tp, polymorphic_allocator< _Tp > >::assign(), std::forward_list< _Tp, polymorphic_allocator< _Tp > >::assign(), std::forward_list< _Tp, polymorphic_allocator< _Tp > >::emplace_front(), std::forward_list< _Tp, polymorphic_allocator< _Tp > >::push_front(), remove(), remove_if(), and unique().

## ◆ cbegin()

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

const_iterator std::forward_list< _Tp, _Alloc >::cbegin | ( |  | ) | const
| inlinenoexcept

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

Definition at line 1231 of file forward_list.h.

Referenced by std::operator==().

## ◆ cend()

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

const_iterator std::forward_list< _Tp, _Alloc >::cend | ( |  | ) | const
| inlinenoexcept

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

Definition at line 1251 of file forward_list.h.

Referenced by std::operator==().

## ◆ clear()

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

void std::forward_list< _Tp, _Alloc >::clear | ( |  | ) |
| inlinenoexcept

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.

Definition at line 1626 of file forward_list.h.

Referenced by std::forward_list< _Tp, polymorphic_allocator< _Tp > >::assign(), std::forward_list< _Tp, polymorphic_allocator< _Tp > >::assign(), operator=(), and std::forward_list< _Tp, polymorphic_allocator< _Tp > >::operator=().

## ◆ emplace_after()

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.

Definition at line 1409 of file forward_list.h.

## ◆ emplace_front()

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.

Definition at line 1318 of file forward_list.h.

## ◆ empty()

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

bool std::forward_list< _Tp, _Alloc >::empty | ( |  | ) | const
| inlinenoexcept

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

Definition at line 1260 of file forward_list.h.

Referenced by insert_after(), and sort().

## ◆ end() [1/2]

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

const_iterator std::forward_list< _Tp, _Alloc >::end | ( |  | ) | const
| inlinenoexcept

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

Definition at line 1221 of file forward_list.h.

## ◆ end() [2/2]

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

iterator std::forward_list< _Tp, _Alloc >::end | ( |  | ) |
| inlinenoexcept

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

Definition at line 1211 of file forward_list.h.

Referenced by std::forward_list< _Tp, polymorphic_allocator< _Tp > >::assign(), std::forward_list< _Tp, polymorphic_allocator< _Tp > >::assign(), insert_after(), insert_after(), resize(), resize(), and unique().

## ◆ erase_after() [1/2]

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.

Definition at line 1538 of file forward_list.h.

Referenced by std::forward_list< _Tp, polymorphic_allocator< _Tp > >::assign(), std::forward_list< _Tp, polymorphic_allocator< _Tp > >::assign(), resize(), and resize().

## ◆ erase_after() [2/2]

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.

Definition at line 1561 of file forward_list.h.

## ◆ front() [1/2]

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.

Definition at line 1279 of file forward_list.h.

Referenced by std::forward_list< _Tp, polymorphic_allocator< _Tp > >::emplace_front().

## ◆ front() [2/2]

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.

Definition at line 1292 of file forward_list.h.

## ◆ get_allocator()

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

allocator_type std::forward_list< _Tp, _Alloc >::get_allocator | ( |  | ) | const
| inlinenoexcept

Get a copy of the memory allocation object.

Definition at line 1161 of file forward_list.h.

Referenced by insert_after(), insert_after(), remove(), remove_if(), and unique().

## ◆ insert_after() [1/5]

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.

Definition at line 265 of file forward_list.tcc.

References forward_list(), before_begin(), empty(), end(), and get_allocator().

## ◆ insert_after() [2/5]

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

iterator std::forward_list< _Tp, _Alloc >::insert_after | ( | const_iterator | __pos,
|  | _Tp && | __val )
| inline

Definition at line 1433 of file forward_list.h.

## ◆ insert_after() [3/5]

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.

Definition at line 1426 of file forward_list.h.

Referenced by std::forward_list< _Tp, polymorphic_allocator< _Tp > >::assign(), std::forward_list< _Tp, polymorphic_allocator< _Tp > >::assign(), std::forward_list< _Tp, polymorphic_allocator< _Tp > >::insert_after(), and resize().

## ◆ insert_after() [4/5]

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.

Definition at line 250 of file forward_list.tcc.

References forward_list(), before_begin(), end(), and get_allocator().

## ◆ insert_after() [5/5]

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.

Definition at line 1491 of file forward_list.h.

## ◆ max_size()

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

size_type std::forward_list< _Tp, _Alloc >::max_size | ( |  | ) | const
| inlinenoexcept

Returns the largest possible number of elements of forward_list.

Definition at line 1268 of file forward_list.h.

## ◆ merge() [1/4]

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.

Definition at line 1781 of file forward_list.h.

Referenced by std::forward_list< _Tp, polymorphic_allocator< _Tp > >::merge().

## ◆ merge() [2/4]

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

Definition at line 362 of file forward_list.tcc.

References forward_list(), std::__addressof(), and std::move().

## ◆ merge() [3/4]

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

void std::forward_list< _Tp, _Alloc >::merge | ( | forward_list< _Tp, _Alloc > & | __list | ) |
| inline

Definition at line 1785 of file forward_list.h.

## ◆ merge() [4/4]

template<typename _Tp, typename _Alloc = allocator<_Tp>>
template<typename _Comp>

void std::forward_list< _Tp, _Alloc >::merge | ( | forward_list< _Tp, _Alloc > & | __list,
|  | _Comp | __comp )
| inline

Definition at line 1805 of file forward_list.h.

## ◆ operator=() [1/3]

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.

Definition at line 134 of file forward_list.tcc.

References forward_list(), std::__addressof(), assign(), and clear().

## ◆ operator=() [2/3]

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

forward_list & std::forward_list< _Tp, _Alloc >::operator= | ( | forward_list< _Tp, _Alloc > && | __list | ) |
| inlinenoexcept

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.

Definition at line 990 of file forward_list.h.

## ◆ operator=() [3/3]

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

Definition at line 1026 of file forward_list.h.

## ◆ pop_front()

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.

Definition at line 1388 of file forward_list.h.

## ◆ push_front() [1/2]

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

void std::forward_list< _Tp, _Alloc >::push_front | ( | _Tp && | __val | ) |
| inline

Definition at line 1345 of file forward_list.h.

## ◆ push_front() [2/2]

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.

Definition at line 1338 of file forward_list.h.

## ◆ remove()

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.

Definition at line 284 of file forward_list.tcc.

References forward_list(), cbefore_begin(), get_allocator(), and splice_after().

## ◆ remove_if()

template<typename _Tp, typename _Alloc>
template<typename _Pred>

auto forward_list::remove_if | ( | _Pred | __pred | ) | -> __remove_return_type

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.

Definition at line 307 of file forward_list.tcc.

References forward_list(), cbefore_begin(), get_allocator(), and splice_after().

## ◆ resize() [1/2]

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.

Definition at line 176 of file forward_list.tcc.

References forward_list(), before_begin(), end(), and erase_after().

## ◆ resize() [2/2]

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.

Definition at line 195 of file forward_list.tcc.

References forward_list(), before_begin(), end(), erase_after(), and insert_after().

## ◆ reverse()

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

void std::forward_list< _Tp, _Alloc >::reverse | ( |  | ) |
| inlinenoexcept

Reverse the elements in list.

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

Definition at line 1834 of file forward_list.h.

## ◆ sort() [1/2]

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.

Definition at line 1815 of file forward_list.h.

Referenced by std::forward_list< _Tp, polymorphic_allocator< _Tp > >::sort().

## ◆ sort() [2/2]

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.

Definition at line 412 of file forward_list.tcc.

References forward_list(), and empty().

## ◆ splice_after() [1/6]

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 )
| inlinenoexcept

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).

Definition at line 1687 of file forward_list.h.

## ◆ splice_after() [2/6]

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

void std::forward_list< _Tp, _Alloc >::splice_after | ( | const_iterator | __pos,
|  | forward_list< _Tp, _Alloc > && | __list )
| inlinenoexcept

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.

Definition at line 1643 of file forward_list.h.

Referenced by remove(), remove_if(), std::forward_list< _Tp, polymorphic_allocator< _Tp > >::splice_after(), and unique().

## ◆ splice_after() [3/6]

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.

Definition at line 233 of file forward_list.tcc.

References forward_list().

## ◆ splice_after() [4/6]

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 )
| inlinenoexcept

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).

Definition at line 1692 of file forward_list.h.

## ◆ splice_after() [5/6]

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

void std::forward_list< _Tp, _Alloc >::splice_after | ( | const_iterator | __pos,
|  | forward_list< _Tp, _Alloc > & | __list )
| inlinenoexcept

Definition at line 1650 of file forward_list.h.

## ◆ splice_after() [6/6]

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

void std::forward_list< _Tp, _Alloc >::splice_after | ( | const_iterator | __pos,
|  | forward_list< _Tp, _Alloc > & | __list,
|  | const_iterator | __i )
| inlinenoexcept

Definition at line 1668 of file forward_list.h.

## ◆ swap()

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

void std::forward_list< _Tp, _Alloc >::swap | ( | forward_list< _Tp, _Alloc > & | __list | ) |
| inlinenoexcept

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 overloaded such that std::swap(l1, l2) will feed to this function.

Whether the allocators are swapped depends on the allocator traits.

Definition at line 1580 of file forward_list.h.

## ◆ unique() [1/2]

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.

Definition at line 1750 of file forward_list.h.

Referenced by std::forward_list< _Tp, polymorphic_allocator< _Tp > >::unique().

## ◆ unique() [2/2]

template<typename _Tp, typename _Alloc>
template<typename _BinPred>

auto forward_list::unique | ( | _BinPred | __binary_pred | ) | -> __remove_return_type

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.

Definition at line 330 of file forward_list.tcc.

References forward_list(), begin(), cbefore_begin(), end(), get_allocator(), and splice_after().

The documentation for this class was generated from the following files:

- forward_list.h
- forward_list.tcc