[forward.list.modifiers]

# 23 Containers library [[containers]](./#containers)

## 23.3 Sequence containers [[sequences]](sequences#forward.list.modifiers)

### 23.3.7 Class template forward_list [[forward.list]](forward.list#modifiers)

#### 23.3.7.5 Modifiers [forward.list.modifiers]

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7269)

The member functions in this subclause
do not affect the validity of iterators and references
when inserting elements, and when erasing elements
invalidate iterators and references to the erased elements only[.](#1.sentence-1)

If an exception is thrown by any of these member functions
there is no effect on the container[.](#1.sentence-2)

Inserting n elements into a forward_list is linear inn, and the number of calls to the copy or move constructor of T is
exactly equal to n[.](#1.sentence-3)

Erasing n elements from a forward_list is
linear in n and the number of calls to the destructor of type T is
exactly equal to n[.](#1.sentence-4)

[ð](#lib:emplace_front,forward_list)

`template<class... Args> constexpr reference emplace_front(Args&&... args);
`

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7288)

*Effects*: Inserts an object of type value_type constructed withvalue_type(std​::​forward<Args>(​args)...) at the beginning of the list[.](#2.sentence-1)

[ð](#lib:push_front,forward_list)

`constexpr void push_front(const T& x);
constexpr void push_front(T&& x);
`

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7301)

*Effects*: Inserts a copy of x at the beginning of the list[.](#3.sentence-1)

[ð](#lib:prepend_range,forward_list)

`template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1 Introduction [container.intro.reqmts]")<T> R>
  constexpr void prepend_range(R&& rg);
`

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7313)

*Effects*: Inserts a copy of each element of rg at the beginning of the list[.](#4.sentence-1)

[*Note [1](#note-1)*:

The order of elements is not reversed[.](#4.sentence-2)

â *end note*]

[ð](#lib:pop,forward_list)

`constexpr void pop_front();
`

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7327)

*Effects*: As if by erase_after(before_begin())[.](#5.sentence-1)

[ð](#lib:insert_after,forward_list)

`constexpr iterator insert_after(const_iterator position, const T& x);
`

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7338)

*Preconditions*: T is *Cpp17CopyInsertable* into forward_list[.](#6.sentence-1)

position is before_begin() or is a dereferenceable
iterator in the range [begin(), end())[.](#6.sentence-2)

[7](#7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7344)

*Effects*: Inserts a copy of x after position[.](#7.sentence-1)

[8](#8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7348)

*Returns*: An iterator pointing to the copy of x[.](#8.sentence-1)

[ð](#lib:insert_after,forward_list_)

`constexpr iterator insert_after(const_iterator position, T&& x);
`

[9](#9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7359)

*Preconditions*: T is *Cpp17MoveInsertable* into forward_list[.](#9.sentence-1)

position is before_begin() or is a dereferenceable
iterator in the range [begin(), end())[.](#9.sentence-2)

[10](#10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7365)

*Effects*: Inserts a copy of x after position[.](#10.sentence-1)

[11](#11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7369)

*Returns*: An iterator pointing to the copy of x[.](#11.sentence-1)

[ð](#lib:insert_after,forward_list__)

`constexpr iterator insert_after(const_iterator position, size_type n, const T& x);
`

[12](#12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7380)

*Preconditions*: T is *Cpp17CopyInsertable* into forward_list[.](#12.sentence-1)

position is before_begin() or is a dereferenceable
iterator in the range [begin(), end())[.](#12.sentence-2)

[13](#13)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7386)

*Effects*: Inserts n copies of x after position[.](#13.sentence-1)

[14](#14)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7390)

*Returns*: An iterator pointing to the last inserted copy of x, orposition if n == 0 is true[.](#14.sentence-1)

[ð](#lib:insert_after,forward_list___)

`template<class InputIterator>
  constexpr iterator insert_after(const_iterator position,
                                  InputIterator first, InputIterator last);
`

[15](#15)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7404)

*Preconditions*: T is *Cpp17EmplaceConstructible* into forward_list from *first[.](#15.sentence-1)

position is before_begin() or is a dereferenceable
iterator in the range [begin(), end())[.](#15.sentence-2)

Neither first nor last are iterators in *this[.](#15.sentence-3)

[16](#16)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7412)

*Effects*: Inserts copies of elements in [first, last) after position[.](#16.sentence-1)

[17](#17)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7416)

*Returns*: An iterator pointing to the last inserted element, orposition if first == last is true[.](#17.sentence-1)

[ð](#lib:insert_range_after,forward_list)

`template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1 Introduction [container.intro.reqmts]")<T> R>
  constexpr iterator insert_range_after(const_iterator position, R&& rg);
`

[18](#18)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7429)

*Preconditions*: T is *Cpp17EmplaceConstructible* into forward_list from *ranges​::​begin(rg)[.](#18.sentence-1)

position is before_begin() or
is a dereferenceable iterator in the range [begin(), end())[.](#18.sentence-2)

rg and *this do not overlap[.](#18.sentence-3)

[19](#19)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7437)

*Effects*: Inserts copies of elements in the range rg after position[.](#19.sentence-1)

[20](#20)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7441)

*Returns*: An iterator pointing to the last inserted element,
or position if rg is empty[.](#20.sentence-1)

[ð](#lib:insert_after,forward_list____)

`constexpr iterator insert_after(const_iterator position, initializer_list<T> il);
`

[21](#21)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7453)

*Effects*: Equivalent to: return insert_after(position, il.begin(), il.end());

[ð](#lib:emplace_after,forward_list)

`template<class... Args>
  constexpr iterator emplace_after(const_iterator position, Args&&... args);
`

[22](#22)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7466)

*Preconditions*: T is *Cpp17EmplaceConstructible* into forward_list from std​::​forward<Args>(args)...[.](#22.sentence-1)

position is before_begin() or is a dereferenceable
iterator in the range [begin(), end())[.](#22.sentence-2)

[23](#23)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7473)

*Effects*: Inserts an object of type value_type direct-non-list-initialized withstd​::​forward<Args>(args)... after position[.](#23.sentence-1)

[24](#24)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7478)

*Returns*: An iterator pointing to the new object[.](#24.sentence-1)

[ð](#lib:erase_after,forward_list)

`constexpr iterator erase_after(const_iterator position);
`

[25](#25)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7489)

*Preconditions*: The iterator following position is dereferenceable[.](#25.sentence-1)

[26](#26)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7493)

*Effects*: Erases the element pointed to by the iterator following position[.](#26.sentence-1)

[27](#27)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7497)

*Returns*: An iterator pointing to the element following the one that was
erased, or end() if no such element exists[.](#27.sentence-1)

[28](#28)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7502)

*Throws*: Nothing[.](#28.sentence-1)

[ð](#itemdecl:13)

`constexpr iterator erase_after(const_iterator position, const_iterator last);
`

[29](#29)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7512)

*Preconditions*: All iterators in the range (position, last) are dereferenceable[.](#29.sentence-1)

[30](#30)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7516)

*Effects*: Erases the elements in the range (position, last)[.](#30.sentence-1)

[31](#31)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7520)

*Returns*: last[.](#31.sentence-1)

[32](#32)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7524)

*Throws*: Nothing[.](#32.sentence-1)

[ð](#lib:resize,forward_list)

`constexpr void resize(size_type sz);
`

[33](#33)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7535)

*Preconditions*: T is *Cpp17DefaultInsertable* into forward_list[.](#33.sentence-1)

[34](#34)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7539)

*Effects*: If sz < distance(begin(), end()), erases the last distance(begin(),
end()) - sz elements from the list[.](#34.sentence-1)

Otherwise, inserts sz - distance(begin(), end()) default-inserted
elements at the end of the list[.](#34.sentence-2)

[ð](#itemdecl:15)

`constexpr void resize(size_type sz, const value_type& c);
`

[35](#35)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7551)

*Preconditions*: T is *Cpp17CopyInsertable* into forward_list[.](#35.sentence-1)

[36](#36)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7555)

*Effects*: If sz < distance(begin(), end()), erases the last distance(begin(),
end()) - sz elements from the list[.](#36.sentence-1)

Otherwise, inserts sz - distance(begin(), end()) copies of c at the end of the list[.](#36.sentence-2)

[ð](#lib:clear,forward_list)

`constexpr void clear() noexcept;
`

[37](#37)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7569)

*Effects*: Erases all elements in the range [begin(), end())[.](#37.sentence-1)

[38](#38)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7573)

*Remarks*: Does not invalidate past-the-end iterators[.](#38.sentence-1)
