Files
cppdraft_translate/cppdraft/list.md
2025-10-25 03:02:53 +03:00

669 lines
31 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[list]
# 23 Containers library [[containers]](./#containers)
## 23.3 Sequence containers [[sequences]](sequences#list)
### 23.3.11 Class template list [list]
#### [23.3.11.1](#overview) Overview [[list.overview]](list.overview)
[1](#overview-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9016)
Alist is a sequence container that supports
bidirectional iterators and allows constant time insert and erase
operations anywhere within the sequence, with storage management handled
automatically[.](#overview-1.sentence-1)
Unlike [vectors](vector "23.3.13Class template vector[vector]") and [deques](deque "23.3.5Class template deque[deque]"),
fast random access to list elements is not supported, but many
algorithms only need sequential access anyway[.](#overview-1.sentence-2)
[2](#overview-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9027)
A list meets all of the requirements
of a container ([[container.reqmts]](container.reqmts "23.2.2.2Container requirements")),
of a reversible container ([[container.rev.reqmts]](container.rev.reqmts "23.2.2.3Reversible container requirements")),
of an allocator-aware container ([[container.alloc.reqmts]](container.alloc.reqmts "23.2.2.5Allocator-aware containers")), and
of a sequence container,
including most of the optional sequence container
requirements ([[sequence.reqmts]](sequence.reqmts "23.2.4Sequence containers"))[.](#overview-2.sentence-1)
The exceptions are theoperator[] andat member functions, which are not provided[.](#overview-2.sentence-2)[195](#footnote-195 "These member functions are only provided by containers whose iterators are random access iterators.")
Descriptions are provided here only for operations onlist that are not described in one of these tables
or for operations where there is additional semantic information[.](#overview-2.sentence-3)
[3](#overview-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9050)
The types iterator and const_iterator meet
the constexpr iterator requirements[[iterator.requirements.general]](iterator.requirements.general "24.3.1General")[.](#overview-3.sentence-1)
namespace std {template<class T, class Allocator = allocator<T>>class 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.2Requirements")using difference_type = *implementation-defined*; // see [[container.requirements]](container.requirements "23.2Requirements")using iterator = *implementation-defined*; // see [[container.requirements]](container.requirements "23.2Requirements")using const_iterator = *implementation-defined*; // see [[container.requirements]](container.requirements "23.2Requirements")using reverse_iterator = std::reverse_iterator<iterator>; using const_reverse_iterator = std::reverse_iterator<const_iterator>; // [[list.cons]](#cons "23.3.11.2Constructors, copy, and assignment"), construct/copy/destroyconstexpr list() : list(Allocator()) { }constexpr explicit list(const Allocator&); constexpr explicit list(size_type n, const Allocator& = Allocator()); constexpr list(size_type n, const T& value, const Allocator& = Allocator()); template<class InputIterator>constexpr list(InputIterator first, InputIterator last, const Allocator& = Allocator()); template<[*container-compatible-range*](container.intro.reqmts#concept:container-compatible-range "23.2.2.1Introduction[container.intro.reqmts]")<T> R>constexpr list(from_range_t, R&& rg, const Allocator& = Allocator()); constexpr list(const list& x); constexpr list(list&& x); constexpr list(const list&, const type_identity_t<Allocator>&); constexpr list(list&&, const type_identity_t<Allocator>&); constexpr list(initializer_list<T>, const Allocator& = Allocator()); constexpr ~list(); constexpr list& operator=(const list& x); constexpr list& operator=(list&& x)noexcept(allocator_traits<Allocator>::is_always_equal::value); constexpr 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.1Introduction[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; // iteratorsconstexpr iterator begin() noexcept; constexpr const_iterator begin() const noexcept; constexpr iterator end() noexcept; constexpr const_iterator end() const noexcept; constexpr reverse_iterator rbegin() noexcept; constexpr const_reverse_iterator rbegin() const noexcept; constexpr reverse_iterator rend() noexcept; constexpr const_reverse_iterator rend() const noexcept; constexpr const_iterator cbegin() const noexcept; constexpr const_iterator cend() const noexcept; constexpr const_reverse_iterator crbegin() const noexcept; constexpr const_reverse_iterator crend() const noexcept; // [[list.capacity]](#capacity "23.3.11.3Capacity"), capacityconstexpr bool empty() const noexcept; constexpr size_type size() const noexcept; constexpr size_type max_size() const noexcept; constexpr void resize(size_type sz); constexpr void resize(size_type sz, const T& c); // element accessconstexpr reference front(); constexpr const_reference front() const; constexpr reference back(); constexpr const_reference back() const; // [[list.modifiers]](#modifiers "23.3.11.4Modifiers"), modifierstemplate<class... Args> constexpr reference emplace_front(Args&&... args); template<class... Args> constexpr reference emplace_back(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.1Introduction[container.intro.reqmts]")<T> R>constexpr void prepend_range(R&& rg); constexpr void pop_front(); constexpr void push_back(const T& x); constexpr void push_back(T&& x); template<[*container-compatible-range*](container.intro.reqmts#concept:container-compatible-range "23.2.2.1Introduction[container.intro.reqmts]")<T> R>constexpr void append_range(R&& rg); constexpr void pop_back(); template<class... Args> constexpr iterator emplace(const_iterator position, Args&&... args); constexpr iterator insert(const_iterator position, const T& x); constexpr iterator insert(const_iterator position, T&& x); constexpr iterator insert(const_iterator position, size_type n, const T& x); template<class InputIterator>constexpr iterator insert(const_iterator position,
InputIterator first, InputIterator last); template<[*container-compatible-range*](container.intro.reqmts#concept:container-compatible-range "23.2.2.1Introduction[container.intro.reqmts]")<T> R>constexpr iterator insert_range(const_iterator position, R&& rg); constexpr iterator insert(const_iterator position, initializer_list<T> il); constexpr iterator erase(const_iterator position); constexpr iterator erase(const_iterator position, const_iterator last); constexpr void swap(list&) noexcept(allocator_traits<Allocator>::is_always_equal::value); constexpr void clear() noexcept; // [[list.ops]](#ops "23.3.11.5Operations"), list operationsconstexpr void splice(const_iterator position, list& x); constexpr void splice(const_iterator position, list&& x); constexpr void splice(const_iterator position, list& x, const_iterator i); constexpr void splice(const_iterator position, list&& x, const_iterator i); constexpr void splice(const_iterator position, list& x,
const_iterator first, const_iterator last); constexpr void splice(const_iterator position, 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); constexpr size_type unique(); template<class BinaryPredicate>constexpr size_type unique(BinaryPredicate binary_pred); constexpr void merge(list& x); constexpr void merge(list&& x); template<class Compare> constexpr void merge(list& x, Compare comp); template<class Compare> constexpr void merge(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>>> list(InputIterator, InputIterator, Allocator = Allocator())-> list<*iter-value-type*<InputIterator>, Allocator>; template<ranges::[input_range](range.refinements#concept:input_range "25.4.6Other range refinements[range.refinements]") R, class Allocator = allocator<ranges::range_value_t<R>>> list(from_range_t, R&&, Allocator = Allocator())-> list<ranges::range_value_t<R>, Allocator>;}
[4](#overview-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9196)
An incomplete type T may be used when instantiating list if the allocator meets the[allocator completeness requirements](allocator.requirements.completeness "16.4.4.6.2Allocator completeness requirements[allocator.requirements.completeness]")[.](#overview-4.sentence-1)
T shall be complete before any member of the resulting specialization
of list is referenced[.](#overview-4.sentence-2)
[195)](#footnote-195)[195)](#footnoteref-195)
These member functions
are only provided by containers whose iterators
are random access iterators[.](#footnote-195.sentence-1)
#### [23.3.11.2](#cons) Constructors, copy, and assignment [[list.cons]](list.cons)
[🔗](#lib:list,constructor)
`constexpr explicit list(const Allocator&);
`
[1](#cons-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9211)
*Effects*: Constructs an empty list, using the specified allocator[.](#cons-1.sentence-1)
[2](#cons-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9215)
*Complexity*: Constant[.](#cons-2.sentence-1)
[🔗](#lib:list,constructor_)
`constexpr explicit list(size_type n, const Allocator& = Allocator());
`
[3](#cons-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9226)
*Preconditions*: T is *Cpp17DefaultInsertable* into list[.](#cons-3.sentence-1)
[4](#cons-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9230)
*Effects*: Constructs a list withn default-inserted elements using the specified allocator[.](#cons-4.sentence-1)
[5](#cons-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9235)
*Complexity*: Linear inn[.](#cons-5.sentence-1)
[🔗](#lib:list,constructor__)
`constexpr list(size_type n, const T& value, const Allocator& = Allocator());
`
[6](#cons-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9247)
*Preconditions*: T is *Cpp17CopyInsertable* into list[.](#cons-6.sentence-1)
[7](#cons-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9251)
*Effects*: Constructs alist withn copies ofvalue,
using the specified allocator[.](#cons-7.sentence-1)
[8](#cons-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9261)
*Complexity*: Linear inn[.](#cons-8.sentence-1)
[🔗](#lib:list,constructor___)
`template<class InputIterator>
constexpr list(InputIterator first, InputIterator last, const Allocator& = Allocator());
`
[9](#cons-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9274)
*Effects*: Constructs alist equal to the range
[first, last)[.](#cons-9.sentence-1)
[10](#cons-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9281)
*Complexity*: Linear indistance(first, last)[.](#cons-10.sentence-1)
[🔗](#lib:list,constructor____)
`template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1Introduction[container.intro.reqmts]")<T> R>
constexpr list(from_range_t, R&& rg, const Allocator& = Allocator());
`
[11](#cons-11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9294)
*Effects*: Constructs a 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#L9298)
*Complexity*: Linear in ranges::distance(rg)[.](#cons-12.sentence-1)
#### [23.3.11.3](#capacity) Capacity [[list.capacity]](list.capacity)
[🔗](#lib:resize,list)
`constexpr void resize(size_type sz);
`
[1](#capacity-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9311)
*Preconditions*: T is *Cpp17DefaultInsertable* into list[.](#capacity-1.sentence-1)
[2](#capacity-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9315)
*Effects*: If size() < sz,
appends sz - size() default-inserted elements to the
sequence[.](#capacity-2.sentence-1)
If sz <= size(), equivalent to:list<T>::iterator it = begin();
advance(it, sz);
erase(it, end());
[🔗](#lib:resize,list_)
`constexpr void resize(size_type sz, const T& c);
`
[3](#capacity-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9334)
*Preconditions*: T is *Cpp17CopyInsertable* into list[.](#capacity-3.sentence-1)
[4](#capacity-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9338)
*Effects*: As if by:if (sz > size()) insert(end(), sz-size(), c);else if (sz < size()) { iterator i = begin();
advance(i, sz);
erase(i, end());}else ; // do nothing
#### [23.3.11.4](#modifiers) Modifiers [[list.modifiers]](list.modifiers)
[🔗](#lib:insert,list)
`constexpr iterator insert(const_iterator position, const T& x);
constexpr iterator insert(const_iterator position, T&& x);
constexpr iterator insert(const_iterator position, size_type n, const T& x);
template<class InputIterator>
constexpr iterator insert(const_iterator position,
InputIterator first, InputIterator last);
template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1Introduction[container.intro.reqmts]")<T> R>
constexpr iterator insert_range(const_iterator position, R&& rg);
constexpr iterator insert(const_iterator position, initializer_list<T>);
template<class... Args> constexpr reference emplace_front(Args&&... args);
template<class... Args> constexpr reference emplace_back(Args&&... args);
template<class... Args> constexpr iterator emplace(const_iterator position, 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.1Introduction[container.intro.reqmts]")<T> R>
constexpr void prepend_range(R&& rg);
constexpr void push_back(const T& x);
constexpr void push_back(T&& x);
template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1Introduction[container.intro.reqmts]")<T> R>
constexpr void append_range(R&& rg);
`
[1](#modifiers-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9382)
*Complexity*: Insertion of a single element into a list takes constant time and
exactly one call to a constructor ofT[.](#modifiers-1.sentence-1)
Insertion of multiple elements into a list is linear in the
number of elements inserted, and the number of calls to the copy
constructor or move constructor of T is exactly equal
to the number of elements inserted[.](#modifiers-1.sentence-2)
[2](#modifiers-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9391)
*Remarks*: Does not affect the validity of iterators and references[.](#modifiers-2.sentence-1)
If an exception is thrown, there are no effects[.](#modifiers-2.sentence-2)
[🔗](#lib:erase,list)
`constexpr iterator erase(const_iterator position);
constexpr iterator erase(const_iterator first, const_iterator last);
constexpr void pop_front();
constexpr void pop_back();
constexpr void clear() noexcept;
`
[3](#modifiers-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9407)
*Effects*: Invalidates only the iterators and references to the erased elements[.](#modifiers-3.sentence-1)
[4](#modifiers-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9411)
*Throws*: Nothing[.](#modifiers-4.sentence-1)
[5](#modifiers-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9415)
*Complexity*: Erasing a single element is a constant time operation with a single call to the destructor ofT[.](#modifiers-5.sentence-1)
Erasing a range in a list is linear time in the
size of the range and the number of calls to the destructor of typeT is exactly equal to the size of the range[.](#modifiers-5.sentence-2)
#### [23.3.11.5](#ops) Operations [[list.ops]](list.ops)
[1](#ops-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9427)
Since lists allow fast insertion and erasing from the middle of a list, certain
operations are provided specifically for them[.](#ops-1.sentence-1)[196](#footnote-196 "As specified in [allocator.requirements], the requirements in this Clause apply only to lists whose allocators compare equal.")
In this subclause,
arguments for a template parameter
named Predicate or BinaryPredicate shall meet the corresponding requirements in [[algorithms.requirements]](algorithms.requirements "26.2Algorithms requirements")[.](#ops-1.sentence-2)
The semantics of i + n and i - n,
where i is an iterator into the list and n is an integer,
are the same as those of next(i, n) and prev(i, n),
respectively[.](#ops-1.sentence-3)
For merge and sort,
the definitions and requirements in [[alg.sorting]](alg.sorting "26.8Sorting and related operations") apply[.](#ops-1.sentence-4)
[2](#ops-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9446)
list provides three splice operations that destructively move elements from one list to
another[.](#ops-2.sentence-1)
The behavior of splice operations is undefined if get_allocator() != x.get_allocator()[.](#ops-2.sentence-2)
[🔗](#lib:splice,list)
`constexpr void splice(const_iterator position, list& x);
constexpr void splice(const_iterator position, list&& x);
`
[3](#ops-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9458)
*Preconditions*: addressof(x) != this is true[.](#ops-3.sentence-1)
[4](#ops-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9462)
*Effects*: Inserts the contents ofx beforeposition andx becomes empty[.](#ops-4.sentence-1)
Pointers and references to the moved elements ofx now refer to those same elements but as members of*this[.](#ops-4.sentence-2)
Iterators referring to the moved elements will continue to refer to their
elements, but they now behave as iterators into*this,
not intox[.](#ops-4.sentence-3)
[5](#ops-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9481)
*Throws*: Nothing[.](#ops-5.sentence-1)
[6](#ops-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9485)
*Complexity*: Constant time[.](#ops-6.sentence-1)
[🔗](#lib:splice,list_)
`constexpr void splice(const_iterator position, list& x, const_iterator i);
constexpr void splice(const_iterator position, list&& x, const_iterator i);
`
[7](#ops-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9497)
*Preconditions*: i is a valid dereferenceable iterator of x[.](#ops-7.sentence-1)
[8](#ops-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9501)
*Effects*: Inserts an element pointed to byi from listx before position and removes the element fromx[.](#ops-8.sentence-1)
The result is unchanged ifposition == i orposition == ++i[.](#ops-8.sentence-2)
Pointers and references to*i continue to refer to this same element but as a member of*this[.](#ops-8.sentence-3)
Iterators
to*i (includingi itself) continue to refer to the same element, but now behave as iterators into*this,
not intox[.](#ops-8.sentence-4)
[9](#ops-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9527)
*Throws*: Nothing[.](#ops-9.sentence-1)
[10](#ops-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9531)
*Complexity*: Constant time[.](#ops-10.sentence-1)
[🔗](#lib:splice,list__)
`constexpr void splice(const_iterator position, list& x,
const_iterator first, const_iterator last);
constexpr void splice(const_iterator position, list&& x,
const_iterator first, const_iterator last);
`
[11](#ops-11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9545)
*Preconditions*: [first, last) is a valid range in x[.](#ops-11.sentence-1)
position is not an iterator in the range [first, last)[.](#ops-11.sentence-2)
[12](#ops-12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9550)
*Effects*: Inserts elements in the range
[first, last)
beforeposition and removes the elements fromx[.](#ops-12.sentence-1)
Pointers and references to the moved elements ofx now refer to those same elements but as members of*this[.](#ops-12.sentence-2)
Iterators referring to the moved elements will continue to refer to their
elements, but they now behave as iterators into*this,
not intox[.](#ops-12.sentence-3)
[13](#ops-13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9568)
*Throws*: Nothing[.](#ops-13.sentence-1)
[14](#ops-14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9572)
*Complexity*: Constant time ifaddressof(x) == this;
otherwise, linear time[.](#ops-14.sentence-1)
[🔗](#lib:remove,list)
`constexpr size_type remove(const T& value);
template<class Predicate> constexpr size_type remove_if(Predicate pred);
`
[15](#ops-15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9586)
*Effects*: Erases all the elements in the list referred to by a list iterator i for which the
following conditions hold: *i == value, pred(*i) != false[.](#ops-15.sentence-1)
Invalidates only the iterators and references to the erased elements[.](#ops-15.sentence-2)
[16](#ops-16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9592)
*Returns*: The number of elements erased[.](#ops-16.sentence-1)
[17](#ops-17)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9596)
*Throws*: Nothing unless an exception is thrown by*i == value orpred(*i) != false[.](#ops-17.sentence-1)
[18](#ops-18)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9603)
*Complexity*: Exactlysize() applications of the corresponding predicate[.](#ops-18.sentence-1)
[19](#ops-19)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9609)
*Remarks*: [Stable](algorithm.stable "16.4.6.8Requirements for stable algorithms[algorithm.stable]")[.](#ops-19.sentence-1)
[🔗](#lib:unique,list)
`constexpr size_type unique();
template<class BinaryPredicate> constexpr size_type unique(BinaryPredicate binary_pred);
`
[20](#ops-20)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9621)
Let binary_pred be equal_to<>{} for the first overload[.](#ops-20.sentence-1)
[21](#ops-21)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9624)
*Preconditions*: binary_pred is an equivalence relation[.](#ops-21.sentence-1)
[22](#ops-22)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9628)
*Effects*: Erases all but the first element from every
consecutive group of equivalent elements[.](#ops-22.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-22.sentence-2)
Invalidates only the iterators and references to the erased elements[.](#ops-22.sentence-3)
[23](#ops-23)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9637)
*Returns*: The number of elements erased[.](#ops-23.sentence-1)
[24](#ops-24)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9641)
*Throws*: Nothing unless an exception is thrown by the predicate[.](#ops-24.sentence-1)
[25](#ops-25)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9645)
*Complexity*: If empty() is false,
exactly size() - 1 applications of the corresponding predicate,
otherwise no applications of the predicate[.](#ops-25.sentence-1)
[🔗](#lib:merge,list)
`constexpr void merge(list& x);
constexpr void merge(list&& x);
template<class Compare> constexpr void merge(list& x, Compare comp);
template<class Compare> constexpr void merge(list&& x, Compare comp);
`
[26](#ops-26)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9661)
Let comp be less<> for the first two overloads[.](#ops-26.sentence-1)
[27](#ops-27)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9664)
*Preconditions*: *this and x are both sorted
with respect to the comparator comp, andget_allocator() == x.get_allocator() is true[.](#ops-27.sentence-1)
[28](#ops-28)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9670)
*Effects*: If addressof(x) == this, there are no effects[.](#ops-28.sentence-1)
Otherwise, merges
the two sorted ranges [begin(), end()) and [x.begin(), x.end())[.](#ops-28.sentence-2)
The result is a range
that is sorted with respect to the comparator comp[.](#ops-28.sentence-3)
Pointers and references to the moved elements of x now refer to those same elements
but as members of *this[.](#ops-28.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-28.sentence-5)
[29](#ops-29)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9682)
*Complexity*: At most size() + x.size() - 1 comparisons
if addressof(x) != this;
otherwise, no comparisons are performed[.](#ops-29.sentence-1)
[30](#ops-30)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9688)
*Remarks*: Stable ([[algorithm.stable]](algorithm.stable "16.4.6.8Requirements for stable algorithms"))[.](#ops-30.sentence-1)
If addressof(x) != this, x is empty after the merge[.](#ops-30.sentence-2)
No elements are copied by this operation[.](#ops-30.sentence-3)
If an exception is thrown other than by a comparison, there are no effects[.](#ops-30.sentence-4)
[🔗](#lib:reverse,list)
`constexpr void reverse() noexcept;
`
[31](#ops-31)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9702)
*Effects*: Reverses the order of the elements in the list[.](#ops-31.sentence-1)
Does not affect the validity of iterators and references[.](#ops-31.sentence-2)
[32](#ops-32)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9707)
*Complexity*: Linear time[.](#ops-32.sentence-1)
[🔗](#lib:sort,list)
`void sort();
template<class Compare> void sort(Compare comp);
`
[33](#ops-33)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9719)
*Effects*: Sorts the list according to the operator< or a Compare function object[.](#ops-33.sentence-1)
If an exception is thrown,
the order of the elements in *this is unspecified[.](#ops-33.sentence-2)
Does not affect the validity of iterators and references[.](#ops-33.sentence-3)
[34](#ops-34)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9726)
*Complexity*: ApproximatelyNlogN comparisons, where N is size()[.](#ops-34.sentence-1)
[35](#ops-35)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9732)
*Remarks*: [Stable](algorithm.stable "16.4.6.8Requirements for stable algorithms[algorithm.stable]")[.](#ops-35.sentence-1)
[196)](#footnote-196)[196)](#footnoteref-196)
As specified
in [[allocator.requirements]](allocator.requirements "16.4.4.6Cpp17Allocator requirements"), the requirements in this Clause apply only to
lists whose allocators compare equal[.](#footnote-196.sentence-1)
#### [23.3.11.6](#erasure) Erasure [[list.erasure]](list.erasure)
[🔗](#lib:erase,list_)
`template<class T, class Allocator, class U = T>
typename list<T, Allocator>::size_type
constexpr erase(list<T, Allocator>& c, const U& value);
`
[1](#erasure-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9747)
*Effects*: Equivalent to:return erase_if(c, [&](const auto& elem) -> bool { return elem == value; });
[🔗](#lib:erase_if,list)
`template<class T, class Allocator, class Predicate>
typename list<T, Allocator>::size_type
constexpr erase_if(list<T, Allocator>& c, Predicate pred);
`
[2](#erasure-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9763)
*Effects*: Equivalent to: return c.remove_if(pred);