968 lines
40 KiB
Markdown
968 lines
40 KiB
Markdown
[forward.list]
|
||
|
||
# 23 Containers library [[containers]](./#containers)
|
||
|
||
## 23.3 Sequence containers [[sequences]](sequences#forward.list)
|
||
|
||
### 23.3.7 Class template forward_list [forward.list]
|
||
|
||
#### [23.3.7.1](#overview) Overview [[forward.list.overview]](forward.list.overview)
|
||
|
||
[1](#overview-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6962)
|
||
|
||
A forward_list is a container that supports forward iterators and allows
|
||
constant time insert and erase operations anywhere within the sequence, with storage
|
||
management handled automatically[.](#overview-1.sentence-1)
|
||
|
||
Fast random access to list elements is not supported[.](#overview-1.sentence-2)
|
||
|
||
[*Note [1](#overview-note-1)*:
|
||
|
||
It is intended that forward_list have zero space or time overhead
|
||
relative to a hand-written C-style singly linked list[.](#overview-1.sentence-3)
|
||
|
||
Features that would conflict with
|
||
that goal have been omitted[.](#overview-1.sentence-4)
|
||
|
||
â *end note*]
|
||
|
||
[2](#overview-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6972)
|
||
|
||
A forward_list meets all of the requirements
|
||
of a container ([[container.reqmts]](container.reqmts "23.2.2.2 Container requirements")),
|
||
except that the size() member function is not provided andoperator== has linear complexity[.](#overview-2.sentence-1)
|
||
|
||
A forward_list also meets all of the requirements
|
||
for an allocator-aware container ([[container.alloc.reqmts]](container.alloc.reqmts "23.2.2.5 Allocator-aware containers"))[.](#overview-2.sentence-2)
|
||
|
||
In addition, a forward_list provides the assign member functions and
|
||
several of the optional sequence container requirements ([[sequence.reqmts]](sequence.reqmts "23.2.4 Sequence containers"))[.](#overview-2.sentence-3)
|
||
|
||
Descriptions are provided here only for operations onforward_list that are not described in that table or for operations where there
|
||
is additional semantic information[.](#overview-2.sentence-4)
|
||
|
||
[3](#overview-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6986)
|
||
|
||
[*Note [2](#overview-note-2)*:
|
||
|
||
Modifying any list requires access to the element preceding the first element
|
||
of interest, but in a forward_list there is no constant-time way to access a
|
||
preceding element[.](#overview-3.sentence-1)
|
||
|
||
For this reason, erase_after and splice_after take fully-open ranges, not semi-open ranges[.](#overview-3.sentence-2)
|
||
|
||
â *end note*]
|
||
|
||
[4](#overview-4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6995)
|
||
|
||
The types iterator and const_iterator meet
|
||
the constexpr iterator requirements ([[iterator.requirements.general]](iterator.requirements.general "24.3.1 General"))[.](#overview-4.sentence-1)
|
||
|
||
namespace std {template<class T, class Allocator = allocator<T>>class forward_list {public:// typesusing value_type = T; using allocator_type = Allocator; using pointer = typename allocator_traits<Allocator>::pointer; using const_pointer = typename allocator_traits<Allocator>::const_pointer; using reference = value_type&; using const_reference = const value_type&; using size_type = *implementation-defined*; // see [[container.requirements]](container.requirements "23.2 Requirements")using difference_type = *implementation-defined*; // see [[container.requirements]](container.requirements "23.2 Requirements")using iterator = *implementation-defined*; // see [[container.requirements]](container.requirements "23.2 Requirements")using const_iterator = *implementation-defined*; // see [[container.requirements]](container.requirements "23.2 Requirements")// [[forward.list.cons]](#cons "23.3.7.2 Constructors, copy, and assignment"), construct/copy/destroyconstexpr forward_list() : forward_list(Allocator()) { }constexpr explicit forward_list(const Allocator&); constexpr explicit forward_list(size_type n, const Allocator& = Allocator()); constexpr forward_list(size_type n, const T& value, const Allocator& = Allocator()); template<class InputIterator>constexpr forward_list(InputIterator first, InputIterator last, const Allocator& = Allocator()); template<[*container-compatible-range*](container.intro.reqmts#concept:container-compatible-range "23.2.2.1 Introduction [container.intro.reqmts]")<T> R>constexpr forward_list(from_range_t, R&& rg, const Allocator& = Allocator()); constexpr forward_list(const forward_list& x); constexpr forward_list(forward_list&& x); constexpr forward_list(const forward_list& x, const type_identity_t<Allocator>&); constexpr forward_list(forward_list&& x, const type_identity_t<Allocator>&); constexpr forward_list(initializer_list<T>, const Allocator& = Allocator()); constexpr ~forward_list(); constexpr forward_list& operator=(const forward_list& x); constexpr forward_list& operator=(forward_list&& x)noexcept(allocator_traits<Allocator>::is_always_equal::value); constexpr forward_list& operator=(initializer_list<T>); template<class InputIterator>constexpr void assign(InputIterator first, InputIterator last); template<[*container-compatible-range*](container.intro.reqmts#concept:container-compatible-range "23.2.2.1 Introduction [container.intro.reqmts]")<T> R>constexpr void assign_range(R&& rg); constexpr void assign(size_type n, const T& t); constexpr void assign(initializer_list<T>); constexpr allocator_type get_allocator() const noexcept; // [[forward.list.iter]](#iter "23.3.7.3 Iterators"), iteratorsconstexpr iterator before_begin() noexcept; constexpr const_iterator before_begin() const noexcept; constexpr iterator begin() noexcept; constexpr const_iterator begin() const noexcept; constexpr iterator end() noexcept; constexpr const_iterator end() const noexcept; constexpr const_iterator cbegin() const noexcept; constexpr const_iterator cbefore_begin() const noexcept; constexpr const_iterator cend() const noexcept; // capacityconstexpr bool empty() const noexcept; constexpr size_type max_size() const noexcept; // [[forward.list.access]](#access "23.3.7.4 Element access"), element accessconstexpr reference front(); constexpr const_reference front() const; // [[forward.list.modifiers]](#modifiers "23.3.7.5 Modifiers"), modifierstemplate<class... Args> constexpr reference emplace_front(Args&&... args); constexpr void push_front(const T& x); constexpr void push_front(T&& x); 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); constexpr void pop_front(); template<class... Args>constexpr iterator emplace_after(const_iterator position, Args&&... args); constexpr iterator insert_after(const_iterator position, const T& x); constexpr iterator insert_after(const_iterator position, T&& x); constexpr iterator insert_after(const_iterator position, size_type n, const T& x); template<class InputIterator>constexpr iterator insert_after(const_iterator position,
|
||
InputIterator first, InputIterator last); constexpr iterator insert_after(const_iterator position, initializer_list<T> il); 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); constexpr iterator erase_after(const_iterator position); constexpr iterator erase_after(const_iterator position, const_iterator last); constexpr void swap(forward_list&)noexcept(allocator_traits<Allocator>::is_always_equal::value); constexpr void resize(size_type sz); constexpr void resize(size_type sz, const value_type& c); constexpr void clear() noexcept; // [[forward.list.ops]](#ops "23.3.7.6 Operations"), forward_list operationsconstexpr void splice_after(const_iterator position, forward_list& x); constexpr void splice_after(const_iterator position, forward_list&& x); constexpr void splice_after(const_iterator position, forward_list& x, const_iterator i); constexpr void splice_after(const_iterator position, forward_list&& x, const_iterator i); constexpr void splice_after(const_iterator position, forward_list& x,
|
||
const_iterator first, const_iterator last); constexpr void splice_after(const_iterator position, forward_list&& x,
|
||
const_iterator first, const_iterator last); constexpr size_type remove(const T& value); template<class Predicate> constexpr size_type remove_if(Predicate pred);
|
||
|
||
size_type unique(); template<class BinaryPredicate> constexpr size_type unique(BinaryPredicate binary_pred); constexpr void merge(forward_list& x); constexpr void merge(forward_list&& x); template<class Compare> constexpr void merge(forward_list& x, Compare comp); template<class Compare> constexpr void merge(forward_list&& x, Compare comp); constexpr void sort(); template<class Compare> constexpr void sort(Compare comp); constexpr void reverse() noexcept; }; template<class InputIterator, class Allocator = allocator<*iter-value-type*<InputIterator>>> forward_list(InputIterator, InputIterator, Allocator = Allocator())-> forward_list<*iter-value-type*<InputIterator>, Allocator>; template<ranges::[input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") R, class Allocator = allocator<ranges::range_value_t<R>>> forward_list(from_range_t, R&&, Allocator = Allocator())-> forward_list<ranges::range_value_t<R>, Allocator>;}
|
||
|
||
[5](#overview-5)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7131)
|
||
|
||
An incomplete type T may be used when instantiating forward_list if the allocator meets the[allocator completeness requirements](allocator.requirements.completeness "16.4.4.6.2 Allocator completeness requirements [allocator.requirements.completeness]")[.](#overview-5.sentence-1)
|
||
|
||
T shall be complete before any member of the resulting specialization
|
||
of forward_list is referenced[.](#overview-5.sentence-2)
|
||
|
||
#### [23.3.7.2](#cons) Constructors, copy, and assignment [[forward.list.cons]](forward.list.cons)
|
||
|
||
[ð](#lib:forward_list,constructor)
|
||
|
||
`constexpr explicit forward_list(const Allocator&);
|
||
`
|
||
|
||
[1](#cons-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7146)
|
||
|
||
*Effects*: Constructs an empty forward_list object using the specified allocator[.](#cons-1.sentence-1)
|
||
|
||
[2](#cons-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7150)
|
||
|
||
*Complexity*: Constant[.](#cons-2.sentence-1)
|
||
|
||
[ð](#lib:forward_list,constructor_)
|
||
|
||
`constexpr explicit forward_list(size_type n, const Allocator& = Allocator());
|
||
`
|
||
|
||
[3](#cons-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7161)
|
||
|
||
*Preconditions*: T is *Cpp17DefaultInsertable* into forward_list[.](#cons-3.sentence-1)
|
||
|
||
[4](#cons-4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7165)
|
||
|
||
*Effects*: Constructs a forward_list object with n default-inserted elements using the specified allocator[.](#cons-4.sentence-1)
|
||
|
||
[5](#cons-5)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7170)
|
||
|
||
*Complexity*: Linear in n[.](#cons-5.sentence-1)
|
||
|
||
[ð](#lib:forward_list,constructor__)
|
||
|
||
`constexpr forward_list(size_type n, const T& value, const Allocator& = Allocator());
|
||
`
|
||
|
||
[6](#cons-6)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7181)
|
||
|
||
*Preconditions*: T is *Cpp17CopyInsertable* into forward_list[.](#cons-6.sentence-1)
|
||
|
||
[7](#cons-7)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7185)
|
||
|
||
*Effects*: Constructs a forward_list object with n copies of value using the specified allocator[.](#cons-7.sentence-1)
|
||
|
||
[8](#cons-8)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7189)
|
||
|
||
*Complexity*: Linear in n[.](#cons-8.sentence-1)
|
||
|
||
[ð](#lib:forward_list,constructor___)
|
||
|
||
`template<class InputIterator>
|
||
constexpr forward_list(InputIterator first, InputIterator last, const Allocator& = Allocator());
|
||
`
|
||
|
||
[9](#cons-9)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7201)
|
||
|
||
*Effects*: Constructs a forward_list object equal to the range [first, last)[.](#cons-9.sentence-1)
|
||
|
||
[10](#cons-10)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7205)
|
||
|
||
*Complexity*: Linear in distance(first, last)[.](#cons-10.sentence-1)
|
||
|
||
[ð](#lib:forward_list,constructor____)
|
||
|
||
`template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1 Introduction [container.intro.reqmts]")<T> R>
|
||
constexpr forward_list(from_range_t, R&& rg, const Allocator& = Allocator());
|
||
`
|
||
|
||
[11](#cons-11)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7217)
|
||
|
||
*Effects*: Constructs a forward_list object
|
||
with the elements of the range rg[.](#cons-11.sentence-1)
|
||
|
||
[12](#cons-12)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7222)
|
||
|
||
*Complexity*: Linear in ranges::distance(rg)[.](#cons-12.sentence-1)
|
||
|
||
#### [23.3.7.3](#iter) Iterators [[forward.list.iter]](forward.list.iter)
|
||
|
||
[ð](#lib:before_begin,forward_list)
|
||
|
||
`constexpr iterator before_begin() noexcept;
|
||
constexpr const_iterator before_begin() const noexcept;
|
||
constexpr const_iterator cbefore_begin() const noexcept;
|
||
`
|
||
|
||
[1](#iter-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7238)
|
||
|
||
*Effects*: cbefore_begin() is equivalent toconst_cast<forward_list const&>(*this).before_begin()[.](#iter-1.sentence-1)
|
||
|
||
[2](#iter-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7243)
|
||
|
||
*Returns*: A non-dereferenceable iterator that, when incremented, is equal to the iterator
|
||
returned by begin()[.](#iter-2.sentence-1)
|
||
|
||
[3](#iter-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7248)
|
||
|
||
*Remarks*: before_begin() == end() shall equal false[.](#iter-3.sentence-1)
|
||
|
||
#### [23.3.7.4](#access) Element access [[forward.list.access]](forward.list.access)
|
||
|
||
[ð](#lib:front,forward_list)
|
||
|
||
`constexpr reference front();
|
||
constexpr const_reference front() const;
|
||
`
|
||
|
||
[1](#access-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7262)
|
||
|
||
*Returns*: *begin()
|
||
|
||
#### [23.3.7.5](#modifiers) Modifiers [[forward.list.modifiers]](forward.list.modifiers)
|
||
|
||
[1](#modifiers-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[.](#modifiers-1.sentence-1)
|
||
|
||
If an exception is thrown by any of these member functions
|
||
there is no effect on the container[.](#modifiers-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[.](#modifiers-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[.](#modifiers-1.sentence-4)
|
||
|
||
[ð](#lib:emplace_front,forward_list)
|
||
|
||
`template<class... Args> constexpr reference emplace_front(Args&&... args);
|
||
`
|
||
|
||
[2](#modifiers-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[.](#modifiers-2.sentence-1)
|
||
|
||
[ð](#lib:push_front,forward_list)
|
||
|
||
`constexpr void push_front(const T& x);
|
||
constexpr void push_front(T&& x);
|
||
`
|
||
|
||
[3](#modifiers-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7301)
|
||
|
||
*Effects*: Inserts a copy of x at the beginning of the list[.](#modifiers-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](#modifiers-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[.](#modifiers-4.sentence-1)
|
||
|
||
[*Note [1](#modifiers-note-1)*:
|
||
|
||
The order of elements is not reversed[.](#modifiers-4.sentence-2)
|
||
|
||
â *end note*]
|
||
|
||
[ð](#lib:pop,forward_list)
|
||
|
||
`constexpr void pop_front();
|
||
`
|
||
|
||
[5](#modifiers-5)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7327)
|
||
|
||
*Effects*: As if by erase_after(before_begin())[.](#modifiers-5.sentence-1)
|
||
|
||
[ð](#lib:insert_after,forward_list)
|
||
|
||
`constexpr iterator insert_after(const_iterator position, const T& x);
|
||
`
|
||
|
||
[6](#modifiers-6)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7338)
|
||
|
||
*Preconditions*: T is *Cpp17CopyInsertable* into forward_list[.](#modifiers-6.sentence-1)
|
||
|
||
position is before_begin() or is a dereferenceable
|
||
iterator in the range [begin(), end())[.](#modifiers-6.sentence-2)
|
||
|
||
[7](#modifiers-7)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7344)
|
||
|
||
*Effects*: Inserts a copy of x after position[.](#modifiers-7.sentence-1)
|
||
|
||
[8](#modifiers-8)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7348)
|
||
|
||
*Returns*: An iterator pointing to the copy of x[.](#modifiers-8.sentence-1)
|
||
|
||
[ð](#lib:insert_after,forward_list_)
|
||
|
||
`constexpr iterator insert_after(const_iterator position, T&& x);
|
||
`
|
||
|
||
[9](#modifiers-9)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7359)
|
||
|
||
*Preconditions*: T is *Cpp17MoveInsertable* into forward_list[.](#modifiers-9.sentence-1)
|
||
|
||
position is before_begin() or is a dereferenceable
|
||
iterator in the range [begin(), end())[.](#modifiers-9.sentence-2)
|
||
|
||
[10](#modifiers-10)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7365)
|
||
|
||
*Effects*: Inserts a copy of x after position[.](#modifiers-10.sentence-1)
|
||
|
||
[11](#modifiers-11)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7369)
|
||
|
||
*Returns*: An iterator pointing to the copy of x[.](#modifiers-11.sentence-1)
|
||
|
||
[ð](#lib:insert_after,forward_list__)
|
||
|
||
`constexpr iterator insert_after(const_iterator position, size_type n, const T& x);
|
||
`
|
||
|
||
[12](#modifiers-12)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7380)
|
||
|
||
*Preconditions*: T is *Cpp17CopyInsertable* into forward_list[.](#modifiers-12.sentence-1)
|
||
|
||
position is before_begin() or is a dereferenceable
|
||
iterator in the range [begin(), end())[.](#modifiers-12.sentence-2)
|
||
|
||
[13](#modifiers-13)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7386)
|
||
|
||
*Effects*: Inserts n copies of x after position[.](#modifiers-13.sentence-1)
|
||
|
||
[14](#modifiers-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[.](#modifiers-14.sentence-1)
|
||
|
||
[ð](#lib:insert_after,forward_list___)
|
||
|
||
`template<class InputIterator>
|
||
constexpr iterator insert_after(const_iterator position,
|
||
InputIterator first, InputIterator last);
|
||
`
|
||
|
||
[15](#modifiers-15)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7404)
|
||
|
||
*Preconditions*: T is *Cpp17EmplaceConstructible* into forward_list from *first[.](#modifiers-15.sentence-1)
|
||
|
||
position is before_begin() or is a dereferenceable
|
||
iterator in the range [begin(), end())[.](#modifiers-15.sentence-2)
|
||
|
||
Neither first nor last are iterators in *this[.](#modifiers-15.sentence-3)
|
||
|
||
[16](#modifiers-16)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7412)
|
||
|
||
*Effects*: Inserts copies of elements in [first, last) after position[.](#modifiers-16.sentence-1)
|
||
|
||
[17](#modifiers-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[.](#modifiers-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](#modifiers-18)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7429)
|
||
|
||
*Preconditions*: T is *Cpp17EmplaceConstructible* into forward_list from *ranges::begin(rg)[.](#modifiers-18.sentence-1)
|
||
|
||
position is before_begin() or
|
||
is a dereferenceable iterator in the range [begin(), end())[.](#modifiers-18.sentence-2)
|
||
|
||
rg and *this do not overlap[.](#modifiers-18.sentence-3)
|
||
|
||
[19](#modifiers-19)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7437)
|
||
|
||
*Effects*: Inserts copies of elements in the range rg after position[.](#modifiers-19.sentence-1)
|
||
|
||
[20](#modifiers-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[.](#modifiers-20.sentence-1)
|
||
|
||
[ð](#lib:insert_after,forward_list____)
|
||
|
||
`constexpr iterator insert_after(const_iterator position, initializer_list<T> il);
|
||
`
|
||
|
||
[21](#modifiers-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](#modifiers-22)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7466)
|
||
|
||
*Preconditions*: T is *Cpp17EmplaceConstructible* into forward_list from std::forward<Args>(args)...[.](#modifiers-22.sentence-1)
|
||
|
||
position is before_begin() or is a dereferenceable
|
||
iterator in the range [begin(), end())[.](#modifiers-22.sentence-2)
|
||
|
||
[23](#modifiers-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[.](#modifiers-23.sentence-1)
|
||
|
||
[24](#modifiers-24)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7478)
|
||
|
||
*Returns*: An iterator pointing to the new object[.](#modifiers-24.sentence-1)
|
||
|
||
[ð](#lib:erase_after,forward_list)
|
||
|
||
`constexpr iterator erase_after(const_iterator position);
|
||
`
|
||
|
||
[25](#modifiers-25)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7489)
|
||
|
||
*Preconditions*: The iterator following position is dereferenceable[.](#modifiers-25.sentence-1)
|
||
|
||
[26](#modifiers-26)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7493)
|
||
|
||
*Effects*: Erases the element pointed to by the iterator following position[.](#modifiers-26.sentence-1)
|
||
|
||
[27](#modifiers-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[.](#modifiers-27.sentence-1)
|
||
|
||
[28](#modifiers-28)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7502)
|
||
|
||
*Throws*: Nothing[.](#modifiers-28.sentence-1)
|
||
|
||
[ð](#modifiers-itemdecl:13)
|
||
|
||
`constexpr iterator erase_after(const_iterator position, const_iterator last);
|
||
`
|
||
|
||
[29](#modifiers-29)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7512)
|
||
|
||
*Preconditions*: All iterators in the range (position, last) are dereferenceable[.](#modifiers-29.sentence-1)
|
||
|
||
[30](#modifiers-30)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7516)
|
||
|
||
*Effects*: Erases the elements in the range (position, last)[.](#modifiers-30.sentence-1)
|
||
|
||
[31](#modifiers-31)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7520)
|
||
|
||
*Returns*: last[.](#modifiers-31.sentence-1)
|
||
|
||
[32](#modifiers-32)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7524)
|
||
|
||
*Throws*: Nothing[.](#modifiers-32.sentence-1)
|
||
|
||
[ð](#lib:resize,forward_list)
|
||
|
||
`constexpr void resize(size_type sz);
|
||
`
|
||
|
||
[33](#modifiers-33)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7535)
|
||
|
||
*Preconditions*: T is *Cpp17DefaultInsertable* into forward_list[.](#modifiers-33.sentence-1)
|
||
|
||
[34](#modifiers-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[.](#modifiers-34.sentence-1)
|
||
|
||
Otherwise, inserts sz - distance(begin(), end()) default-inserted
|
||
elements at the end of the list[.](#modifiers-34.sentence-2)
|
||
|
||
[ð](#modifiers-itemdecl:15)
|
||
|
||
`constexpr void resize(size_type sz, const value_type& c);
|
||
`
|
||
|
||
[35](#modifiers-35)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7551)
|
||
|
||
*Preconditions*: T is *Cpp17CopyInsertable* into forward_list[.](#modifiers-35.sentence-1)
|
||
|
||
[36](#modifiers-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[.](#modifiers-36.sentence-1)
|
||
|
||
Otherwise, inserts sz - distance(begin(), end()) copies of c at the end of the list[.](#modifiers-36.sentence-2)
|
||
|
||
[ð](#lib:clear,forward_list)
|
||
|
||
`constexpr void clear() noexcept;
|
||
`
|
||
|
||
[37](#modifiers-37)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7569)
|
||
|
||
*Effects*: Erases all elements in the range [begin(), end())[.](#modifiers-37.sentence-1)
|
||
|
||
[38](#modifiers-38)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7573)
|
||
|
||
*Remarks*: Does not invalidate past-the-end iterators[.](#modifiers-38.sentence-1)
|
||
|
||
#### [23.3.7.6](#ops) Operations [[forward.list.ops]](forward.list.ops)
|
||
|
||
[1](#ops-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7580)
|
||
|
||
In this subclause,
|
||
arguments for a template parameter
|
||
named Predicate or BinaryPredicate shall meet the corresponding requirements in [[algorithms.requirements]](algorithms.requirements "26.2 Algorithms requirements")[.](#ops-1.sentence-1)
|
||
|
||
The semantics of i + n,
|
||
where i is an iterator into the list and n is an integer,
|
||
are the same as those of next(i, n)[.](#ops-1.sentence-2)
|
||
|
||
The expression i - n,
|
||
where i is an iterator into the list and n is an integer,
|
||
means an iterator j such that j + n == i is true[.](#ops-1.sentence-3)
|
||
|
||
For merge and sort,
|
||
the definitions and requirements in [[alg.sorting]](alg.sorting "26.8 Sorting and related operations") apply[.](#ops-1.sentence-4)
|
||
|
||
[ð](#lib:splice_after,forward_list)
|
||
|
||
`constexpr void splice_after(const_iterator position, forward_list& x);
|
||
constexpr void splice_after(const_iterator position, forward_list&& x);
|
||
`
|
||
|
||
[2](#ops-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7601)
|
||
|
||
*Preconditions*: position is before_begin() or is a dereferenceable
|
||
iterator in the range [begin(), end())[.](#ops-2.sentence-1)
|
||
|
||
get_allocator() == x.get_allocator() is true[.](#ops-2.sentence-2)
|
||
|
||
addressof(x) != this is true[.](#ops-2.sentence-3)
|
||
|
||
[3](#ops-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7608)
|
||
|
||
*Effects*: Inserts the contents of x afterposition, and x becomes empty[.](#ops-3.sentence-1)
|
||
|
||
Pointers and references to the moved
|
||
elements of x now refer to those same elements but as members of *this[.](#ops-3.sentence-2)
|
||
|
||
Iterators referring to the moved elements will continue to refer to their elements, but
|
||
they now behave as iterators into *this, not into x[.](#ops-3.sentence-3)
|
||
|
||
[4](#ops-4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7616)
|
||
|
||
*Throws*: Nothing[.](#ops-4.sentence-1)
|
||
|
||
[5](#ops-5)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7620)
|
||
|
||
*Complexity*: O(distance(x.begin(), x.end()))
|
||
|
||
[ð](#lib:splice_after,forward_list_)
|
||
|
||
`constexpr void splice_after(const_iterator position, forward_list& x, const_iterator i);
|
||
constexpr void splice_after(const_iterator position, forward_list&& x, const_iterator i);
|
||
`
|
||
|
||
[6](#ops-6)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7632)
|
||
|
||
*Preconditions*: position is before_begin() or is a dereferenceable
|
||
iterator in the range [begin(), end())[.](#ops-6.sentence-1)
|
||
|
||
The iterator following i is a dereferenceable iterator in x[.](#ops-6.sentence-2)
|
||
|
||
get_allocator() == x.get_allocator() is true[.](#ops-6.sentence-3)
|
||
|
||
[7](#ops-7)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7639)
|
||
|
||
*Effects*: Inserts the element following i into *this, followingposition, and removes it from x[.](#ops-7.sentence-1)
|
||
|
||
The result is unchanged if position == i or position == ++i[.](#ops-7.sentence-2)
|
||
|
||
Pointers
|
||
and references to *++i continue to refer to the same element but as a member of*this[.](#ops-7.sentence-3)
|
||
|
||
Iterators to *++i continue to refer to
|
||
the same element, but now behave as iterators into *this, not into x[.](#ops-7.sentence-4)
|
||
|
||
[8](#ops-8)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7648)
|
||
|
||
*Throws*: Nothing[.](#ops-8.sentence-1)
|
||
|
||
[9](#ops-9)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7652)
|
||
|
||
*Complexity*: O(1)
|
||
|
||
[ð](#lib:splice_after,forward_list__)
|
||
|
||
`constexpr void splice_after(const_iterator position, forward_list& x,
|
||
const_iterator first, const_iterator last);
|
||
constexpr void splice_after(const_iterator position, forward_list&& x,
|
||
const_iterator first, const_iterator last);
|
||
`
|
||
|
||
[10](#ops-10)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7666)
|
||
|
||
*Preconditions*: position is before_begin() or is a
|
||
dereferenceable iterator in the range [begin(), end())[.](#ops-10.sentence-1)
|
||
|
||
(first, last) is a
|
||
valid range in x, and all iterators in the range (first, last) are
|
||
dereferenceable[.](#ops-10.sentence-2)
|
||
|
||
position is not an iterator in the range (first, last)[.](#ops-10.sentence-3)
|
||
|
||
get_allocator() == x.get_allocator() is true[.](#ops-10.sentence-4)
|
||
|
||
[11](#ops-11)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7674)
|
||
|
||
*Effects*: Inserts elements in the range (first, last) after position and
|
||
removes the elements from x[.](#ops-11.sentence-1)
|
||
|
||
Pointers and references to the moved elements ofx now refer to those same elements but as members of *this[.](#ops-11.sentence-2)
|
||
|
||
Iterators
|
||
referring to the moved elements will continue to refer to their elements, but they now
|
||
behave as iterators into *this, not into x[.](#ops-11.sentence-3)
|
||
|
||
[12](#ops-12)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7682)
|
||
|
||
*Complexity*: O(distance(first, last))
|
||
|
||
[ð](#lib:remove,forward_list)
|
||
|
||
`constexpr size_type remove(const T& value);
|
||
template<class Predicate> constexpr size_type remove_if(Predicate pred);
|
||
`
|
||
|
||
[13](#ops-13)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7695)
|
||
|
||
*Effects*: Erases all the elements in the list referred to by a list iterator i for
|
||
which the following conditions hold: *i == value (for remove()),pred(*i) is true (for remove_if())[.](#ops-13.sentence-1)
|
||
|
||
Invalidates only the iterators and references to the erased elements[.](#ops-13.sentence-2)
|
||
|
||
[14](#ops-14)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7702)
|
||
|
||
*Returns*: The number of elements erased[.](#ops-14.sentence-1)
|
||
|
||
[15](#ops-15)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7706)
|
||
|
||
*Throws*: Nothing unless an exception is thrown by the equality comparison or the
|
||
predicate[.](#ops-15.sentence-1)
|
||
|
||
[16](#ops-16)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7711)
|
||
|
||
*Complexity*: Exactly distance(begin(), end()) applications of the corresponding
|
||
predicate[.](#ops-16.sentence-1)
|
||
|
||
[17](#ops-17)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7716)
|
||
|
||
*Remarks*: [Stable](algorithm.stable "16.4.6.8 Requirements for stable algorithms [algorithm.stable]")[.](#ops-17.sentence-1)
|
||
|
||
[ð](#lib:unique,forward_list)
|
||
|
||
`constexpr size_type unique();
|
||
template<class BinaryPredicate> constexpr size_type unique(BinaryPredicate binary_pred);
|
||
`
|
||
|
||
[18](#ops-18)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7728)
|
||
|
||
Let binary_pred be equal_to<>{} for the first overload[.](#ops-18.sentence-1)
|
||
|
||
[19](#ops-19)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7731)
|
||
|
||
*Preconditions*: binary_pred is an equivalence relation[.](#ops-19.sentence-1)
|
||
|
||
[20](#ops-20)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7735)
|
||
|
||
*Effects*: Erases all but the first element from every consecutive
|
||
group of equivalent elements[.](#ops-20.sentence-1)
|
||
|
||
That is, for a nonempty list, erases all elements referred to
|
||
by the iterator i in the range [begin() + 1, end())
|
||
for which binary_pred(*i, *(i - 1)) is true[.](#ops-20.sentence-2)
|
||
|
||
Invalidates only the iterators and references to the erased elements[.](#ops-20.sentence-3)
|
||
|
||
[21](#ops-21)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7744)
|
||
|
||
*Returns*: The number of elements erased[.](#ops-21.sentence-1)
|
||
|
||
[22](#ops-22)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7748)
|
||
|
||
*Throws*: Nothing unless an exception is thrown by the predicate[.](#ops-22.sentence-1)
|
||
|
||
[23](#ops-23)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7752)
|
||
|
||
*Complexity*: If empty() is false,
|
||
exactly distance(begin(), end()) - 1 applications of
|
||
the corresponding predicate,
|
||
otherwise no applications of the predicate[.](#ops-23.sentence-1)
|
||
|
||
[ð](#lib:merge,forward_list)
|
||
|
||
`constexpr void merge(forward_list& x);
|
||
constexpr void merge(forward_list&& x);
|
||
template<class Compare> constexpr void merge(forward_list& x, Compare comp);
|
||
template<class Compare> constexpr void merge(forward_list&& x, Compare comp);
|
||
`
|
||
|
||
[24](#ops-24)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7769)
|
||
|
||
Let comp be less<> for the first two overloads[.](#ops-24.sentence-1)
|
||
|
||
[25](#ops-25)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7772)
|
||
|
||
*Preconditions*: *this and x are both sorted
|
||
with respect to the comparator comp, andget_allocator() == x.get_allocator() is true[.](#ops-25.sentence-1)
|
||
|
||
[26](#ops-26)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7778)
|
||
|
||
*Effects*: If addressof(x) == this, there are no effects[.](#ops-26.sentence-1)
|
||
|
||
Otherwise, merges
|
||
the two sorted ranges [begin(), end()) and [x.begin(), x.end())[.](#ops-26.sentence-2)
|
||
|
||
The result is a range
|
||
that is sorted with respect to the comparator comp[.](#ops-26.sentence-3)
|
||
|
||
Pointers and references to the moved elements of x now refer to those same elements
|
||
but as members of *this[.](#ops-26.sentence-4)
|
||
|
||
Iterators referring to the moved elements will continue to
|
||
refer to their elements, but they now behave as iterators into *this, not intox[.](#ops-26.sentence-5)
|
||
|
||
[27](#ops-27)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7790)
|
||
|
||
*Complexity*: At most distance(begin(),
|
||
end()) + distance(x.begin(), x.end()) - 1 comparisons
|
||
if addressof(x) != this; otherwise, no comparisons are performed[.](#ops-27.sentence-1)
|
||
|
||
[28](#ops-28)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7796)
|
||
|
||
*Remarks*: Stable ([[algorithm.stable]](algorithm.stable "16.4.6.8 Requirements for stable algorithms"))[.](#ops-28.sentence-1)
|
||
|
||
If addressof(x) != this, x is empty after the merge[.](#ops-28.sentence-2)
|
||
|
||
No elements are copied by this operation[.](#ops-28.sentence-3)
|
||
|
||
If an exception is thrown other than by a comparison, there are no effects[.](#ops-28.sentence-4)
|
||
|
||
[ð](#lib:sort,forward_list)
|
||
|
||
`constexpr void sort();
|
||
template<class Compare> constexpr void sort(Compare comp);
|
||
`
|
||
|
||
[29](#ops-29)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7811)
|
||
|
||
*Effects*: Sorts the list according to the operator< or the comp function object[.](#ops-29.sentence-1)
|
||
|
||
If an exception is thrown, the order of the elements in *this is unspecified[.](#ops-29.sentence-2)
|
||
|
||
Does not affect the validity of iterators and references[.](#ops-29.sentence-3)
|
||
|
||
[30](#ops-30)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7817)
|
||
|
||
*Complexity*: Approximately NlogN comparisons, where N is distance(begin(), end())[.](#ops-30.sentence-1)
|
||
|
||
[31](#ops-31)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7821)
|
||
|
||
*Remarks*: [Stable](algorithm.stable "16.4.6.8 Requirements for stable algorithms [algorithm.stable]")[.](#ops-31.sentence-1)
|
||
|
||
[ð](#lib:reverse,forward_list)
|
||
|
||
`constexpr void reverse() noexcept;
|
||
`
|
||
|
||
[32](#ops-32)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7832)
|
||
|
||
*Effects*: Reverses the order of the elements in the list[.](#ops-32.sentence-1)
|
||
|
||
Does not affect the validity of iterators and references[.](#ops-32.sentence-2)
|
||
|
||
[33](#ops-33)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7837)
|
||
|
||
*Complexity*: Linear time[.](#ops-33.sentence-1)
|
||
|
||
#### [23.3.7.7](#erasure) Erasure [[forward.list.erasure]](forward.list.erasure)
|
||
|
||
[ð](#lib:erase,forward_list)
|
||
|
||
`template<class T, class Allocator, class U = T>
|
||
constexpr typename forward_list<T, Allocator>::size_type
|
||
erase(forward_list<T, Allocator>& c, const U& value);
|
||
`
|
||
|
||
[1](#erasure-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7852)
|
||
|
||
*Effects*: Equivalent to:return erase_if(c, [&](const auto& elem) -> bool { return elem == value; });
|
||
|
||
[ð](#lib:erase_if,forward_list)
|
||
|
||
`template<class T, class Allocator, class Predicate>
|
||
constexpr typename forward_list<T, Allocator>::size_type
|
||
erase_if(forward_list<T, Allocator>& c, Predicate pred);
|
||
`
|
||
|
||
[2](#erasure-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7868)
|
||
|
||
*Effects*: Equivalent to: return c.remove_if(pred);
|