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

4750 lines
231 KiB
Markdown
Raw Permalink 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.

[sequences]
# 23 Containers library [[containers]](./#containers)
## 23.3 Sequence containers [sequences]
### [23.3.1](#general) General [[sequences.general]](sequences.general)
[1](#general-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6039)
The headers[<array>](#header:%3carray%3e "23.3.2Header <array> synopsis[array.syn]"),[<deque>](#header:%3cdeque%3e "23.3.4Header <deque> synopsis[deque.syn]"),[<forward_list>](#header:%3cforward_list%3e "23.3.6Header <forward_­list> synopsis[forward.list.syn]"),[<hive>](#header:%3chive%3e "23.3.8Header <hive> synopsis[hive.syn]"),[<inplace_vector>](#header:%3cinplace_vector%3e "23.3.15Header <inplace_­vector> synopsis[inplace.vector.syn]"),[<list>](#header:%3clist%3e "23.3.10Header <list> synopsis[list.syn]"), and[<vector>](#header:%3cvector%3e "23.3.12Header <vector> synopsis[vector.syn]") define class templates that meet the requirements for sequence containers[.](#general-1.sentence-1)
[2](#general-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6050)
The following exposition-only alias template may appear in deduction guides for sequence containers:template<class InputIterator>using *iter-value-type* = typename iterator_traits<InputIterator>::value_type; // *exposition only*
### [23.3.2](#array.syn) Header <array> synopsis [[array.syn]](array.syn)
[🔗](#header:%3carray%3e)
// mostly freestanding#include <compare> // see [[compare.syn]](compare.syn "17.12.1Header <compare> synopsis")#include <initializer_list> // see [[initializer.list.syn]](initializer.list.syn "17.11.2Header <initializer_­list> synopsis")namespace std {// [[array]](#array "23.3.3Class template array"), class template arraytemplate<class T, size_t N> struct array; // partially freestandingtemplate<class T, size_t N>constexpr bool operator==(const array<T, N>& x, const array<T, N>& y); template<class T, size_t N>constexpr *synth-three-way-result*<T>operator<=>(const array<T, N>& x, const array<T, N>& y); // [[array.special]](#array.special "23.3.3.4Specialized algorithms"), specialized algorithmstemplate<class T, size_t N>constexpr void swap(array<T, N>& x, array<T, N>& y) noexcept(noexcept(x.swap(y))); // [[array.creation]](#array.creation "23.3.3.6Array creation functions"), array creation functionstemplate<class T, size_t N>constexpr array<remove_cv_t<T>, N> to_array(T (&a)[N]); template<class T, size_t N>constexpr array<remove_cv_t<T>, N> to_array(T (&&a)[N]); // [[array.tuple]](#array.tuple "23.3.3.7Tuple interface"), tuple interfacetemplate<class T> struct tuple_size; template<size_t I, class T> struct tuple_element; template<class T, size_t N>struct tuple_size<array<T, N>>; template<size_t I, class T, size_t N>struct tuple_element<I, array<T, N>>; template<size_t I, class T, size_t N>constexpr T& get(array<T, N>&) noexcept; template<size_t I, class T, size_t N>constexpr T&& get(array<T, N>&&) noexcept; template<size_t I, class T, size_t N>constexpr const T& get(const array<T, N>&) noexcept; template<size_t I, class T, size_t N>constexpr const T&& get(const array<T, N>&&) noexcept;}
### [23.3.3](#array) Class template array [[array]](array)
#### [23.3.3.1](#array.overview) Overview [[array.overview]](array.overview)
[1](#array.overview-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6108)
The header [<array>](#header:%3carray%3e "23.3.2Header <array> synopsis[array.syn]") defines a class template for storing fixed-size
sequences of objects[.](#array.overview-1.sentence-1)
An array is a [contiguous container](container.reqmts#def:container,contiguous "23.2.2.2Container requirements[container.reqmts]")[.](#array.overview-1.sentence-2)
An instance of array<T, N> stores N elements of type T,
so that size() == N is an invariant[.](#array.overview-1.sentence-3)
[2](#array.overview-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6116)
An array is an [aggregate](dcl.init.aggr#def:aggregate "9.5.2Aggregates[dcl.init.aggr]") that can be
list-initialized with up
to N elements whose types are convertible to T[.](#array.overview-2.sentence-1)
[3](#array.overview-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6123)
An array meets all of the requirements
of a container ([[container.reqmts]](container.reqmts "23.2.2.2Container requirements")) and
of a reversible container ([[container.rev.reqmts]](container.rev.reqmts "23.2.2.3Reversible container requirements")),
except that a default
constructed array object is not empty if N>0[.](#array.overview-3.sentence-1)
An array meets some of the requirements of a[sequence container](sequence.reqmts "23.2.4Sequence containers[sequence.reqmts]")[.](#array.overview-3.sentence-2)
Descriptions are provided here
only for operations on array that are not described in
one of these tables and
for operations where there is additional semantic information[.](#array.overview-3.sentence-3)
[4](#array.overview-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6137)
array<T, N> is a structural type ([[temp.param]](temp.param#term.structural.type "13.2Template parameters")) ifT is a structural type[.](#array.overview-4.sentence-1)
Two values a1 and a2 of type array<T, N> are [template-argument-equivalent](temp.type#def:template-argument-equivalent "13.6Type equivalence[temp.type]") if and only if
each pair of corresponding elements in a1 and a2 are template-argument-equivalent[.](#array.overview-4.sentence-2)
[5](#array.overview-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6145)
The types iterator and const_iterator meet
the [constexpr iterator](iterator.requirements.general#def:iterator,constexpr "24.3.1General[iterator.requirements.general]") requirements[.](#array.overview-5.sentence-1)
[🔗](#lib:array_)
namespace std {template<class T, size_t N>struct array {// typesusing value_type = T; using pointer = T*; using const_pointer = const T*; using reference = T&; using const_reference = const T&; using size_type = size_t; using difference_type = ptrdiff_t; 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>; // no explicit construct/copy/destroy for aggregate typeconstexpr void fill(const T& u); constexpr void swap(array&) noexcept(is_nothrow_swappable_v<T>); // 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; // capacityconstexpr bool empty() const noexcept; constexpr size_type size() const noexcept; constexpr size_type max_size() const noexcept; // element accessconstexpr reference operator[](size_type n); constexpr const_reference operator[](size_type n) const; constexpr reference at(size_type n); // freestanding-deletedconstexpr const_reference at(size_type n) const; // freestanding-deletedconstexpr reference front(); constexpr const_reference front() const; constexpr reference back(); constexpr const_reference back() const; constexpr T* data() noexcept; constexpr const T* data() const noexcept; }; template<class T, class... U> array(T, U...) -> array<T, 1 + sizeof...(U)>;}
#### [23.3.3.2](#array.cons) Constructors, copy, and assignment [[array.cons]](array.cons)
[1](#array.cons-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6218)
An array relies on the implicitly-declared special
member functions ([[class.default.ctor]](class.default.ctor "11.4.5.2Default constructors"), [[class.dtor]](class.dtor "11.4.7Destructors"), [[class.copy.ctor]](class.copy.ctor "11.4.5.3Copy/move constructors")) to
conform to the container requirements table in [[container.requirements]](container.requirements "23.2Requirements")[.](#array.cons-1.sentence-1)
In addition to the requirements specified in the container requirements table,
the implicitly-declared move constructor and move assignment operator for array require that T be *Cpp17MoveConstructible* or *Cpp17MoveAssignable*,
respectively[.](#array.cons-1.sentence-2)
[🔗](#array.cons-itemdecl:1)
`template<class T, class... U>
array(T, U...) -> array<T, 1 + sizeof...(U)>;
`
[2](#array.cons-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6234)
*Mandates*: (is_same_v<T, U> && ...) is true[.](#array.cons-2.sentence-1)
#### [23.3.3.3](#array.members) Member functions [[array.members]](array.members)
[🔗](#lib:array,size_)
`constexpr size_type size() const noexcept;
`
[1](#array.members-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6247)
*Returns*: N[.](#array.members-1.sentence-1)
[🔗](#lib:array,data)
`constexpr T* data() noexcept;
constexpr const T* data() const noexcept;
`
[2](#array.members-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6259)
*Returns*: A pointer such that [data(), data() + size()) is a valid range[.](#array.members-2.sentence-1)
For a
non-empty array, data() == addressof(front()) is true[.](#array.members-2.sentence-2)
[🔗](#lib:array,fill)
`constexpr void fill(const T& u);
`
[3](#array.members-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6271)
*Effects*: As if by fill_n(begin(), N, u)[.](#array.members-3.sentence-1)
[🔗](#lib:array,swap)
`constexpr void swap(array& y) noexcept(is_nothrow_swappable_v<T>);
`
[4](#array.members-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6282)
*Effects*: Equivalent to swap_ranges(begin(), end(), y.begin())[.](#array.members-4.sentence-1)
[5](#array.members-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6286)
[*Note [1](#array.members-note-1)*:
Unlike the swap function for other containers, array::swap takes linear time, can exit via an exception, and does not cause iterators to
become associated with the other container[.](#array.members-5.sentence-1)
— *end note*]
#### [23.3.3.4](#array.special) Specialized algorithms [[array.special]](array.special)
[🔗](#lib:array,swap_)
`template<class T, size_t N>
constexpr void swap(array<T, N>& x, array<T, N>& y) noexcept(noexcept(x.swap(y)));
`
[1](#array.special-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6303)
*Constraints*: N == 0 or is_swappable_v<T> is true[.](#array.special-1.sentence-1)
[2](#array.special-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6307)
*Effects*: As if by x.swap(y)[.](#array.special-2.sentence-1)
[3](#array.special-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6311)
*Complexity*: Linear in N[.](#array.special-3.sentence-1)
#### [23.3.3.5](#array.zero) Zero-sized arrays [[array.zero]](array.zero)
[1](#array.zero-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6319)
array shall provide support for the special case N == 0[.](#array.zero-1.sentence-1)
[2](#array.zero-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6322)
In the case that N == 0, begin() == end() == unique value[.](#array.zero-2.sentence-1)
The return value of data() is unspecified[.](#array.zero-2.sentence-2)
[3](#array.zero-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6326)
The effect of calling front() or back() for a zero-sized array is
undefined[.](#array.zero-3.sentence-1)
[4](#array.zero-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6330)
Member function swap() shall have a
non-throwing exception specification[.](#array.zero-4.sentence-1)
#### [23.3.3.6](#array.creation) Array creation functions [[array.creation]](array.creation)
[🔗](#lib:to_array)
`template<class T, size_t N>
constexpr array<remove_cv_t<T>, N> to_array(T (&a)[N]);
`
[1](#array.creation-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6344)
*Mandates*: is_array_v<T> is false andis_constructible_v<remove_cv_t<T>, T&> is true[.](#array.creation-1.sentence-1)
[2](#array.creation-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6349)
*Preconditions*: T meets the *Cpp17CopyConstructible* requirements[.](#array.creation-2.sentence-1)
[3](#array.creation-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6353)
*Returns*: {{ a[0], …, a[N - 1] }}[.](#array.creation-3.sentence-1)
[🔗](#lib:to_array_)
`template<class T, size_t N>
constexpr array<remove_cv_t<T>, N> to_array(T (&&a)[N]);
`
[4](#array.creation-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6365)
*Mandates*: is_array_v<T> is false andis_constructible_v<remove_cv_t<T>, T> is true[.](#array.creation-4.sentence-1)
[5](#array.creation-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6370)
*Preconditions*: T meets the *Cpp17MoveConstructible* requirements[.](#array.creation-5.sentence-1)
[6](#array.creation-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6374)
*Returns*: {{ std::move(a[0]), …, std::move(a[N - 1]) }}[.](#array.creation-6.sentence-1)
#### [23.3.3.7](#array.tuple) Tuple interface [[array.tuple]](array.tuple)
[🔗](#lib:array__)
`template<class T, size_t N>
struct tuple_size<array<T, N>> : integral_constant<size_t, N> { };
`
[🔗](#lib:tuple_element)
`template<size_t I, class T, size_t N>
struct tuple_element<I, array<T, N>> {
using type = T;
};
`
[1](#array.tuple-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6398)
*Mandates*: I < N is true[.](#array.tuple-1.sentence-1)
[🔗](#lib:array,get)
`template<size_t I, class T, size_t N>
constexpr T& get(array<T, N>& a) noexcept;
template<size_t I, class T, size_t N>
constexpr T&& get(array<T, N>&& a) noexcept;
template<size_t I, class T, size_t N>
constexpr const T& get(const array<T, N>& a) noexcept;
template<size_t I, class T, size_t N>
constexpr const T&& get(const array<T, N>&& a) noexcept;
`
[2](#array.tuple-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6416)
*Mandates*: I < N is true[.](#array.tuple-2.sentence-1)
[3](#array.tuple-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6420)
*Returns*: A reference to the Ith element of a,
where indexing is zero-based[.](#array.tuple-3.sentence-1)
### [23.3.4](#deque.syn) Header <deque> synopsis [[deque.syn]](deque.syn)
[🔗](#header:%3cdeque%3e)
#include <compare> // see [[compare.syn]](compare.syn "17.12.1Header <compare> synopsis")#include <initializer_list> // see [[initializer.list.syn]](initializer.list.syn "17.11.2Header <initializer_­list> synopsis")namespace std {// [[deque]](#deque "23.3.5Class template deque"), class template dequetemplate<class T, class Allocator = allocator<T>> class deque; template<class T, class Allocator>constexpr bool operator==(const deque<T, Allocator>& x, const deque<T, Allocator>& y); template<class T, class Allocator>constexpr *synth-three-way-result*<T> operator<=>(const deque<T, Allocator>& x, const deque<T, Allocator>& y); template<class T, class Allocator>constexpr void swap(deque<T, Allocator>& x, deque<T, Allocator>& y)noexcept(noexcept(x.swap(y))); // [[deque.erasure]](#deque.erasure "23.3.5.5Erasure"), erasuretemplate<class T, class Allocator, class U = T>constexpr typename deque<T, Allocator>::size_type
erase(deque<T, Allocator>& c, const U& value); template<class T, class Allocator, class Predicate>constexpr typename deque<T, Allocator>::size_type
erase_if(deque<T, Allocator>& c, Predicate pred); namespace pmr {template<class T>using deque = std::deque<T, polymorphic_allocator<T>>; }}
### [23.3.5](#deque) Class template deque [[deque]](deque)
#### [23.3.5.1](#deque.overview) Overview [[deque.overview]](deque.overview)
[1](#deque.overview-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6466)
Adeque is a sequence container that supports [random access iterators](random.access.iterators "24.3.5.7Random access iterators[random.access.iterators]")[.](#deque.overview-1.sentence-1)
In addition, it supports constant time insert and erase operations at the beginning or the end;
insert and erase in the middle take linear time[.](#deque.overview-1.sentence-2)
That is, a deque is especially optimized for pushing and popping elements at the beginning and end[.](#deque.overview-1.sentence-3)
Storage management is handled automatically[.](#deque.overview-1.sentence-4)
[2](#deque.overview-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6476)
A deque 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 the optional sequence container requirements ([[sequence.reqmts]](sequence.reqmts "23.2.4Sequence containers"))[.](#deque.overview-2.sentence-1)
Descriptions are provided here only for operations ondeque that are not described in one of these tables
or for operations where there is additional semantic information[.](#deque.overview-2.sentence-2)
[3](#deque.overview-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6488)
The types iterator and const_iterator meet
the constexpr iterator requirements ([[iterator.requirements.general]](iterator.requirements.general "24.3.1General"))[.](#deque.overview-3.sentence-1)
namespace std {template<class T, class Allocator = allocator<T>>class deque {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>; // [[deque.cons]](#deque.cons "23.3.5.2Constructors, copy, and assignment"), construct/copy/destroyconstexpr deque() : deque(Allocator()) { }constexpr explicit deque(const Allocator&); constexpr explicit deque(size_type n, const Allocator& = Allocator()); constexpr deque(size_type n, const T& value, const Allocator& = Allocator()); template<class InputIterator>constexpr deque(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 deque(from_range_t, R&& rg, const Allocator& = Allocator()); constexpr deque(const deque& x); constexpr deque(deque&&); constexpr deque(const deque&, const type_identity_t<Allocator>&); constexpr deque(deque&&, const type_identity_t<Allocator>&); constexpr deque(initializer_list<T>, const Allocator& = Allocator()); constexpr ~deque(); constexpr deque& operator=(const deque& x); constexpr deque& operator=(deque&& x)noexcept(allocator_traits<Allocator>::is_always_equal::value); constexpr deque& 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; // [[deque.capacity]](#deque.capacity "23.3.5.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); constexpr void shrink_to_fit(); // element accessconstexpr reference operator[](size_type n); constexpr const_reference operator[](size_type n) const; constexpr reference at(size_type n); constexpr const_reference at(size_type n) const; constexpr reference front(); constexpr const_reference front() const; constexpr reference back(); constexpr const_reference back() const; // [[deque.modifiers]](#deque.modifiers "23.3.5.4Modifiers"), modifierstemplate<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); 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>); constexpr void pop_front(); constexpr void pop_back(); constexpr iterator erase(const_iterator position); constexpr iterator erase(const_iterator first, const_iterator last); constexpr void swap(deque&)noexcept(allocator_traits<Allocator>::is_always_equal::value); constexpr void clear() noexcept; }; template<class InputIterator, class Allocator = allocator<*iter-value-type*<InputIterator>>> deque(InputIterator, InputIterator, Allocator = Allocator())-> deque<*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>>> deque(from_range_t, R&&, Allocator = Allocator())-> deque<ranges::range_value_t<R>, Allocator>;}
#### [23.3.5.2](#deque.cons) Constructors, copy, and assignment [[deque.cons]](deque.cons)
[🔗](#lib:deque,constructor)
`constexpr explicit deque(const Allocator&);
`
[1](#deque.cons-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6624)
*Effects*: Constructs an emptydeque,
using the specified allocator[.](#deque.cons-1.sentence-1)
[2](#deque.cons-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6630)
*Complexity*: Constant[.](#deque.cons-2.sentence-1)
[🔗](#lib:deque,constructor_)
`constexpr explicit deque(size_type n, const Allocator& = Allocator());
`
[3](#deque.cons-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6641)
*Preconditions*: T is *Cpp17DefaultInsertable* into deque[.](#deque.cons-3.sentence-1)
[4](#deque.cons-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6645)
*Effects*: Constructs a deque withn default-inserted elements using the specified allocator[.](#deque.cons-4.sentence-1)
[5](#deque.cons-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6650)
*Complexity*: Linear in n[.](#deque.cons-5.sentence-1)
[🔗](#lib:deque,constructor__)
`constexpr deque(size_type n, const T& value, const Allocator& = Allocator());
`
[6](#deque.cons-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6661)
*Preconditions*: T is *Cpp17CopyInsertable* into deque[.](#deque.cons-6.sentence-1)
[7](#deque.cons-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6665)
*Effects*: Constructs adeque with n copies of value,
using the specified allocator[.](#deque.cons-7.sentence-1)
[8](#deque.cons-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6672)
*Complexity*: Linear in n[.](#deque.cons-8.sentence-1)
[🔗](#lib:deque,constructor___)
`template<class InputIterator>
constexpr deque(InputIterator first, InputIterator last, const Allocator& = Allocator());
`
[9](#deque.cons-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6684)
*Effects*: Constructs adeque equal to the range
[first, last),
using the specified allocator[.](#deque.cons-9.sentence-1)
[10](#deque.cons-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6692)
*Complexity*: Linear in distance(first, last)[.](#deque.cons-10.sentence-1)
[🔗](#lib:deque,constructor____)
`template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1Introduction[container.intro.reqmts]")<T> R>
constexpr deque(from_range_t, R&& rg, const Allocator& = Allocator());
`
[11](#deque.cons-11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6704)
*Effects*: Constructs a deque with the elements of the range rg,
using the specified allocator[.](#deque.cons-11.sentence-1)
[12](#deque.cons-12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6709)
*Complexity*: Linear in ranges::distance(rg)[.](#deque.cons-12.sentence-1)
#### [23.3.5.3](#deque.capacity) Capacity [[deque.capacity]](deque.capacity)
[🔗](#lib:resize,deque)
`constexpr void resize(size_type sz);
`
[1](#deque.capacity-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6722)
*Preconditions*: T is *Cpp17MoveInsertable* and *Cpp17DefaultInsertable* into deque[.](#deque.capacity-1.sentence-1)
[2](#deque.capacity-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6726)
*Effects*: If sz < size(), erases the last size() - sz elements
from the sequence[.](#deque.capacity-2.sentence-1)
Otherwise,
appends sz - size() default-inserted elements to the sequence[.](#deque.capacity-2.sentence-2)
[🔗](#lib:resize,deque_)
`constexpr void resize(size_type sz, const T& c);
`
[3](#deque.capacity-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6739)
*Preconditions*: T is *Cpp17CopyInsertable* into deque[.](#deque.capacity-3.sentence-1)
[4](#deque.capacity-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6743)
*Effects*: If sz < size(), erases the last size() - sz elements
from the sequence[.](#deque.capacity-4.sentence-1)
Otherwise,
appends sz - size() copies of c to the sequence[.](#deque.capacity-4.sentence-2)
[🔗](#lib:shrink_to_fit,deque)
`constexpr void shrink_to_fit();
`
[5](#deque.capacity-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6756)
*Preconditions*: T is *Cpp17MoveInsertable* into deque[.](#deque.capacity-5.sentence-1)
[6](#deque.capacity-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6760)
*Effects*: shrink_to_fit is a non-binding request to reduce memory use
but does not change the size of the sequence[.](#deque.capacity-6.sentence-1)
[*Note [1](#deque.capacity-note-1)*:
The request is non-binding to allow latitude for
implementation-specific optimizations[.](#deque.capacity-6.sentence-2)
— *end note*]
If the size is equal to the old capacity, or
if an exception is thrown other than by the move constructor
of a non-*Cpp17CopyInsertable* T,
then there are no effects[.](#deque.capacity-6.sentence-3)
[7](#deque.capacity-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6773)
*Complexity*: If the size is not equal to the old capacity,
linear in the size of the sequence;
otherwise constant[.](#deque.capacity-7.sentence-1)
[8](#deque.capacity-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6779)
*Remarks*: If the size is not equal to the old capacity,
then invalidates all the references, pointers, and iterators
referring to the elements in the sequence,
as well as the past-the-end iterator[.](#deque.capacity-8.sentence-1)
#### [23.3.5.4](#deque.modifiers) Modifiers [[deque.modifiers]](deque.modifiers)
[🔗](#lib:insert,deque)
`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](#deque.modifiers-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6818)
*Effects*: An insertion in the middle of the deque invalidates all the iterators and
references to elements of the deque[.](#deque.modifiers-1.sentence-1)
An insertion at either end of the
deque invalidates all the iterators to the deque, but has no effect on
the validity of references to elements of the deque[.](#deque.modifiers-1.sentence-2)
[2](#deque.modifiers-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6826)
*Complexity*: The complexity is linear in the number of elements inserted plus the lesser
of the distances to the beginning and end of the deque[.](#deque.modifiers-2.sentence-1)
Inserting a single element at either the beginning or end of a deque always takes constant time
and causes a single call to a constructor ofT[.](#deque.modifiers-2.sentence-2)
[3](#deque.modifiers-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6834)
*Remarks*: If an exception is thrown other than by the
copy constructor, move constructor,
assignment operator, or move assignment operator ofT,
there are no effects[.](#deque.modifiers-3.sentence-1)
If an exception is thrown while inserting a single element at either end,
there are no effects[.](#deque.modifiers-3.sentence-2)
Otherwise, if an exception is thrown by the move constructor of a
non-*Cpp17CopyInsertable*T, the effects are unspecified[.](#deque.modifiers-3.sentence-3)
[🔗](#lib:erase,deque)
`constexpr iterator erase(const_iterator position);
constexpr iterator erase(const_iterator first, const_iterator last);
constexpr void pop_front();
constexpr void pop_back();
`
[4](#deque.modifiers-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6857)
*Effects*: An erase operation that erases the last element of a deque invalidates only the past-the-end iterator
and all iterators and references to the erased elements[.](#deque.modifiers-4.sentence-1)
An erase operation that erases the first
element of a deque but not the last element invalidates only iterators
and references to the erased elements[.](#deque.modifiers-4.sentence-2)
An erase operation
that erases neither the first element nor the last element of a deque invalidates the past-the-end
iterator and all iterators and references to all the elements of the deque[.](#deque.modifiers-4.sentence-3)
[*Note [1](#deque.modifiers-note-1)*:
pop_front and pop_back are erase operations[.](#deque.modifiers-4.sentence-4)
— *end note*]
[5](#deque.modifiers-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6869)
*Throws*: Nothing unless an exception is thrown by the assignment operator ofT[.](#deque.modifiers-5.sentence-1)
[6](#deque.modifiers-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6874)
*Complexity*: The number of calls to the destructor of T is the same as the
number of elements erased, but the number of calls to the assignment operator of T is
no more than the lesser of the number of elements before the erased elements and the number of elements after the erased elements[.](#deque.modifiers-6.sentence-1)
#### [23.3.5.5](#deque.erasure) Erasure [[deque.erasure]](deque.erasure)
[🔗](#lib:erase,deque_)
`template<class T, class Allocator, class U = T>
constexpr typename deque<T, Allocator>::size_type
erase(deque<T, Allocator>& c, const U& value);
`
[1](#deque.erasure-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6891)
*Effects*: Equivalent to:auto it = remove(c.begin(), c.end(), value);auto r = distance(it, c.end());
c.erase(it, c.end());return r;
[🔗](#lib:erase_if,deque)
`template<class T, class Allocator, class Predicate>
constexpr typename deque<T, Allocator>::size_type
erase_if(deque<T, Allocator>& c, Predicate pred);
`
[2](#deque.erasure-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6910)
*Effects*: Equivalent to:auto it = remove_if(c.begin(), c.end(), pred);auto r = distance(it, c.end());
c.erase(it, c.end());return r;
### [23.3.6](#forward.list.syn) Header <forward_list> synopsis [[forward.list.syn]](forward.list.syn)
[🔗](#header:%3cforward_list%3e)
#include <compare> // see [[compare.syn]](compare.syn "17.12.1Header <compare> synopsis")#include <initializer_list> // see [[initializer.list.syn]](initializer.list.syn "17.11.2Header <initializer_­list> synopsis")namespace std {// [[forward.list]](#forward.list "23.3.7Class template forward_­list"), class template forward_listtemplate<class T, class Allocator = allocator<T>> class forward_list; template<class T, class Allocator>constexpr bool operator==(const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y); template<class T, class Allocator>constexpr *synth-three-way-result*<T> operator<=>(const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y); template<class T, class Allocator>constexpr void swap(forward_list<T, Allocator>& x, forward_list<T, Allocator>& y)noexcept(noexcept(x.swap(y))); // [[forward.list.erasure]](#forward.list.erasure "23.3.7.7Erasure"), erasuretemplate<class T, class Allocator, class U = T>constexpr typename forward_list<T, Allocator>::size_type
erase(forward_list<T, Allocator>& c, const U& value); template<class T, class Allocator, class Predicate>constexpr typename forward_list<T, Allocator>::size_type
erase_if(forward_list<T, Allocator>& c, Predicate pred); namespace pmr {template<class T>using forward_list = std::forward_list<T, polymorphic_allocator<T>>; }}
### [23.3.7](#forward.list) Class template forward_list [[forward.list]](forward.list)
#### [23.3.7.1](#forward.list.overview) Overview [[forward.list.overview]](forward.list.overview)
[1](#forward.list.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[.](#forward.list.overview-1.sentence-1)
Fast random access to list elements is not supported[.](#forward.list.overview-1.sentence-2)
[*Note [1](#forward.list.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[.](#forward.list.overview-1.sentence-3)
Features that would conflict with
that goal have been omitted[.](#forward.list.overview-1.sentence-4)
— *end note*]
[2](#forward.list.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.2Container requirements")),
except that the size() member function is not provided andoperator== has linear complexity[.](#forward.list.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.5Allocator-aware containers"))[.](#forward.list.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.4Sequence containers"))[.](#forward.list.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[.](#forward.list.overview-2.sentence-4)
[3](#forward.list.overview-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6986)
[*Note [2](#forward.list.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[.](#forward.list.overview-3.sentence-1)
For this reason, erase_after and splice_after take fully-open ranges, not semi-open ranges[.](#forward.list.overview-3.sentence-2)
— *end note*]
[4](#forward.list.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.1General"))[.](#forward.list.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.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")// [[forward.list.cons]](#forward.list.cons "23.3.7.2Constructors, 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.1Introduction[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.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; // [[forward.list.iter]](#forward.list.iter "23.3.7.3Iterators"), 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]](#forward.list.access "23.3.7.4Element access"), element accessconstexpr reference front(); constexpr const_reference front() const; // [[forward.list.modifiers]](#forward.list.modifiers "23.3.7.5Modifiers"), 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.1Introduction[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.1Introduction[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]](#forward.list.ops "23.3.7.6Operations"), 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.6Other 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](#forward.list.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.2Allocator completeness requirements[allocator.requirements.completeness]")[.](#forward.list.overview-5.sentence-1)
T shall be complete before any member of the resulting specialization
of forward_list is referenced[.](#forward.list.overview-5.sentence-2)
#### [23.3.7.2](#forward.list.cons) Constructors, copy, and assignment [[forward.list.cons]](forward.list.cons)
[🔗](#lib:forward_list,constructor)
`constexpr explicit forward_list(const Allocator&);
`
[1](#forward.list.cons-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7146)
*Effects*: Constructs an empty forward_list object using the specified allocator[.](#forward.list.cons-1.sentence-1)
[2](#forward.list.cons-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7150)
*Complexity*: Constant[.](#forward.list.cons-2.sentence-1)
[🔗](#lib:forward_list,constructor_)
`constexpr explicit forward_list(size_type n, const Allocator& = Allocator());
`
[3](#forward.list.cons-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7161)
*Preconditions*: T is *Cpp17DefaultInsertable* into forward_list[.](#forward.list.cons-3.sentence-1)
[4](#forward.list.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[.](#forward.list.cons-4.sentence-1)
[5](#forward.list.cons-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7170)
*Complexity*: Linear in n[.](#forward.list.cons-5.sentence-1)
[🔗](#lib:forward_list,constructor__)
`constexpr forward_list(size_type n, const T& value, const Allocator& = Allocator());
`
[6](#forward.list.cons-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7181)
*Preconditions*: T is *Cpp17CopyInsertable* into forward_list[.](#forward.list.cons-6.sentence-1)
[7](#forward.list.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[.](#forward.list.cons-7.sentence-1)
[8](#forward.list.cons-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7189)
*Complexity*: Linear in n[.](#forward.list.cons-8.sentence-1)
[🔗](#lib:forward_list,constructor___)
`template<class InputIterator>
constexpr forward_list(InputIterator first, InputIterator last, const Allocator& = Allocator());
`
[9](#forward.list.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)[.](#forward.list.cons-9.sentence-1)
[10](#forward.list.cons-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7205)
*Complexity*: Linear in distance(first, last)[.](#forward.list.cons-10.sentence-1)
[🔗](#lib:forward_list,constructor____)
`template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1Introduction[container.intro.reqmts]")<T> R>
constexpr forward_list(from_range_t, R&& rg, const Allocator& = Allocator());
`
[11](#forward.list.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[.](#forward.list.cons-11.sentence-1)
[12](#forward.list.cons-12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7222)
*Complexity*: Linear in ranges::distance(rg)[.](#forward.list.cons-12.sentence-1)
#### [23.3.7.3](#forward.list.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](#forward.list.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()[.](#forward.list.iter-1.sentence-1)
[2](#forward.list.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()[.](#forward.list.iter-2.sentence-1)
[3](#forward.list.iter-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7248)
*Remarks*: before_begin() == end() shall equal false[.](#forward.list.iter-3.sentence-1)
#### [23.3.7.4](#forward.list.access) Element access [[forward.list.access]](forward.list.access)
[🔗](#lib:front,forward_list)
`constexpr reference front();
constexpr const_reference front() const;
`
[1](#forward.list.access-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7262)
*Returns*: *begin()
#### [23.3.7.5](#forward.list.modifiers) Modifiers [[forward.list.modifiers]](forward.list.modifiers)
[1](#forward.list.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[.](#forward.list.modifiers-1.sentence-1)
If an exception is thrown by any of these member functions
there is no effect on the container[.](#forward.list.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[.](#forward.list.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[.](#forward.list.modifiers-1.sentence-4)
[🔗](#lib:emplace_front,forward_list)
`template<class... Args> constexpr reference emplace_front(Args&&... args);
`
[2](#forward.list.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[.](#forward.list.modifiers-2.sentence-1)
[🔗](#lib:push_front,forward_list)
`constexpr void push_front(const T& x);
constexpr void push_front(T&& x);
`
[3](#forward.list.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[.](#forward.list.modifiers-3.sentence-1)
[🔗](#lib:prepend_range,forward_list)
`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);
`
[4](#forward.list.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[.](#forward.list.modifiers-4.sentence-1)
[*Note [1](#forward.list.modifiers-note-1)*:
The order of elements is not reversed[.](#forward.list.modifiers-4.sentence-2)
— *end note*]
[🔗](#lib:pop,forward_list)
`constexpr void pop_front();
`
[5](#forward.list.modifiers-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7327)
*Effects*: As if by erase_after(before_begin())[.](#forward.list.modifiers-5.sentence-1)
[🔗](#lib:insert_after,forward_list)
`constexpr iterator insert_after(const_iterator position, const T& x);
`
[6](#forward.list.modifiers-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7338)
*Preconditions*: T is *Cpp17CopyInsertable* into forward_list[.](#forward.list.modifiers-6.sentence-1)
position is before_begin() or is a dereferenceable
iterator in the range [begin(), end())[.](#forward.list.modifiers-6.sentence-2)
[7](#forward.list.modifiers-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7344)
*Effects*: Inserts a copy of x after position[.](#forward.list.modifiers-7.sentence-1)
[8](#forward.list.modifiers-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7348)
*Returns*: An iterator pointing to the copy of x[.](#forward.list.modifiers-8.sentence-1)
[🔗](#lib:insert_after,forward_list_)
`constexpr iterator insert_after(const_iterator position, T&& x);
`
[9](#forward.list.modifiers-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7359)
*Preconditions*: T is *Cpp17MoveInsertable* into forward_list[.](#forward.list.modifiers-9.sentence-1)
position is before_begin() or is a dereferenceable
iterator in the range [begin(), end())[.](#forward.list.modifiers-9.sentence-2)
[10](#forward.list.modifiers-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7365)
*Effects*: Inserts a copy of x after position[.](#forward.list.modifiers-10.sentence-1)
[11](#forward.list.modifiers-11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7369)
*Returns*: An iterator pointing to the copy of x[.](#forward.list.modifiers-11.sentence-1)
[🔗](#lib:insert_after,forward_list__)
`constexpr iterator insert_after(const_iterator position, size_type n, const T& x);
`
[12](#forward.list.modifiers-12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7380)
*Preconditions*: T is *Cpp17CopyInsertable* into forward_list[.](#forward.list.modifiers-12.sentence-1)
position is before_begin() or is a dereferenceable
iterator in the range [begin(), end())[.](#forward.list.modifiers-12.sentence-2)
[13](#forward.list.modifiers-13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7386)
*Effects*: Inserts n copies of x after position[.](#forward.list.modifiers-13.sentence-1)
[14](#forward.list.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[.](#forward.list.modifiers-14.sentence-1)
[🔗](#lib:insert_after,forward_list___)
`template<class InputIterator>
constexpr iterator insert_after(const_iterator position,
InputIterator first, InputIterator last);
`
[15](#forward.list.modifiers-15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7404)
*Preconditions*: T is *Cpp17EmplaceConstructible* into forward_list from *first[.](#forward.list.modifiers-15.sentence-1)
position is before_begin() or is a dereferenceable
iterator in the range [begin(), end())[.](#forward.list.modifiers-15.sentence-2)
Neither first nor last are iterators in *this[.](#forward.list.modifiers-15.sentence-3)
[16](#forward.list.modifiers-16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7412)
*Effects*: Inserts copies of elements in [first, last) after position[.](#forward.list.modifiers-16.sentence-1)
[17](#forward.list.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[.](#forward.list.modifiers-17.sentence-1)
[🔗](#lib:insert_range_after,forward_list)
`template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1Introduction[container.intro.reqmts]")<T> R>
constexpr iterator insert_range_after(const_iterator position, R&& rg);
`
[18](#forward.list.modifiers-18)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7429)
*Preconditions*: T is *Cpp17EmplaceConstructible* into forward_list from *ranges::begin(rg)[.](#forward.list.modifiers-18.sentence-1)
position is before_begin() or
is a dereferenceable iterator in the range [begin(), end())[.](#forward.list.modifiers-18.sentence-2)
rg and *this do not overlap[.](#forward.list.modifiers-18.sentence-3)
[19](#forward.list.modifiers-19)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7437)
*Effects*: Inserts copies of elements in the range rg after position[.](#forward.list.modifiers-19.sentence-1)
[20](#forward.list.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[.](#forward.list.modifiers-20.sentence-1)
[🔗](#lib:insert_after,forward_list____)
`constexpr iterator insert_after(const_iterator position, initializer_list<T> il);
`
[21](#forward.list.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](#forward.list.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)...[.](#forward.list.modifiers-22.sentence-1)
position is before_begin() or is a dereferenceable
iterator in the range [begin(), end())[.](#forward.list.modifiers-22.sentence-2)
[23](#forward.list.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[.](#forward.list.modifiers-23.sentence-1)
[24](#forward.list.modifiers-24)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7478)
*Returns*: An iterator pointing to the new object[.](#forward.list.modifiers-24.sentence-1)
[🔗](#lib:erase_after,forward_list)
`constexpr iterator erase_after(const_iterator position);
`
[25](#forward.list.modifiers-25)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7489)
*Preconditions*: The iterator following position is dereferenceable[.](#forward.list.modifiers-25.sentence-1)
[26](#forward.list.modifiers-26)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7493)
*Effects*: Erases the element pointed to by the iterator following position[.](#forward.list.modifiers-26.sentence-1)
[27](#forward.list.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[.](#forward.list.modifiers-27.sentence-1)
[28](#forward.list.modifiers-28)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7502)
*Throws*: Nothing[.](#forward.list.modifiers-28.sentence-1)
[🔗](#forward.list.modifiers-itemdecl:13)
`constexpr iterator erase_after(const_iterator position, const_iterator last);
`
[29](#forward.list.modifiers-29)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7512)
*Preconditions*: All iterators in the range (position, last) are dereferenceable[.](#forward.list.modifiers-29.sentence-1)
[30](#forward.list.modifiers-30)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7516)
*Effects*: Erases the elements in the range (position, last)[.](#forward.list.modifiers-30.sentence-1)
[31](#forward.list.modifiers-31)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7520)
*Returns*: last[.](#forward.list.modifiers-31.sentence-1)
[32](#forward.list.modifiers-32)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7524)
*Throws*: Nothing[.](#forward.list.modifiers-32.sentence-1)
[🔗](#lib:resize,forward_list)
`constexpr void resize(size_type sz);
`
[33](#forward.list.modifiers-33)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7535)
*Preconditions*: T is *Cpp17DefaultInsertable* into forward_list[.](#forward.list.modifiers-33.sentence-1)
[34](#forward.list.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[.](#forward.list.modifiers-34.sentence-1)
Otherwise, inserts sz - distance(begin(), end()) default-inserted
elements at the end of the list[.](#forward.list.modifiers-34.sentence-2)
[🔗](#forward.list.modifiers-itemdecl:15)
`constexpr void resize(size_type sz, const value_type& c);
`
[35](#forward.list.modifiers-35)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7551)
*Preconditions*: T is *Cpp17CopyInsertable* into forward_list[.](#forward.list.modifiers-35.sentence-1)
[36](#forward.list.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[.](#forward.list.modifiers-36.sentence-1)
Otherwise, inserts sz - distance(begin(), end()) copies of c at the end of the list[.](#forward.list.modifiers-36.sentence-2)
[🔗](#lib:clear,forward_list)
`constexpr void clear() noexcept;
`
[37](#forward.list.modifiers-37)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7569)
*Effects*: Erases all elements in the range [begin(), end())[.](#forward.list.modifiers-37.sentence-1)
[38](#forward.list.modifiers-38)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7573)
*Remarks*: Does not invalidate past-the-end iterators[.](#forward.list.modifiers-38.sentence-1)
#### [23.3.7.6](#forward.list.ops) Operations [[forward.list.ops]](forward.list.ops)
[1](#forward.list.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.2Algorithms requirements")[.](#forward.list.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)[.](#forward.list.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[.](#forward.list.ops-1.sentence-3)
For merge and sort,
the definitions and requirements in [[alg.sorting]](alg.sorting "26.8Sorting and related operations") apply[.](#forward.list.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](#forward.list.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())[.](#forward.list.ops-2.sentence-1)
get_allocator() == x.get_allocator() is true[.](#forward.list.ops-2.sentence-2)
addressof(x) != this is true[.](#forward.list.ops-2.sentence-3)
[3](#forward.list.ops-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7608)
*Effects*: Inserts the contents of x afterposition, and x becomes empty[.](#forward.list.ops-3.sentence-1)
Pointers and references to the moved
elements of x now refer to those same elements but as members of *this[.](#forward.list.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[.](#forward.list.ops-3.sentence-3)
[4](#forward.list.ops-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7616)
*Throws*: Nothing[.](#forward.list.ops-4.sentence-1)
[5](#forward.list.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](#forward.list.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())[.](#forward.list.ops-6.sentence-1)
The iterator following i is a dereferenceable iterator in x[.](#forward.list.ops-6.sentence-2)
get_allocator() == x.get_allocator() is true[.](#forward.list.ops-6.sentence-3)
[7](#forward.list.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[.](#forward.list.ops-7.sentence-1)
The result is unchanged if position == i or position == ++i[.](#forward.list.ops-7.sentence-2)
Pointers
and references to *++i continue to refer to the same element but as a member of*this[.](#forward.list.ops-7.sentence-3)
Iterators to *++i continue to refer to
the same element, but now behave as iterators into *this, not into x[.](#forward.list.ops-7.sentence-4)
[8](#forward.list.ops-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7648)
*Throws*: Nothing[.](#forward.list.ops-8.sentence-1)
[9](#forward.list.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](#forward.list.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())[.](#forward.list.ops-10.sentence-1)
(first, last) is a
valid range in x, and all iterators in the range (first, last) are
dereferenceable[.](#forward.list.ops-10.sentence-2)
position is not an iterator in the range (first, last)[.](#forward.list.ops-10.sentence-3)
get_allocator() == x.get_allocator() is true[.](#forward.list.ops-10.sentence-4)
[11](#forward.list.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[.](#forward.list.ops-11.sentence-1)
Pointers and references to the moved elements ofx now refer to those same elements but as members of *this[.](#forward.list.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[.](#forward.list.ops-11.sentence-3)
[12](#forward.list.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](#forward.list.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())[.](#forward.list.ops-13.sentence-1)
Invalidates only the iterators and references to the erased elements[.](#forward.list.ops-13.sentence-2)
[14](#forward.list.ops-14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7702)
*Returns*: The number of elements erased[.](#forward.list.ops-14.sentence-1)
[15](#forward.list.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[.](#forward.list.ops-15.sentence-1)
[16](#forward.list.ops-16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7711)
*Complexity*: Exactly distance(begin(), end()) applications of the corresponding
predicate[.](#forward.list.ops-16.sentence-1)
[17](#forward.list.ops-17)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7716)
*Remarks*: [Stable](algorithm.stable "16.4.6.8Requirements for stable algorithms[algorithm.stable]")[.](#forward.list.ops-17.sentence-1)
[🔗](#lib:unique,forward_list)
`constexpr size_type unique();
template<class BinaryPredicate> constexpr size_type unique(BinaryPredicate binary_pred);
`
[18](#forward.list.ops-18)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7728)
Let binary_pred be equal_to<>{} for the first overload[.](#forward.list.ops-18.sentence-1)
[19](#forward.list.ops-19)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7731)
*Preconditions*: binary_pred is an equivalence relation[.](#forward.list.ops-19.sentence-1)
[20](#forward.list.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[.](#forward.list.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[.](#forward.list.ops-20.sentence-2)
Invalidates only the iterators and references to the erased elements[.](#forward.list.ops-20.sentence-3)
[21](#forward.list.ops-21)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7744)
*Returns*: The number of elements erased[.](#forward.list.ops-21.sentence-1)
[22](#forward.list.ops-22)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7748)
*Throws*: Nothing unless an exception is thrown by the predicate[.](#forward.list.ops-22.sentence-1)
[23](#forward.list.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[.](#forward.list.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](#forward.list.ops-24)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7769)
Let comp be less<> for the first two overloads[.](#forward.list.ops-24.sentence-1)
[25](#forward.list.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[.](#forward.list.ops-25.sentence-1)
[26](#forward.list.ops-26)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7778)
*Effects*: If addressof(x) == this, there are no effects[.](#forward.list.ops-26.sentence-1)
Otherwise, merges
the two sorted ranges [begin(), end()) and [x.begin(), x.end())[.](#forward.list.ops-26.sentence-2)
The result is a range
that is sorted with respect to the comparator comp[.](#forward.list.ops-26.sentence-3)
Pointers and references to the moved elements of x now refer to those same elements
but as members of *this[.](#forward.list.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[.](#forward.list.ops-26.sentence-5)
[27](#forward.list.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[.](#forward.list.ops-27.sentence-1)
[28](#forward.list.ops-28)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7796)
*Remarks*: Stable ([[algorithm.stable]](algorithm.stable "16.4.6.8Requirements for stable algorithms"))[.](#forward.list.ops-28.sentence-1)
If addressof(x) != this, x is empty after the merge[.](#forward.list.ops-28.sentence-2)
No elements are copied by this operation[.](#forward.list.ops-28.sentence-3)
If an exception is thrown other than by a comparison, there are no effects[.](#forward.list.ops-28.sentence-4)
[🔗](#lib:sort,forward_list)
`constexpr void sort();
template<class Compare> constexpr void sort(Compare comp);
`
[29](#forward.list.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[.](#forward.list.ops-29.sentence-1)
If an exception is thrown, the order of the elements in *this is unspecified[.](#forward.list.ops-29.sentence-2)
Does not affect the validity of iterators and references[.](#forward.list.ops-29.sentence-3)
[30](#forward.list.ops-30)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7817)
*Complexity*: Approximately NlogN comparisons, where N is distance(begin(), end())[.](#forward.list.ops-30.sentence-1)
[31](#forward.list.ops-31)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7821)
*Remarks*: [Stable](algorithm.stable "16.4.6.8Requirements for stable algorithms[algorithm.stable]")[.](#forward.list.ops-31.sentence-1)
[🔗](#lib:reverse,forward_list)
`constexpr void reverse() noexcept;
`
[32](#forward.list.ops-32)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7832)
*Effects*: Reverses the order of the elements in the list[.](#forward.list.ops-32.sentence-1)
Does not affect the validity of iterators and references[.](#forward.list.ops-32.sentence-2)
[33](#forward.list.ops-33)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7837)
*Complexity*: Linear time[.](#forward.list.ops-33.sentence-1)
#### [23.3.7.7](#forward.list.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](#forward.list.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](#forward.list.erasure-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7868)
*Effects*: Equivalent to: return c.remove_if(pred);
### [23.3.8](#hive.syn) Header <hive> synopsis [[hive.syn]](hive.syn)
[🔗](#header:%3chive%3e)
#include <initializer_list> // see [[initializer.list.syn]](initializer.list.syn "17.11.2Header <initializer_­list> synopsis")#include <compare> // see [[compare.syn]](compare.syn "17.12.1Header <compare> synopsis")namespace std {struct [hive_limits](#lib:hive_limits "23.3.8Header <hive> synopsis[hive.syn]") { size_t [min](#lib:hive_limits,min "23.3.8Header <hive> synopsis[hive.syn]");
size_t [max](#lib:hive_limits,max "23.3.8Header <hive> synopsis[hive.syn]"); constexpr hive_limits(size_t minimum, size_t maximum) noexcept: min(minimum), max(maximum) {}}; // [[hive]](#hive "23.3.9Class template hive"), class template hivetemplate<class T, class Allocator = allocator<T>> class hive; template<class T, class Allocator>void swap(hive<T, Allocator>& x, hive<T, Allocator>& y)noexcept(noexcept(x.swap(y))); template<class T, class Allocator, class U = T>typename hive<T, Allocator>::size_type
erase(hive<T, Allocator>& c, const U& value); template<class T, class Allocator, class Predicate>typename hive<T, Allocator>::size_type
erase_if(hive<T, Allocator>& c, Predicate pred); namespace pmr {template<class T>using hive = std::hive<T, polymorphic_allocator<T>>; }}
### [23.3.9](#hive) Class template hive [[hive]](hive)
#### [23.3.9.1](#hive.overview) Overview [[hive.overview]](hive.overview)
[1](#hive.overview-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7915)
A hive is a type of sequence container
that provides constant-time insertion and erasure operations[.](#hive.overview-1.sentence-1)
Storage is automatically managed in multiple memory blocks,
referred to as [*element blocks*](#def:element_block "23.3.9.1Overview[hive.overview]")[.](#hive.overview-1.sentence-2)
Insertion position is determined by the container, and insertion
may re-use the memory locations of erased elements[.](#hive.overview-1.sentence-3)
[2](#hive.overview-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7923)
Element blocks which contain elements are referred to
as [*active blocks*](#def:block,active "23.3.9.1Overview[hive.overview]"),
those which do not are referred to as [*reserved blocks*](#def:block,reserved "23.3.9.1Overview[hive.overview]")[.](#hive.overview-2.sentence-1)
Active blocks which become empty of elements are
either deallocated or become reserved blocks[.](#hive.overview-2.sentence-2)
Reserved blocks become active blocks when they are used to store elements[.](#hive.overview-2.sentence-3)
A user can create additional reserved blocks by calling reserve[.](#hive.overview-2.sentence-4)
[3](#hive.overview-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7932)
Erasures use unspecified techniques of constant time complexity
to identify the memory locations of erased elements,
which are subsequently skipped during iteration,
as opposed to relocating subsequent elements during erasure[.](#hive.overview-3.sentence-1)
[4](#hive.overview-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7938)
Active block capacities have
an implementation-defined growth factor
(which need not be integral),
for example a new active block's capacity could be equal to
the summed capacities of the pre-existing active blocks[.](#hive.overview-4.sentence-1)
[5](#hive.overview-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7945)
Limits can be placed on
both the minimum and maximum element capacities of element blocks,
both by users and implementations[.](#hive.overview-5.sentence-1)
- [(5.1)](#hive.overview-5.1)
The minimum limit shall be no larger than the maximum limit[.](#hive.overview-5.1.sentence-1)
- [(5.2)](#hive.overview-5.2)
When limits are not specified by a user during construction,
the implementation's default limits are used[.](#hive.overview-5.2.sentence-1)
- [(5.3)](#hive.overview-5.3)
The default limits of an implementation are not guaranteed to be the same as
the minimum and maximum possible capacities
for an implementation's element blocks[.](#hive.overview-5.3.sentence-1)
[*Note [1](#hive.overview-note-1)*:
To allow latitude for
both implementation-specific and user-directed optimization[.](#hive.overview-5.3.sentence-2)
— *end note*]
The latter are defined as hard limits[.](#hive.overview-5.3.sentence-3)
The maximum hard limit shall be no larger thanstd::allocator_traits<Allocator>::max_size()[.](#hive.overview-5.3.sentence-4)
- [(5.4)](#hive.overview-5.4)
If user-specified limits are not within hard limits, or
if the specified minimum limit is greater than the specified maximum limit,
the behavior is undefined[.](#hive.overview-5.4.sentence-1)
- [(5.5)](#hive.overview-5.5)
An element block is said to be [*within the bounds*](#def:element_block,bounds "23.3.9.1Overview[hive.overview]") of a pair of minimum/maximum limits
when its capacity is greater-or-equal-to the minimum limit and
less-than-or-equal-to the maximum limit[.](#hive.overview-5.5.sentence-1)
[6](#hive.overview-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7977)
A hive conforms to
the requirements for containers ([[container.reqmts]](container.reqmts "23.2.2.2Container requirements")),
with the exception of operators == and !=[.](#hive.overview-6.sentence-1)
A hive also meets the 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
some of the requirements of a sequence container ([[sequence.reqmts]](sequence.reqmts "23.2.4Sequence containers"))[.](#hive.overview-6.sentence-2)
Descriptions are provided here only for operations on hive that are not described in that table or for operations
where there is additional semantic information[.](#hive.overview-6.sentence-3)
[7](#hive.overview-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L7989)
The iterators of hive meet
the *Cpp17BidirectionalIterator* requirements
but also model [three_way_comparable](cmp.concept#concept:three_way_comparable "17.12.4Concept three_­way_­comparable[cmp.concept]")<strong_ordering>[.](#hive.overview-7.sentence-1)
namespace std {template<class T, class Allocator = allocator<T>>class [hive](#lib:hive "23.3.9.1Overview[hive.overview]") {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>; // see [[container.requirements]](container.requirements "23.2Requirements")using const_reverse_iterator = std::reverse_iterator<const_iterator>; // see [[container.requirements]](container.requirements "23.2Requirements")// [[hive.cons]](#hive.cons "23.3.9.2Constructors, copy, and assignment"), construct/copy/destroyconstexpr hive() noexcept(noexcept(Allocator())) : hive(Allocator()) {}constexpr explicit hive(const Allocator&) noexcept; constexpr explicit hive(hive_limits block_limits) : hive(block_limits, Allocator()) {}constexpr hive(hive_limits block_limits, const Allocator&); explicit hive(size_type n, const Allocator& = Allocator());
hive(size_type n, hive_limits block_limits, const Allocator& = Allocator());
hive(size_type n, const T& value, const Allocator& = Allocator());
hive(size_type n, const T& value, hive_limits block_limits, const Allocator& = Allocator()); template<class InputIterator> hive(InputIterator first, InputIterator last, const Allocator& = Allocator()); template<class InputIterator> hive(InputIterator first, InputIterator last, hive_limits block_limits, const Allocator& = Allocator()); template<[*container-compatible-range*](container.intro.reqmts#concept:container-compatible-range "23.2.2.1Introduction[container.intro.reqmts]")<T> R> hive(from_range_t, R&& rg, const Allocator& = Allocator()); template<[*container-compatible-range*](container.intro.reqmts#concept:container-compatible-range "23.2.2.1Introduction[container.intro.reqmts]")<T> R> hive(from_range_t, R&& rg, hive_limits block_limits, const Allocator& = Allocator());
hive(const hive& x);
hive(hive&&) noexcept;
hive(const hive& x, const type_identity_t<Allocator>& alloc);
hive(hive&&, const type_identity_t<Allocator>& alloc);
hive(initializer_list<T> il, const Allocator& = Allocator());
hive(initializer_list<T> il, hive_limits block_limits, const Allocator& = Allocator()); ~hive();
hive& operator=(const hive& x);
hive& operator=(hive&& x) noexcept(*see below*);
hive& operator=(initializer_list<T>); template<class InputIterator>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>void assign_range(R&& rg); void assign(size_type n, const T& t); void assign(initializer_list<T>);
allocator_type get_allocator() const noexcept; // iterators iterator begin() noexcept;
const_iterator begin() const noexcept;
iterator end() noexcept;
const_iterator end() const noexcept;
reverse_iterator rbegin() noexcept;
const_reverse_iterator rbegin() const noexcept;
reverse_iterator rend() noexcept;
const_reverse_iterator rend() const noexcept;
const_iterator cbegin() const noexcept;
const_iterator cend() const noexcept;
const_reverse_iterator crbegin() const noexcept;
const_reverse_iterator crend() const noexcept; // [[hive.capacity]](#hive.capacity "23.3.9.3Capacity"), capacitybool empty() const noexcept;
size_type size() const noexcept;
size_type max_size() const noexcept;
size_type capacity() const noexcept; void reserve(size_type n); void shrink_to_fit(); void trim_capacity() noexcept; void trim_capacity(size_type n) noexcept; constexpr hive_limits block_capacity_limits() const noexcept; static constexpr hive_limits block_capacity_default_limits() noexcept; static constexpr hive_limits block_capacity_hard_limits() noexcept; void reshape(hive_limits block_limits); // [[hive.modifiers]](#hive.modifiers "23.3.9.4Modifiers"), modifierstemplate<class... Args> iterator emplace(Args&&... args); template<class... Args> iterator emplace_hint(const_iterator hint, Args&&... args);
iterator insert(const T& x);
iterator insert(T&& x);
iterator insert(const_iterator hint, const T& x);
iterator insert(const_iterator hint, T&& x); void insert(initializer_list<T> il); template<[*container-compatible-range*](container.intro.reqmts#concept:container-compatible-range "23.2.2.1Introduction[container.intro.reqmts]")<T> R>void insert_range(R&& rg); template<class InputIterator>void insert(InputIterator first, InputIterator last); void insert(size_type n, const T& x);
iterator erase(const_iterator position);
iterator erase(const_iterator first, const_iterator last); void swap(hive&) noexcept(*see below*); void clear() noexcept; // [[hive.operations]](#hive.operations "23.3.9.5Operations"), hive operationsvoid splice(hive& x); void splice(hive&& x); template<class BinaryPredicate = equal_to<T>> size_type unique(BinaryPredicate binary_pred = BinaryPredicate()); template<class Compare = less<T>>void sort(Compare comp = Compare());
iterator get_iterator(const_pointer p) noexcept;
const_iterator get_iterator(const_pointer p) const noexcept; private: hive_limits *current-limits* = *implementation-defined*; // *exposition only*}; template<class InputIterator, class Allocator = allocator<*iter-value-type*<InputIterator>>> hive(InputIterator, InputIterator, Allocator = Allocator())-> hive<*iter-value-type*<InputIterator>, Allocator>; template<class InputIterator, class Allocator = allocator<*iter-value-type*<InputIterator>>> hive(InputIterator, InputIterator, hive_limits, Allocator = Allocator())-> hive<*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>>> hive(from_range_t, R&&, Allocator = Allocator())-> hive<ranges::range_value_t<R>, 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>>> hive(from_range_t, R&&, hive_limits, Allocator = Allocator())-> hive<ranges::range_value_t<R>, Allocator>;}
#### [23.3.9.2](#hive.cons) Constructors, copy, and assignment [[hive.cons]](hive.cons)
[🔗](#lib:hive,constructor)
`constexpr explicit hive(const Allocator&) noexcept;
`
[1](#hive.cons-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8139)
*Effects*: Constructs an empty hive, using the specified allocator[.](#hive.cons-1.sentence-1)
[2](#hive.cons-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8143)
*Complexity*: Constant[.](#hive.cons-2.sentence-1)
[🔗](#lib:hive,constructor_)
`constexpr hive(hive_limits block_limits, const Allocator&);
`
[3](#hive.cons-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8154)
*Effects*: Constructs an empty hive, using the specified allocator[.](#hive.cons-3.sentence-1)
Initializes *current-limits* with block_limits[.](#hive.cons-3.sentence-2)
[4](#hive.cons-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8159)
*Complexity*: Constant[.](#hive.cons-4.sentence-1)
[🔗](#lib:hive,constructor__)
`explicit hive(size_type n, const Allocator& = Allocator());
hive(size_type n, hive_limits block_limits, const Allocator& = Allocator());
`
[5](#hive.cons-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8171)
*Preconditions*: T is *Cpp17DefaultInsertable* into hive[.](#hive.cons-5.sentence-1)
[6](#hive.cons-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8175)
*Effects*: Constructs a hive with n default-inserted elements,
using the specified allocator[.](#hive.cons-6.sentence-1)
If the second overload is called,
also initializes *current-limits* with block_limits[.](#hive.cons-6.sentence-2)
[7](#hive.cons-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8182)
*Complexity*: Linear in n[.](#hive.cons-7.sentence-1)
[🔗](#lib:hive,constructor___)
`hive(size_type n, const T& value, const Allocator& = Allocator());
hive(size_type n, const T& value, hive_limits block_limits, const Allocator& = Allocator());
`
[8](#hive.cons-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8194)
*Preconditions*: T is *Cpp17CopyInsertable* into hive[.](#hive.cons-8.sentence-1)
[9](#hive.cons-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8198)
*Effects*: Constructs a hive with n copies of value,
using the specified allocator[.](#hive.cons-9.sentence-1)
If the second overload is called,
also initializes *current-limits* with block_limits[.](#hive.cons-9.sentence-2)
[10](#hive.cons-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8205)
*Complexity*: Linear in n[.](#hive.cons-10.sentence-1)
[🔗](#lib:hive,constructor____)
`template<class InputIterator>
hive(InputIterator first, InputIterator last, const Allocator& = Allocator());
template<class InputIterator>
hive(InputIterator first, InputIterator last, hive_limits block_limits,
const Allocator& = Allocator());
`
[11](#hive.cons-11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8220)
*Effects*: Constructs a hive equal to the range [first, last),
using the specified allocator[.](#hive.cons-11.sentence-1)
If the second overload is called,
also initializes *current-limits* with block_limits[.](#hive.cons-11.sentence-2)
[12](#hive.cons-12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8227)
*Complexity*: Linear in distance(first, last)[.](#hive.cons-12.sentence-1)
[🔗](#lib:hive,constructor_____)
`template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1Introduction[container.intro.reqmts]")<T> R>
hive(from_range_t, R&& rg, const Allocator& = Allocator());
template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1Introduction[container.intro.reqmts]")<T> R>
hive(from_range_t, R&& rg, hive_limits block_limits, const Allocator& = Allocator());
`
[13](#hive.cons-13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8241)
*Effects*: Constructs a hive object with the elements of the range rg,
using the specified allocator[.](#hive.cons-13.sentence-1)
If the second overload is called,
also initializes *current-limits* with block_limits[.](#hive.cons-13.sentence-2)
[14](#hive.cons-14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8248)
*Complexity*: Linear in ranges::distance(rg)[.](#hive.cons-14.sentence-1)
[🔗](#lib:hive,constructor______)
`hive(const hive& x);
hive(const hive& x, const type_identity_t<Allocator>& alloc);
`
[15](#hive.cons-15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8260)
*Preconditions*: T is *Cpp17CopyInsertable* into hive[.](#hive.cons-15.sentence-1)
[16](#hive.cons-16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8264)
*Effects*: Constructs a hive object with the elements of x[.](#hive.cons-16.sentence-1)
If the second overload is called, uses alloc[.](#hive.cons-16.sentence-2)
Initializes *current-limits* with x.*current-limits*[.](#hive.cons-16.sentence-3)
[17](#hive.cons-17)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8270)
*Complexity*: Linear in x.size()[.](#hive.cons-17.sentence-1)
[🔗](#lib:hive,constructor_______)
`hive(hive&& x) noexcept;
hive(hive&& x, const type_identity_t<Allocator>& alloc);
`
[18](#hive.cons-18)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8282)
*Preconditions*: For the second overload,
when allocator_traits<alloc>::is_always_equal::value is false,T meets the *Cpp17MoveInsertable* requirements[.](#hive.cons-18.sentence-1)
[19](#hive.cons-19)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8288)
*Effects*: When the first overload is called, or
the second overload is called andalloc == x.get_allocator() is true,*current-limits* is set to x.*current-limits* and
each element block is moved from x into *this[.](#hive.cons-19.sentence-1)
Pointers and references to the elements of x now refer to
those same elements but as members of *this[.](#hive.cons-19.sentence-2)
Iterators referring to the elements of x will continue to refer to their elements,
but they now behave as iterators into *this[.](#hive.cons-19.sentence-3)
If the second overload is called andalloc == x.get_allocator() is false,
each element in x is moved into *this[.](#hive.cons-19.sentence-4)
References, pointers and iterators referring to the elements of x, as well as the past-the-end iterator of x, are invalidated[.](#hive.cons-19.sentence-5)
[20](#hive.cons-20)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8306)
*Postconditions*: x.empty() is true[.](#hive.cons-20.sentence-1)
[21](#hive.cons-21)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8310)
*Complexity*: If the second overload is called andalloc == x.get_allocator() is false, linear in x.size()[.](#hive.cons-21.sentence-1)
Otherwise constant[.](#hive.cons-21.sentence-2)
[🔗](#lib:hive,constructor________)
`hive(initializer_list<T> il, const Allocator& = Allocator());
hive(initializer_list<T> il, hive_limits block_limits, const Allocator& = Allocator());
`
[22](#hive.cons-22)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8324)
*Preconditions*: T is *Cpp17CopyInsertable* into hive[.](#hive.cons-22.sentence-1)
[23](#hive.cons-23)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8328)
*Effects*: Constructs a hive object with the elements of il,
using the specified allocator[.](#hive.cons-23.sentence-1)
If the second overload is called,
also initializes *current-limits* with block_limits[.](#hive.cons-23.sentence-2)
[24](#hive.cons-24)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8335)
*Complexity*: Linear in il.size()[.](#hive.cons-24.sentence-1)
[🔗](#lib:operator=,hive)
`hive& operator=(const hive& x);
`
[25](#hive.cons-25)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8346)
*Preconditions*: T is *Cpp17CopyInsertable* into hive and*Cpp17CopyAssignable*[.](#hive.cons-25.sentence-1)
[26](#hive.cons-26)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8351)
*Effects*: All elements in *this are either copy-assigned to, or destroyed[.](#hive.cons-26.sentence-1)
All elements in x are copied into *this[.](#hive.cons-26.sentence-2)
[*Note [1](#hive.cons-note-1)*:
*current-limits* is unchanged[.](#hive.cons-26.sentence-3)
— *end note*]
[27](#hive.cons-27)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8359)
*Complexity*: Linear in size() + x.size()[.](#hive.cons-27.sentence-1)
[🔗](#lib:operator=,hive_)
`hive& operator=(hive&& x)
noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
allocator_traits<Allocator>::is_always_equal::value);
`
[28](#hive.cons-28)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8372)
*Preconditions*: When(allocator_traits<Allocator>::propagate_on_container_move_assignment::value || allocator_traits<Allocator>::is_always_equal::value) is false,T is *Cpp17MoveInsertable* into hive and*Cpp17MoveAssignable*[.](#hive.cons-28.sentence-1)
[29](#hive.cons-29)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8383)
*Effects*: Each element in *this is either move-assigned to, or destroyed[.](#hive.cons-29.sentence-1)
When(allocator_traits<Allocator>::propagate_on_container_move_assignment::value || get_allocator() == x.get_allocator()) is true,*current-limits* is set to x.*current-limits* and
each element block is moved from x into *this[.](#hive.cons-29.sentence-2)
Pointers and references to the elements of x now refer to those same elements but as members of *this[.](#hive.cons-29.sentence-3)
Iterators referring to the elements of x will continue to refer to their elements,
but they now behave as iterators into *this, not into x[.](#hive.cons-29.sentence-4)
When(allocator_traits<Allocator>::propagate_on_container_move_assignment::value || get_allocator() == x.get_allocator()) is false,
each element in x is moved into *this[.](#hive.cons-29.sentence-5)
References, pointers and iterators referring to the elements of x,
as well as the past-the-end iterator of x, are invalidated[.](#hive.cons-29.sentence-6)
[30](#hive.cons-30)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8410)
*Postconditions*: x.empty() is true[.](#hive.cons-30.sentence-1)
[31](#hive.cons-31)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8414)
*Complexity*: Linear in size()[.](#hive.cons-31.sentence-1)
If(allocator_traits<Allocator>::propagate_on_container_move_assignment::value || get_allocator() == x.get_allocator()) is false, also linear in x.size()[.](#hive.cons-31.sentence-2)
#### [23.3.9.3](#hive.capacity) Capacity [[hive.capacity]](hive.capacity)
[🔗](#lib:capacity,hive)
`size_type capacity() const noexcept;
`
[1](#hive.capacity-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8433)
*Returns*: The total number of elements that *this can hold
without requiring allocation of more element blocks[.](#hive.capacity-1.sentence-1)
[2](#hive.capacity-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8438)
*Complexity*: Constant[.](#hive.capacity-2.sentence-1)
[🔗](#lib:reserve,hive)
`void reserve(size_type n);
`
[3](#hive.capacity-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8449)
*Effects*: If n <= capacity() is true, there are no effects[.](#hive.capacity-3.sentence-1)
Otherwise increases capacity() by allocating reserved blocks[.](#hive.capacity-3.sentence-2)
[4](#hive.capacity-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8454)
*Postconditions*: capacity() >= n is true[.](#hive.capacity-4.sentence-1)
[5](#hive.capacity-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8458)
*Throws*: length_error if n > max_size(),
as well as any exceptions thrown by the allocator[.](#hive.capacity-5.sentence-1)
[6](#hive.capacity-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8463)
*Complexity*: It does not change the size of the sequence and
takes at most linear time in the number of reserved blocks allocated[.](#hive.capacity-6.sentence-1)
[7](#hive.capacity-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8468)
*Remarks*: All references, pointers, and iterators referring to elements in *this,
as well as the past-the-end iterator, remain valid[.](#hive.capacity-7.sentence-1)
[🔗](#lib:shrink_to_fit,hive)
`void shrink_to_fit();
`
[8](#hive.capacity-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8480)
*Preconditions*: T is *Cpp17MoveInsertable* into hive[.](#hive.capacity-8.sentence-1)
[9](#hive.capacity-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8484)
*Effects*: shrink_to_fit is a non-binding request
to reduce capacity() to be closer to size()[.](#hive.capacity-9.sentence-1)
[*Note [1](#hive.capacity-note-1)*:
The request is non-binding
to allow latitude for implementation-specific optimizations[.](#hive.capacity-9.sentence-2)
— *end note*]
It does not increase capacity(), but may reduce capacity()[.](#hive.capacity-9.sentence-3)
It may reallocate elements[.](#hive.capacity-9.sentence-4)
If capacity() is already equal to size(), there are no effects[.](#hive.capacity-9.sentence-5)
If an exception is thrown during allocation of a new element block,capacity() may be reduced and reallocation may occur[.](#hive.capacity-9.sentence-6)
Otherwise if an exception is thrown, the effects are unspecified[.](#hive.capacity-9.sentence-7)
[10](#hive.capacity-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8499)
*Complexity*: If reallocation happens, linear in the size of the sequence[.](#hive.capacity-10.sentence-1)
[11](#hive.capacity-11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8503)
*Remarks*: If reallocation happens,
the order of the elements in *this may change and
all references, pointers, and iterators
referring to the elements in *this,
as well as the past-the-end iterator, are invalidated[.](#hive.capacity-11.sentence-1)
[🔗](#lib:trim_capacity,hive)
`void trim_capacity() noexcept;
void trim_capacity(size_type n) noexcept;
`
[12](#hive.capacity-12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8519)
*Effects*: For the first overload, all reserved blocks are deallocated, andcapacity() is reduced accordingly[.](#hive.capacity-12.sentence-1)
For the second overload, capacity() is reduced to no less than n[.](#hive.capacity-12.sentence-2)
[13](#hive.capacity-13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8525)
*Complexity*: Linear in the number of reserved blocks deallocated[.](#hive.capacity-13.sentence-1)
[14](#hive.capacity-14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8529)
*Remarks*: All references, pointers, and iterators referring to elements in *this,
as well as the past-the-end iterator, remain valid[.](#hive.capacity-14.sentence-1)
[🔗](#lib:block_capacity_limits,hive)
`constexpr hive_limits block_capacity_limits() const noexcept;
`
[15](#hive.capacity-15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8541)
*Returns*: *current-limits*[.](#hive.capacity-15.sentence-1)
[16](#hive.capacity-16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8545)
*Complexity*: Constant[.](#hive.capacity-16.sentence-1)
[🔗](#lib:block_capacity_default_limits,hive)
`static constexpr hive_limits block_capacity_default_limits() noexcept;
`
[17](#hive.capacity-17)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8556)
*Returns*: A hive_limits struct
with the min and max members set to
the implementation's default limits[.](#hive.capacity-17.sentence-1)
[18](#hive.capacity-18)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8562)
*Complexity*: Constant[.](#hive.capacity-18.sentence-1)
[🔗](#lib:block_capacity_hard_limits,hive)
`static constexpr hive_limits block_capacity_hard_limits() noexcept;
`
[19](#hive.capacity-19)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8573)
*Returns*: A hive_limits struct
with the min and max members set to
the implementation's hard limits[.](#hive.capacity-19.sentence-1)
[20](#hive.capacity-20)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8579)
*Complexity*: Constant[.](#hive.capacity-20.sentence-1)
[🔗](#lib:reshape,hive)
`void reshape(hive_limits block_limits);
`
[21](#hive.capacity-21)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8590)
*Preconditions*: T is *Cpp17MoveInsertable* into hive[.](#hive.capacity-21.sentence-1)
[22](#hive.capacity-22)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8594)
*Effects*: For any active blocks not within the bounds of block_limits,
the elements within those active blocks are reallocated
to new or existing element blocks which are within the bounds[.](#hive.capacity-22.sentence-1)
Any element blocks not within the bounds of block_limits are deallocated[.](#hive.capacity-22.sentence-2)
If an exception is thrown during allocation of a new element block,capacity() may be reduced,
reallocation may occur, and*current-limits* may be assigned
a value other than block_limits[.](#hive.capacity-22.sentence-3)
Otherwise block_limits is assigned to *current-limits*[.](#hive.capacity-22.sentence-4)
If any other exception is thrown the effects are unspecified[.](#hive.capacity-22.sentence-5)
[23](#hive.capacity-23)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8609)
*Postconditions*: size() is unchanged[.](#hive.capacity-23.sentence-1)
[24](#hive.capacity-24)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8613)
*Complexity*: Linear in the number of element blocks in *this[.](#hive.capacity-24.sentence-1)
If reallocation happens, also linear in the number of elements reallocated[.](#hive.capacity-24.sentence-2)
[25](#hive.capacity-25)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8618)
*Remarks*: This operation may change capacity()[.](#hive.capacity-25.sentence-1)
If reallocation happens, the order of the elements in *this may change[.](#hive.capacity-25.sentence-2)
Reallocation invalidates all references, pointers, and iterators
referring to the elements in *this,
as well as the past-the-end iterator[.](#hive.capacity-25.sentence-3)
[*Note [2](#hive.capacity-note-2)*:
If no reallocation happens, they remain valid[.](#hive.capacity-25.sentence-4)
— *end note*]
#### [23.3.9.4](#hive.modifiers) Modifiers [[hive.modifiers]](hive.modifiers)
[🔗](#lib:emplace,hive)
`template<class... Args> iterator emplace(Args&&... args);
template<class... Args> iterator emplace_hint(const_iterator hint, Args&&... args);
`
[1](#hive.modifiers-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8639)
*Preconditions*: T is *Cpp17EmplaceConstructible* into hive from args[.](#hive.modifiers-1.sentence-1)
[2](#hive.modifiers-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8643)
*Effects*: Inserts an object of type T constructed with std::forward<Args>(args)...[.](#hive.modifiers-2.sentence-1)
The hint parameter is ignored[.](#hive.modifiers-2.sentence-2)
If an exception is thrown, there are no effects[.](#hive.modifiers-2.sentence-3)
[*Note [1](#hive.modifiers-note-1)*:
args can directly or indirectly refer to a value in *this[.](#hive.modifiers-2.sentence-4)
— *end note*]
[3](#hive.modifiers-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8653)
*Returns*: An iterator that points to the new element[.](#hive.modifiers-3.sentence-1)
[4](#hive.modifiers-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8657)
*Complexity*: Constant[.](#hive.modifiers-4.sentence-1)
Exactly one object of type T is constructed[.](#hive.modifiers-4.sentence-2)
[5](#hive.modifiers-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8661)
*Remarks*: Invalidates the past-the-end iterator[.](#hive.modifiers-5.sentence-1)
[🔗](#lib:insert,hive)
`iterator insert(const T& x);
iterator insert(const_iterator hint, const T& x);
iterator insert(T&& x);
iterator insert(const_iterator hint, T&& x);
`
[6](#hive.modifiers-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8675)
*Effects*: Equivalent to: return emplace(std::forward<decltype(x)>(x));
[*Note [2](#hive.modifiers-note-2)*:
The hint parameter is ignored[.](#hive.modifiers-6.sentence-1)
— *end note*]
[🔗](#lib:insert,hive_)
`void insert(initializer_list<T> rg);
template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1Introduction[container.intro.reqmts]")<T> R>
void insert_range(R&& rg);
`
[7](#hive.modifiers-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8691)
*Preconditions*: T is *Cpp17EmplaceInsertable* into hive from *ranges::begin(rg)[.](#hive.modifiers-7.sentence-1)
rg and *this do not overlap[.](#hive.modifiers-7.sentence-2)
[8](#hive.modifiers-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8697)
*Effects*: Inserts copies of elements in rg[.](#hive.modifiers-8.sentence-1)
Each iterator in the range rg is dereferenced exactly once[.](#hive.modifiers-8.sentence-2)
[9](#hive.modifiers-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8702)
*Complexity*: Linear in the number of elements inserted[.](#hive.modifiers-9.sentence-1)
Exactly one object of type T is constructed for each element inserted[.](#hive.modifiers-9.sentence-2)
[10](#hive.modifiers-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8707)
*Remarks*: If an element is inserted, invalidates the past-the-end iterator[.](#hive.modifiers-10.sentence-1)
[🔗](#lib:insert,hive__)
`void insert(size_type n, const T& x);
`
[11](#hive.modifiers-11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8718)
*Preconditions*: T is *Cpp17CopyInsertable* into hive[.](#hive.modifiers-11.sentence-1)
[12](#hive.modifiers-12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8722)
*Effects*: Inserts n copies of x[.](#hive.modifiers-12.sentence-1)
[13](#hive.modifiers-13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8726)
*Complexity*: Linear in n[.](#hive.modifiers-13.sentence-1)
Exactly one object of type T is constructed for each element inserted[.](#hive.modifiers-13.sentence-2)
[14](#hive.modifiers-14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8731)
*Remarks*: If an element is inserted, invalidates the past-the-end iterator[.](#hive.modifiers-14.sentence-1)
[🔗](#lib:insert,hive___)
`template<class InputIterator>
void insert(InputIterator first, InputIterator last);
`
[15](#hive.modifiers-15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8743)
*Effects*: Equivalent to insert_range(ranges::subrange(first, last))[.](#hive.modifiers-15.sentence-1)
[🔗](#lib:erase,hive)
`iterator erase(const_iterator position);
iterator erase(const_iterator first, const_iterator last);
`
[16](#hive.modifiers-16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8755)
*Complexity*: Linear in the number of elements erased[.](#hive.modifiers-16.sentence-1)
Additionally, if any active blocks become empty of elements
as a result of the function call,
at worst linear in the number of element blocks[.](#hive.modifiers-16.sentence-2)
[17](#hive.modifiers-17)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8762)
*Remarks*: Invalidates references, pointers and iterators
referring to the erased elements[.](#hive.modifiers-17.sentence-1)
An erase operation that erases the last element in *this also invalidates the past-the-end iterator[.](#hive.modifiers-17.sentence-2)
[🔗](#lib:swap,hive)
`void swap(hive& x)
noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value ||
allocator_traits<Allocator>::is_always_equal::value);
`
[18](#hive.modifiers-18)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8778)
*Effects*: Exchanges the contents, capacity(), and *current-limits* of *this with that of x[.](#hive.modifiers-18.sentence-1)
[19](#hive.modifiers-19)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8783)
*Complexity*: Constant[.](#hive.modifiers-19.sentence-1)
#### [23.3.9.5](#hive.operations) Operations [[hive.operations]](hive.operations)
[1](#hive.operations-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8790)
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")[.](#hive.operations-1.sentence-1)
The semantics of i + n and i - n,
where i is an iterator into the hive and n is an integer,
are the same as those of next(i, n) and prev(i, n), respectively[.](#hive.operations-1.sentence-2)
For sort, the definitions and requirements in [[alg.sorting]](alg.sorting "26.8Sorting and related operations") apply[.](#hive.operations-1.sentence-3)
[🔗](#lib:splice,hive)
`void splice(hive& x);
void splice(hive&& x);
`
[2](#hive.operations-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8807)
*Preconditions*: get_allocator() == x.get_allocator() is true[.](#hive.operations-2.sentence-1)
[3](#hive.operations-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8811)
*Effects*: If addressof(x) == this is true,
the behavior is erroneous and there are no effects[.](#hive.operations-3.sentence-1)
Otherwise, inserts the contents of x into *this andx becomes empty[.](#hive.operations-3.sentence-2)
Pointers and references to the moved elements of x now refer to those same elements but as members of *this[.](#hive.operations-3.sentence-3)
Iterators referring to the moved elements continue to refer to their elements,
but they now behave as iterators into *this, not into x[.](#hive.operations-3.sentence-4)
[4](#hive.operations-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8822)
*Throws*: length_error if any of x's active blocks
are not within the bounds of *current-limits*[.](#hive.operations-4.sentence-1)
[5](#hive.operations-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8827)
*Complexity*: Linear in the sum of
all element blocks in x plus all element blocks in *this[.](#hive.operations-5.sentence-1)
[6](#hive.operations-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8832)
*Remarks*: Reserved blocks in x are not transferred into *this[.](#hive.operations-6.sentence-1)
If addressof(x) == this is false,
invalidates the past-the-end iterator for both x and *this[.](#hive.operations-6.sentence-2)
[🔗](#lib:unique,hive)
`template<class BinaryPredicate = equal_to<T>>
size_type unique(BinaryPredicate binary_pred = BinaryPredicate());
`
[7](#hive.operations-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8846)
*Preconditions*: binary_pred is an equivalence relation[.](#hive.operations-7.sentence-1)
[8](#hive.operations-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8850)
*Effects*: Erases all but the first element
from every consecutive group of equivalent elements[.](#hive.operations-8.sentence-1)
That is, for a nonempty hive,
erases all elements referred to by the iterator i in the range [begin() + 1, end())
for which binary_pred(*i, *(i - 1)) is true[.](#hive.operations-8.sentence-2)
[9](#hive.operations-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8859)
*Returns*: The number of elements erased[.](#hive.operations-9.sentence-1)
[10](#hive.operations-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8863)
*Throws*: Nothing unless an exception is thrown by the predicate[.](#hive.operations-10.sentence-1)
[11](#hive.operations-11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8867)
*Complexity*: If empty() is false,
exactly size() - 1 applications of the corresponding predicate,
otherwise no applications of the predicate[.](#hive.operations-11.sentence-1)
[12](#hive.operations-12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8873)
*Remarks*: Invalidates references, pointers, and iterators
referring to the erased elements[.](#hive.operations-12.sentence-1)
If the last element in *this is erased,
also invalidates the past-the-end iterator[.](#hive.operations-12.sentence-2)
[🔗](#lib:sort,hive)
`template<class Compare = less<T>>
void sort(Compare comp = Compare());
`
[13](#hive.operations-13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8888)
*Preconditions*: T is *Cpp17MoveInsertable* into hive,*Cpp17MoveAssignable*, and *Cpp17Swappable*[.](#hive.operations-13.sentence-1)
[14](#hive.operations-14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8893)
*Effects*: Sorts *this according to the comp function object[.](#hive.operations-14.sentence-1)
If an exception is thrown,
the order of the elements in *this is unspecified[.](#hive.operations-14.sentence-2)
[15](#hive.operations-15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8899)
*Complexity*: O(NlogN) comparisons, where N is size()[.](#hive.operations-15.sentence-1)
[16](#hive.operations-16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8903)
*Remarks*: May allocate[.](#hive.operations-16.sentence-1)
References, pointers, and iterators referring to elements in *this,
as well as the past-the-end iterator, may be invalidated[.](#hive.operations-16.sentence-2)
[*Note [1](#hive.operations-note-1)*:
Not required to be stable[[algorithm.stable]](algorithm.stable "16.4.6.8Requirements for stable algorithms")[.](#hive.operations-16.sentence-3)
— *end note*]
[🔗](#lib:get_iterator,hive)
`iterator get_iterator(const_pointer p) noexcept;
const_iterator get_iterator(const_pointer p) const noexcept;
`
[17](#hive.operations-17)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8920)
*Preconditions*: p points to an element in *this[.](#hive.operations-17.sentence-1)
[18](#hive.operations-18)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8924)
*Returns*: An iterator or const_iterator pointing to the same element as p[.](#hive.operations-18.sentence-1)
[19](#hive.operations-19)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8929)
*Complexity*: Linear in the number of active blocks in *this[.](#hive.operations-19.sentence-1)
#### [23.3.9.6](#hive.erasure) Erasure [[hive.erasure]](hive.erasure)
[🔗](#lib:erase,hive_)
`template<class T, class Allocator, class U = T>
typename hive<T, Allocator>::size_type
erase(hive<T, Allocator>& c, const U& value);
`
[1](#hive.erasure-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8944)
*Effects*: Equivalent to:return erase_if(c, [&](const auto& elem) -> bool { return elem == value; });
[🔗](#lib:erase_if,hive)
`template<class T, class Allocator, class Predicate>
typename hive<T, Allocator>::size_type
erase_if(hive<T, Allocator>& c, Predicate pred);
`
[2](#hive.erasure-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L8960)
*Effects*: Equivalent to:auto original_size = c.size();for (auto i = c.begin(), last = c.end(); i != last; ) {if (pred(*i)) { i = c.erase(i); } else {++i; }}return original_size - c.size();
### [23.3.10](#list.syn) Header <list> synopsis [[list.syn]](list.syn)
[🔗](#header:%3clist%3e)
#include <compare> // see [[compare.syn]](compare.syn "17.12.1Header <compare> synopsis")#include <initializer_list> // see [[initializer.list.syn]](initializer.list.syn "17.11.2Header <initializer_­list> synopsis")namespace std {// [[list]](#list "23.3.11Class template list"), class template listtemplate<class T, class Allocator = allocator<T>> class list; template<class T, class Allocator>constexpr bool operator==(const list<T, Allocator>& x, const list<T, Allocator>& y); template<class T, class Allocator>constexpr *synth-three-way-result*<T> operator<=>(const list<T, Allocator>& x, const list<T, Allocator>& y); template<class T, class Allocator>constexpr void swap(list<T, Allocator>& x, list<T, Allocator>& y)noexcept(noexcept(x.swap(y))); // [[list.erasure]](#list.erasure "23.3.11.6Erasure"), erasuretemplate<class T, class Allocator, class U = T>constexpr typename list<T, Allocator>::size_type
erase(list<T, Allocator>& c, const U& value); template<class T, class Allocator, class Predicate>constexpr typename list<T, Allocator>::size_type
erase_if(list<T, Allocator>& c, Predicate pred); namespace pmr {template<class T>using list = std::list<T, polymorphic_allocator<T>>; }}
### [23.3.11](#list) Class template list [[list]](list)
#### [23.3.11.1](#list.overview) Overview [[list.overview]](list.overview)
[1](#list.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[.](#list.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[.](#list.overview-1.sentence-2)
[2](#list.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"))[.](#list.overview-2.sentence-1)
The exceptions are theoperator[] andat member functions, which are not provided[.](#list.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[.](#list.overview-2.sentence-3)
[3](#list.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")[.](#list.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]](#list.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]](#list.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]](#list.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]](#list.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](#list.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]")[.](#list.overview-4.sentence-1)
T shall be complete before any member of the resulting specialization
of list is referenced[.](#list.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](#list.cons) Constructors, copy, and assignment [[list.cons]](list.cons)
[🔗](#lib:list,constructor)
`constexpr explicit list(const Allocator&);
`
[1](#list.cons-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9211)
*Effects*: Constructs an empty list, using the specified allocator[.](#list.cons-1.sentence-1)
[2](#list.cons-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9215)
*Complexity*: Constant[.](#list.cons-2.sentence-1)
[🔗](#lib:list,constructor_)
`constexpr explicit list(size_type n, const Allocator& = Allocator());
`
[3](#list.cons-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9226)
*Preconditions*: T is *Cpp17DefaultInsertable* into list[.](#list.cons-3.sentence-1)
[4](#list.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[.](#list.cons-4.sentence-1)
[5](#list.cons-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9235)
*Complexity*: Linear inn[.](#list.cons-5.sentence-1)
[🔗](#lib:list,constructor__)
`constexpr list(size_type n, const T& value, const Allocator& = Allocator());
`
[6](#list.cons-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9247)
*Preconditions*: T is *Cpp17CopyInsertable* into list[.](#list.cons-6.sentence-1)
[7](#list.cons-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9251)
*Effects*: Constructs alist withn copies ofvalue,
using the specified allocator[.](#list.cons-7.sentence-1)
[8](#list.cons-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9261)
*Complexity*: Linear inn[.](#list.cons-8.sentence-1)
[🔗](#lib:list,constructor___)
`template<class InputIterator>
constexpr list(InputIterator first, InputIterator last, const Allocator& = Allocator());
`
[9](#list.cons-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9274)
*Effects*: Constructs alist equal to the range
[first, last)[.](#list.cons-9.sentence-1)
[10](#list.cons-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9281)
*Complexity*: Linear indistance(first, last)[.](#list.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](#list.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[.](#list.cons-11.sentence-1)
[12](#list.cons-12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9298)
*Complexity*: Linear in ranges::distance(rg)[.](#list.cons-12.sentence-1)
#### [23.3.11.3](#list.capacity) Capacity [[list.capacity]](list.capacity)
[🔗](#lib:resize,list)
`constexpr void resize(size_type sz);
`
[1](#list.capacity-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9311)
*Preconditions*: T is *Cpp17DefaultInsertable* into list[.](#list.capacity-1.sentence-1)
[2](#list.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[.](#list.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](#list.capacity-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9334)
*Preconditions*: T is *Cpp17CopyInsertable* into list[.](#list.capacity-3.sentence-1)
[4](#list.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](#list.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](#list.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[.](#list.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[.](#list.modifiers-1.sentence-2)
[2](#list.modifiers-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9391)
*Remarks*: Does not affect the validity of iterators and references[.](#list.modifiers-2.sentence-1)
If an exception is thrown, there are no effects[.](#list.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](#list.modifiers-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9407)
*Effects*: Invalidates only the iterators and references to the erased elements[.](#list.modifiers-3.sentence-1)
[4](#list.modifiers-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9411)
*Throws*: Nothing[.](#list.modifiers-4.sentence-1)
[5](#list.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[.](#list.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[.](#list.modifiers-5.sentence-2)
#### [23.3.11.5](#list.ops) Operations [[list.ops]](list.ops)
[1](#list.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[.](#list.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")[.](#list.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[.](#list.ops-1.sentence-3)
For merge and sort,
the definitions and requirements in [[alg.sorting]](alg.sorting "26.8Sorting and related operations") apply[.](#list.ops-1.sentence-4)
[2](#list.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[.](#list.ops-2.sentence-1)
The behavior of splice operations is undefined if get_allocator() != x.get_allocator()[.](#list.ops-2.sentence-2)
[🔗](#lib:splice,list)
`constexpr void splice(const_iterator position, list& x);
constexpr void splice(const_iterator position, list&& x);
`
[3](#list.ops-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9458)
*Preconditions*: addressof(x) != this is true[.](#list.ops-3.sentence-1)
[4](#list.ops-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9462)
*Effects*: Inserts the contents ofx beforeposition andx becomes empty[.](#list.ops-4.sentence-1)
Pointers and references to the moved elements ofx now refer to those same elements but as members of*this[.](#list.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[.](#list.ops-4.sentence-3)
[5](#list.ops-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9481)
*Throws*: Nothing[.](#list.ops-5.sentence-1)
[6](#list.ops-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9485)
*Complexity*: Constant time[.](#list.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](#list.ops-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9497)
*Preconditions*: i is a valid dereferenceable iterator of x[.](#list.ops-7.sentence-1)
[8](#list.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[.](#list.ops-8.sentence-1)
The result is unchanged ifposition == i orposition == ++i[.](#list.ops-8.sentence-2)
Pointers and references to*i continue to refer to this same element but as a member of*this[.](#list.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[.](#list.ops-8.sentence-4)
[9](#list.ops-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9527)
*Throws*: Nothing[.](#list.ops-9.sentence-1)
[10](#list.ops-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9531)
*Complexity*: Constant time[.](#list.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](#list.ops-11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9545)
*Preconditions*: [first, last) is a valid range in x[.](#list.ops-11.sentence-1)
position is not an iterator in the range [first, last)[.](#list.ops-11.sentence-2)
[12](#list.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[.](#list.ops-12.sentence-1)
Pointers and references to the moved elements ofx now refer to those same elements but as members of*this[.](#list.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[.](#list.ops-12.sentence-3)
[13](#list.ops-13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9568)
*Throws*: Nothing[.](#list.ops-13.sentence-1)
[14](#list.ops-14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9572)
*Complexity*: Constant time ifaddressof(x) == this;
otherwise, linear time[.](#list.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](#list.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[.](#list.ops-15.sentence-1)
Invalidates only the iterators and references to the erased elements[.](#list.ops-15.sentence-2)
[16](#list.ops-16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9592)
*Returns*: The number of elements erased[.](#list.ops-16.sentence-1)
[17](#list.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[.](#list.ops-17.sentence-1)
[18](#list.ops-18)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9603)
*Complexity*: Exactlysize() applications of the corresponding predicate[.](#list.ops-18.sentence-1)
[19](#list.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]")[.](#list.ops-19.sentence-1)
[🔗](#lib:unique,list)
`constexpr size_type unique();
template<class BinaryPredicate> constexpr size_type unique(BinaryPredicate binary_pred);
`
[20](#list.ops-20)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9621)
Let binary_pred be equal_to<>{} for the first overload[.](#list.ops-20.sentence-1)
[21](#list.ops-21)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9624)
*Preconditions*: binary_pred is an equivalence relation[.](#list.ops-21.sentence-1)
[22](#list.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[.](#list.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[.](#list.ops-22.sentence-2)
Invalidates only the iterators and references to the erased elements[.](#list.ops-22.sentence-3)
[23](#list.ops-23)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9637)
*Returns*: The number of elements erased[.](#list.ops-23.sentence-1)
[24](#list.ops-24)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9641)
*Throws*: Nothing unless an exception is thrown by the predicate[.](#list.ops-24.sentence-1)
[25](#list.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[.](#list.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](#list.ops-26)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9661)
Let comp be less<> for the first two overloads[.](#list.ops-26.sentence-1)
[27](#list.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[.](#list.ops-27.sentence-1)
[28](#list.ops-28)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9670)
*Effects*: If addressof(x) == this, there are no effects[.](#list.ops-28.sentence-1)
Otherwise, merges
the two sorted ranges [begin(), end()) and [x.begin(), x.end())[.](#list.ops-28.sentence-2)
The result is a range
that is sorted with respect to the comparator comp[.](#list.ops-28.sentence-3)
Pointers and references to the moved elements of x now refer to those same elements
but as members of *this[.](#list.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[.](#list.ops-28.sentence-5)
[29](#list.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[.](#list.ops-29.sentence-1)
[30](#list.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"))[.](#list.ops-30.sentence-1)
If addressof(x) != this, x is empty after the merge[.](#list.ops-30.sentence-2)
No elements are copied by this operation[.](#list.ops-30.sentence-3)
If an exception is thrown other than by a comparison, there are no effects[.](#list.ops-30.sentence-4)
[🔗](#lib:reverse,list)
`constexpr void reverse() noexcept;
`
[31](#list.ops-31)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9702)
*Effects*: Reverses the order of the elements in the list[.](#list.ops-31.sentence-1)
Does not affect the validity of iterators and references[.](#list.ops-31.sentence-2)
[32](#list.ops-32)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9707)
*Complexity*: Linear time[.](#list.ops-32.sentence-1)
[🔗](#lib:sort,list)
`void sort();
template<class Compare> void sort(Compare comp);
`
[33](#list.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[.](#list.ops-33.sentence-1)
If an exception is thrown,
the order of the elements in *this is unspecified[.](#list.ops-33.sentence-2)
Does not affect the validity of iterators and references[.](#list.ops-33.sentence-3)
[34](#list.ops-34)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9726)
*Complexity*: ApproximatelyNlogN comparisons, where N is size()[.](#list.ops-34.sentence-1)
[35](#list.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]")[.](#list.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](#list.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](#list.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](#list.erasure-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9763)
*Effects*: Equivalent to: return c.remove_if(pred);
### [23.3.12](#vector.syn) Header <vector> synopsis [[vector.syn]](vector.syn)
[🔗](#header:%3cvector%3e)
#include <compare> // see [[compare.syn]](compare.syn "17.12.1Header <compare> synopsis")#include <initializer_list> // see [[initializer.list.syn]](initializer.list.syn "17.11.2Header <initializer_­list> synopsis")namespace std {// [[vector]](#vector "23.3.13Class template vector"), class template vectortemplate<class T, class Allocator = allocator<T>> class vector; template<class T, class Allocator>constexpr bool operator==(const vector<T, Allocator>& x, const vector<T, Allocator>& y); template<class T, class Allocator>constexpr *synth-three-way-result*<T> operator<=>(const vector<T, Allocator>& x, const vector<T, Allocator>& y); template<class T, class Allocator>constexpr void swap(vector<T, Allocator>& x, vector<T, Allocator>& y)noexcept(noexcept(x.swap(y))); // [[vector.erasure]](#vector.erasure "23.3.13.6Erasure"), erasuretemplate<class T, class Allocator, class U = T>constexpr typename vector<T, Allocator>::size_type
erase(vector<T, Allocator>& c, const U& value); template<class T, class Allocator, class Predicate>constexpr typename vector<T, Allocator>::size_type
erase_if(vector<T, Allocator>& c, Predicate pred); namespace pmr {template<class T>using vector = std::vector<T, polymorphic_allocator<T>>; }// [[vector.bool]](#vector.bool "23.3.14Specialization of vector for bool"), specialization of vector for bool// [[vector.bool.pspc]](#vector.bool.pspc "23.3.14.1Partial class template specialization vector<bool, Allocator>"), partial class template specialization vector<bool, Allocator>template<class Allocator>class vector<bool, Allocator>; template<class T>constexpr bool *is-vector-bool-reference* = *see below*; // *exposition only*// hash supporttemplate<class T> struct hash; template<class Allocator> struct hash<vector<bool, Allocator>>; // [[vector.bool.fmt]](#vector.bool.fmt "23.3.14.2Formatter specialization for vector<bool>"), formatter specialization for vector<bool>template<class T, class charT> requires *is-vector-bool-reference*<T>struct formatter<T, charT>;}
### [23.3.13](#vector) Class template vector [[vector]](vector)
#### [23.3.13.1](#vector.overview) Overview [[vector.overview]](vector.overview)
[1](#vector.overview-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9824)
Avector is a sequence container that supports
(amortized) constant time insert and erase operations at the end;
insert and erase in the middle take linear time[.](#vector.overview-1.sentence-1)
Storage management is handled automatically, though hints can be given
to improve efficiency[.](#vector.overview-1.sentence-2)
[2](#vector.overview-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9834)
A vector 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")),
of a sequence container, including most of the optional sequence container
requirements ([[sequence.reqmts]](sequence.reqmts "23.2.4Sequence containers")),
and, for an element type other than bool,
of a [contiguous container](container.reqmts#def:container,contiguous "23.2.2.2Container requirements[container.reqmts]")[.](#vector.overview-2.sentence-1)
The exceptions are thepush_front, prepend_range, pop_front, and emplace_front member functions, which are not
provided[.](#vector.overview-2.sentence-2)
Descriptions are provided here only for operations on vector that are not described in one of these tables or for operations where there is
additional semantic information[.](#vector.overview-2.sentence-3)
[3](#vector.overview-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9849)
The types iterator and const_iterator meet
the constexpr iterator requirements ([[iterator.requirements.general]](iterator.requirements.general "24.3.1General"))[.](#vector.overview-3.sentence-1)
namespace std {template<class T, class Allocator = allocator<T>>class vector {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>; // [[vector.cons]](#vector.cons "23.3.13.2Constructors"), construct/copy/destroyconstexpr vector() noexcept(noexcept(Allocator())) : vector(Allocator()) { }constexpr explicit vector(const Allocator&) noexcept; constexpr explicit vector(size_type n, const Allocator& = Allocator()); constexpr vector(size_type n, const T& value, const Allocator& = Allocator()); template<class InputIterator>constexpr vector(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 vector(from_range_t, R&& rg, const Allocator& = Allocator()); constexpr vector(const vector& x); constexpr vector(vector&&) noexcept; constexpr vector(const vector&, const type_identity_t<Allocator>&); constexpr vector(vector&&, const type_identity_t<Allocator>&); constexpr vector(initializer_list<T>, const Allocator& = Allocator()); constexpr ~vector(); constexpr vector& operator=(const vector& x); constexpr vector& operator=(vector&& x)noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value || allocator_traits<Allocator>::is_always_equal::value); constexpr vector& 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& u); 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; // [[vector.capacity]](#vector.capacity "23.3.13.3Capacity"), capacityconstexpr bool empty() const noexcept; constexpr size_type size() const noexcept; constexpr size_type max_size() const noexcept; constexpr size_type capacity() const noexcept; constexpr void resize(size_type sz); constexpr void resize(size_type sz, const T& c); constexpr void reserve(size_type n); constexpr void shrink_to_fit(); // element accessconstexpr reference operator[](size_type n); constexpr const_reference operator[](size_type n) const; constexpr reference at(size_type n); constexpr const_reference at(size_type n) const; constexpr reference front(); constexpr const_reference front() const; constexpr reference back(); constexpr const_reference back() const; // [[vector.data]](#vector.data "23.3.13.4Data"), data accessconstexpr T* data() noexcept; constexpr const T* data() const noexcept; // [[vector.modifiers]](#vector.modifiers "23.3.13.5Modifiers"), modifierstemplate<class... Args> constexpr reference emplace_back(Args&&... args); 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 first, const_iterator last); constexpr void swap(vector&)noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value || allocator_traits<Allocator>::is_always_equal::value); constexpr void clear() noexcept; }; template<class InputIterator, class Allocator = allocator<*iter-value-type*<InputIterator>>> vector(InputIterator, InputIterator, Allocator = Allocator())-> vector<*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>>> vector(from_range_t, R&&, Allocator = Allocator())-> vector<ranges::range_value_t<R>, Allocator>;}
[4](#vector.overview-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9977)
An incomplete type T may be used when instantiating vector if the allocator meets the[allocator completeness requirements](allocator.requirements.completeness "16.4.4.6.2Allocator completeness requirements[allocator.requirements.completeness]")[.](#vector.overview-4.sentence-1)
T shall be complete before any member of the resulting specialization
of vector is referenced[.](#vector.overview-4.sentence-2)
#### [23.3.13.2](#vector.cons) Constructors [[vector.cons]](vector.cons)
[🔗](#lib:vector,constructor)
`constexpr explicit vector(const Allocator&) noexcept;
`
[1](#vector.cons-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9992)
*Effects*: Constructs an empty vector, using the
specified allocator[.](#vector.cons-1.sentence-1)
[2](#vector.cons-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9997)
*Complexity*: Constant[.](#vector.cons-2.sentence-1)
[🔗](#lib:vector,constructor_)
`constexpr explicit vector(size_type n, const Allocator& = Allocator());
`
[3](#vector.cons-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10008)
*Preconditions*: T is *Cpp17DefaultInsertable* into vector[.](#vector.cons-3.sentence-1)
[4](#vector.cons-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10012)
*Effects*: Constructs a vector with n default-inserted elements using the specified allocator[.](#vector.cons-4.sentence-1)
[5](#vector.cons-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10017)
*Complexity*: Linear in n[.](#vector.cons-5.sentence-1)
[🔗](#lib:vector,constructor__)
`constexpr vector(size_type n, const T& value,
const Allocator& = Allocator());
`
[6](#vector.cons-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10029)
*Preconditions*: T is*Cpp17CopyInsertable* into vector[.](#vector.cons-6.sentence-1)
[7](#vector.cons-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10034)
*Effects*: Constructs a vector with n copies of value, using the specified allocator[.](#vector.cons-7.sentence-1)
[8](#vector.cons-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10039)
*Complexity*: Linear in n[.](#vector.cons-8.sentence-1)
[🔗](#lib:vector,constructor___)
`template<class InputIterator>
constexpr vector(InputIterator first, InputIterator last,
const Allocator& = Allocator());
`
[9](#vector.cons-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10052)
*Effects*: Constructs a vector equal to the
range [first, last), using the specified allocator[.](#vector.cons-9.sentence-1)
[10](#vector.cons-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10057)
*Complexity*: Makes only N calls to the copy constructor ofT (where N is the distance betweenfirst andlast)
and no reallocations ifInputIterator meets the *Cpp17ForwardIterator* requirements[.](#vector.cons-10.sentence-1)
It makes orderN calls to the copy constructor ofT and orderlogN reallocations if they are just input iterators[.](#vector.cons-10.sentence-2)
[🔗](#lib:vector,constructor____)
`template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1Introduction[container.intro.reqmts]")<T> R>
constexpr vector(from_range_t, R&& rg, const Allocator& = Allocator());
`
[11](#vector.cons-11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10085)
*Effects*: Constructs a vector object with the elements of the range rg,
using the specified allocator[.](#vector.cons-11.sentence-1)
[12](#vector.cons-12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10090)
*Complexity*: Initializes exactly N elements
from the results of dereferencing successive iterators of rg,
where N is ranges::distance(rg)[.](#vector.cons-12.sentence-1)
[13](#vector.cons-13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10096)
Performs no reallocations if:
- [(13.1)](#vector.cons-13.1)
R models ranges::[approximately_sized_range](range.approximately.sized#concept:approximately_sized_range "25.4.3Approximately sized ranges[range.approximately.sized]"), andranges::distance(rg) <= ranges::reserve_hint(rg) is true, or
- [(13.2)](#vector.cons-13.2)
R models ranges::[forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]") andR does not model ranges::[approximately_sized_range](range.approximately.sized#concept:approximately_sized_range "25.4.3Approximately sized ranges[range.approximately.sized]")[.](#vector.cons-13.sentence-1)
Otherwise, performs order logN reallocations and
order N calls to the copy or move constructor of T[.](#vector.cons-13.sentence-2)
#### [23.3.13.3](#vector.capacity) Capacity [[vector.capacity]](vector.capacity)
[🔗](#lib:capacity,vector)
`constexpr size_type capacity() const noexcept;
`
[1](#vector.capacity-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10118)
*Returns*: The total number of elements that the vector can hold
without requiring reallocation[.](#vector.capacity-1.sentence-1)
[2](#vector.capacity-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10123)
*Complexity*: Constant time[.](#vector.capacity-2.sentence-1)
[🔗](#lib:reserve,vector)
`constexpr void reserve(size_type n);
`
[3](#vector.capacity-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10134)
*Preconditions*: T is *Cpp17MoveInsertable* into vector[.](#vector.capacity-3.sentence-1)
[4](#vector.capacity-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10138)
*Effects*: A directive that informs avector of a planned change in size, so that it can manage the storage allocation accordingly[.](#vector.capacity-4.sentence-1)
Afterreserve(),capacity() is greater or equal to the argument ofreserve if reallocation happens; and equal to the previous value ofcapacity() otherwise[.](#vector.capacity-4.sentence-2)
Reallocation happens at this point if and only if the current capacity is less than the
argument ofreserve()[.](#vector.capacity-4.sentence-3)
If an exception is thrown
other than by the move constructor of a non-*Cpp17CopyInsertable* type,
there are no effects[.](#vector.capacity-4.sentence-4)
[5](#vector.capacity-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10157)
*Throws*: length_error if n > max_size()[.](#vector.capacity-5.sentence-1)[197](#footnote-197 "reserve() uses Allocator::allocate() which can throw an appropriate exception.")
[6](#vector.capacity-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10166)
*Complexity*: It does not change the size of the sequence and takes at most linear
time in the size of the sequence[.](#vector.capacity-6.sentence-1)
[7](#vector.capacity-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10171)
*Remarks*: Reallocation invalidates all the references, pointers, and iterators
referring to the elements in the sequence, as well as the past-the-end iterator[.](#vector.capacity-7.sentence-1)
[*Note [1](#vector.capacity-note-1)*:
If no reallocation happens, they remain valid[.](#vector.capacity-7.sentence-2)
— *end note*]
No reallocation shall take place during insertions that happen
after a call to reserve() until an insertion would make the size of the vector
greater than the value of capacity()[.](#vector.capacity-7.sentence-3)
[🔗](#lib:shrink_to_fit,vector)
`constexpr void shrink_to_fit();
`
[8](#vector.capacity-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10190)
*Preconditions*: T is *Cpp17MoveInsertable* into vector[.](#vector.capacity-8.sentence-1)
[9](#vector.capacity-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10194)
*Effects*: shrink_to_fit is a non-binding request to reducecapacity() to size()[.](#vector.capacity-9.sentence-1)
[*Note [2](#vector.capacity-note-2)*:
The request is non-binding to allow latitude for
implementation-specific optimizations[.](#vector.capacity-9.sentence-2)
— *end note*]
It does not increase capacity(), but may reduce capacity() by causing reallocation[.](#vector.capacity-9.sentence-3)
If an exception is thrown other than by the move constructor
of a non-*Cpp17CopyInsertable* T, there are no effects[.](#vector.capacity-9.sentence-4)
[10](#vector.capacity-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10207)
*Complexity*: If reallocation happens,
linear in the size of the sequence[.](#vector.capacity-10.sentence-1)
[11](#vector.capacity-11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10212)
*Remarks*: Reallocation invalidates all the references, pointers, and iterators
referring to the elements in the sequence as well as the past-the-end iterator[.](#vector.capacity-11.sentence-1)
[*Note [3](#vector.capacity-note-3)*:
If no reallocation happens, they remain valid[.](#vector.capacity-11.sentence-2)
— *end note*]
[🔗](#lib:swap,vector)
`constexpr void swap(vector& x)
noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value ||
allocator_traits<Allocator>::is_always_equal::value);
`
[12](#vector.capacity-12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10229)
*Effects*: Exchanges the contents andcapacity() of*this with that of x[.](#vector.capacity-12.sentence-1)
[13](#vector.capacity-13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10237)
*Complexity*: Constant time[.](#vector.capacity-13.sentence-1)
[🔗](#lib:resize,vector)
`constexpr void resize(size_type sz);
`
[14](#vector.capacity-14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10248)
*Preconditions*: T is*Cpp17MoveInsertable* and *Cpp17DefaultInsertable* into vector[.](#vector.capacity-14.sentence-1)
[15](#vector.capacity-15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10253)
*Effects*: If sz < size(), erases the last size() - sz elements
from the sequence[.](#vector.capacity-15.sentence-1)
Otherwise,
appends sz - size() default-inserted elements to the sequence[.](#vector.capacity-15.sentence-2)
[16](#vector.capacity-16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10259)
*Remarks*: If an exception is thrown other than by the move constructor of a non-*Cpp17CopyInsertable*T, there are no effects[.](#vector.capacity-16.sentence-1)
[🔗](#lib:resize,vector_)
`constexpr void resize(size_type sz, const T& c);
`
[17](#vector.capacity-17)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10271)
*Preconditions*: T is*Cpp17CopyInsertable* into vector[.](#vector.capacity-17.sentence-1)
[18](#vector.capacity-18)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10276)
*Effects*: If sz < size(), erases the last size() - sz elements
from the sequence[.](#vector.capacity-18.sentence-1)
Otherwise,
appends sz - size() copies of c to the sequence[.](#vector.capacity-18.sentence-2)
[19](#vector.capacity-19)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10282)
*Remarks*: If an exception is thrown, there are no effects[.](#vector.capacity-19.sentence-1)
[197)](#footnote-197)[197)](#footnoteref-197)
reserve() uses Allocator::allocate() which
can throw an appropriate exception[.](#footnote-197.sentence-1)
#### [23.3.13.4](#vector.data) Data [[vector.data]](vector.data)
[🔗](#lib:data,vector)
`constexpr T* data() noexcept;
constexpr const T* data() const noexcept;
`
[1](#vector.data-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10296)
*Returns*: A pointer such that [data(), data() + size()) is a valid range[.](#vector.data-1.sentence-1)
For a
non-empty vector, data() == addressof(front()) is true[.](#vector.data-1.sentence-2)
[2](#vector.data-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10301)
*Complexity*: Constant time[.](#vector.data-2.sentence-1)
#### [23.3.13.5](#vector.modifiers) Modifiers [[vector.modifiers]](vector.modifiers)
[🔗](#lib:insert,vector)
`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_back(Args&&... args);
template<class... Args> constexpr iterator emplace(const_iterator position, Args&&... args);
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](#vector.modifiers-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10328)
*Complexity*: If reallocation happens,
linear in the number of elements of the resulting vector;
otherwise,
linear in the number of elements inserted plus the distance
to the end of the vector[.](#vector.modifiers-1.sentence-1)
[2](#vector.modifiers-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10336)
*Remarks*: Causes reallocation if the new size is greater than the old capacity[.](#vector.modifiers-2.sentence-1)
Reallocation invalidates all the references, pointers, and iterators
referring to the elements in the sequence, as well as the past-the-end iterator[.](#vector.modifiers-2.sentence-2)
If no reallocation happens, then
references, pointers, and iterators
before the insertion point remain valid
but those at or after the insertion point,
including the past-the-end iterator,
are invalidated[.](#vector.modifiers-2.sentence-3)
If an exception is thrown other than by
the copy constructor, move constructor,
assignment operator, or move assignment operator ofT or by any InputIterator operation,
there are no effects[.](#vector.modifiers-2.sentence-4)
If an exception is thrown while inserting a single element at the end andT is *Cpp17CopyInsertable* or is_nothrow_move_constructible_v<T> is true, there are no effects[.](#vector.modifiers-2.sentence-5)
Otherwise, if an exception is thrown by the move constructor of a non-*Cpp17CopyInsertable*T, the effects are unspecified[.](#vector.modifiers-2.sentence-6)
[3](#vector.modifiers-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10358)
For the declarations taking a range R,
performs at most one reallocation if:
- [(3.1)](#vector.modifiers-3.1)
R models ranges::[approximately_sized_range](range.approximately.sized#concept:approximately_sized_range "25.4.3Approximately sized ranges[range.approximately.sized]") andranges::distance(rg) <= ranges::reserve_hint(rg) is true, or
- [(3.2)](#vector.modifiers-3.2)
R models ranges::[forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]") andR does not model ranges::[approximately_sized_range](range.approximately.sized#concept:approximately_sized_range "25.4.3Approximately sized ranges[range.approximately.sized]")[.](#vector.modifiers-3.sentence-1)
For the declarations taking a pair of InputIterator,
performs at most one reallocation ifInputIterator meets the *Cpp17ForwardIterator* requirements[.](#vector.modifiers-3.sentence-2)
[🔗](#lib:erase,vector)
`constexpr iterator erase(const_iterator position);
constexpr iterator erase(const_iterator first, const_iterator last);
constexpr void pop_back();
`
[4](#vector.modifiers-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10382)
*Effects*: Invalidates iterators and references at or after the point of the erase[.](#vector.modifiers-4.sentence-1)
[5](#vector.modifiers-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10386)
*Throws*: Nothing unless an exception is thrown by the
assignment operator or move assignment operator ofT[.](#vector.modifiers-5.sentence-1)
[6](#vector.modifiers-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10392)
*Complexity*: The destructor of T is called the number of times equal to the
number of the elements erased, but the assignment operator
of T is called the number of times equal to the number of
elements in the vector after the erased elements[.](#vector.modifiers-6.sentence-1)
#### [23.3.13.6](#vector.erasure) Erasure [[vector.erasure]](vector.erasure)
[🔗](#lib:erase,vector_)
`template<class T, class Allocator, class U = T>
constexpr typename vector<T, Allocator>::size_type
erase(vector<T, Allocator>& c, const U& value);
`
[1](#vector.erasure-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10410)
*Effects*: Equivalent to:auto it = remove(c.begin(), c.end(), value);auto r = distance(it, c.end());
c.erase(it, c.end());return r;
[🔗](#lib:erase_if,vector)
`template<class T, class Allocator, class Predicate>
constexpr typename vector<T, Allocator>::size_type
erase_if(vector<T, Allocator>& c, Predicate pred);
`
[2](#vector.erasure-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10429)
*Effects*: Equivalent to:auto it = remove_if(c.begin(), c.end(), pred);auto r = distance(it, c.end());
c.erase(it, c.end());return r;
### [23.3.14](#vector.bool) Specialization of vector for bool [[vector.bool]](vector.bool)
#### [23.3.14.1](#vector.bool.pspc) Partial class template specialization vector<bool, Allocator> [[vector.bool.pspc]](vector.bool.pspc)
[1](#vector.bool.pspc-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10444)
To optimize space allocation, a partial specialization of vector forbool elements is provided:namespace std {template<class Allocator>class vector<bool, Allocator> {public:// typesusing value_type = bool; using allocator_type = Allocator; using pointer = *implementation-defined*; using const_pointer = *implementation-defined*; using const_reference = bool; 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>; // bit referenceclass [reference](#lib:vector%3cbool%3e,reference "23.3.14.1Partial class template specialization vector<bool, Allocator>[vector.bool.pspc]") {public:constexpr reference(const reference&) = default; constexpr ~reference(); constexpr operator bool() const noexcept; constexpr reference& operator=(bool x) noexcept; constexpr reference& operator=(const reference& x) noexcept; constexpr const reference& operator=(bool x) const noexcept; constexpr void flip() noexcept; // flips the bit}; // construct/copy/destroyconstexpr vector() noexcept(noexcept(Allocator())) : vector(Allocator()) { }constexpr explicit vector(const Allocator&) noexcept; constexpr explicit vector(size_type n, const Allocator& = Allocator()); constexpr vector(size_type n, const bool& value, const Allocator& = Allocator()); template<class InputIterator>constexpr vector(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]")<bool> R>constexpr vector(from_range_t, R&& rg, const Allocator& = Allocator()); constexpr vector(const vector& x); constexpr vector(vector&& x) noexcept; constexpr vector(const vector&, const type_identity_t<Allocator>&); constexpr vector(vector&&, const type_identity_t<Allocator>&); constexpr vector(initializer_list<bool>, const Allocator& = Allocator()); constexpr ~vector(); constexpr vector& operator=(const vector& x); constexpr vector& operator=(vector&& x)noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value || allocator_traits<Allocator>::is_always_equal::value); constexpr vector& operator=(initializer_list<bool>); 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]")<bool> R>constexpr void assign_range(R&& rg); constexpr void assign(size_type n, const bool& t); constexpr void assign(initializer_list<bool>); 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; // capacityconstexpr bool empty() const noexcept; constexpr size_type size() const noexcept; constexpr size_type max_size() const noexcept; constexpr size_type capacity() const noexcept; constexpr void resize(size_type sz, bool c = false); constexpr void reserve(size_type n); constexpr void shrink_to_fit(); // element accessconstexpr reference operator[](size_type n); constexpr const_reference operator[](size_type n) const; constexpr reference at(size_type n); constexpr const_reference at(size_type n) const; constexpr reference front(); constexpr const_reference front() const; constexpr reference back(); constexpr const_reference back() const; // modifierstemplate<class... Args> constexpr reference emplace_back(Args&&... args); constexpr void push_back(const bool& x); template<[*container-compatible-range*](container.intro.reqmts#concept:container-compatible-range "23.2.2.1Introduction[container.intro.reqmts]")<bool> 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 bool& x); constexpr iterator insert(const_iterator position, size_type n, const bool& 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]")<bool> R>constexpr iterator insert_range(const_iterator position, R&& rg); constexpr iterator insert(const_iterator position, initializer_list<bool> il); constexpr iterator erase(const_iterator position); constexpr iterator erase(const_iterator first, const_iterator last); constexpr void swap(vector&)noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value || allocator_traits<Allocator>::is_always_equal::value); static constexpr void swap(reference x, reference y) noexcept; constexpr void flip() noexcept; // flips all bitsconstexpr void clear() noexcept; };}
[2](#vector.bool.pspc-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10568)
Unless described below, all operations have the same requirements and
semantics as the primary vector template, except that operations
dealing with the bool value type map to bit values in the
container storage and[allocator_traits::construct](allocator.traits.members#lib:allocator_traits,construct "20.2.9.3Static member functions[allocator.traits.members]") is not used to construct these values[.](#vector.bool.pspc-2.sentence-1)
[3](#vector.bool.pspc-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10576)
There is no requirement that the data be stored as a contiguous allocation
of bool values[.](#vector.bool.pspc-3.sentence-1)
A space-optimized representation of bits is
recommended instead[.](#vector.bool.pspc-3.sentence-2)
[4](#vector.bool.pspc-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10581)
reference is a class that simulates the behavior of references of a single bit invector<bool>[.](#vector.bool.pspc-4.sentence-1)
The conversion function returns true when the bit is set, and false otherwise[.](#vector.bool.pspc-4.sentence-2)
The assignment operators
set the bit when the argument is (convertible to) true and
clear it otherwise[.](#vector.bool.pspc-4.sentence-3)
flip reverses the state of the bit[.](#vector.bool.pspc-4.sentence-4)
[🔗](#lib:flip,vector%3cbool%3e)
`constexpr void flip() noexcept;
`
[5](#vector.bool.pspc-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10595)
*Effects*: Replaces each element in the container with its complement[.](#vector.bool.pspc-5.sentence-1)
[🔗](#lib:swap,vector%3cbool%3e)
`static constexpr void swap(reference x, reference y) noexcept;
`
[6](#vector.bool.pspc-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10606)
*Effects*: Exchanges the contents of x and y as if by:bool b = x;
x = y;
y = b;
[🔗](#vector.bool.pspc-itemdecl:3)
`template<class Allocator> struct hash<vector<bool, Allocator>>;
`
[7](#vector.bool.pspc-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10621)
The specialization is enabled ([[unord.hash]](unord.hash "22.10.19Class template hash"))[.](#vector.bool.pspc-7.sentence-1)
[🔗](#lib:is-vector-bool-reference)
`template<class T>
constexpr bool is-vector-bool-reference = see below;
`
[8](#vector.bool.pspc-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10632)
The expression*is-vector-bool-reference*<T> is true if T denotes the type vector<bool, Alloc>::reference for some type Alloc andvector<bool, Alloc> is not a program-defined specialization[.](#vector.bool.pspc-8.sentence-1)
#### [23.3.14.2](#vector.bool.fmt) Formatter specialization for vector<bool> [[vector.bool.fmt]](vector.bool.fmt)
[🔗](#lib:formatter)
namespace std {template<class T, class charT>requires *is-vector-bool-reference*<T>struct formatter<T, charT> {private: formatter<bool, charT> *underlying_*; // *exposition only*public:template<class ParseContext>constexpr typename ParseContext::iterator
parse(ParseContext& ctx); template<class FormatContext>typename FormatContext::iterator
format(const T& ref, FormatContext& ctx) const; };}
[🔗](#lib:parse,formatter)
`template<class ParseContext>
constexpr typename ParseContext::iterator
parse(ParseContext& ctx);
`
[1](#vector.bool.fmt-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10671)
Equivalent to: return *underlying_*.parse(ctx);
[🔗](#lib:format,formatter)
`template<class FormatContext>
typename FormatContext::iterator
format(const T& ref, FormatContext& ctx) const;
`
[2](#vector.bool.fmt-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10683)
Equivalent to: return *underlying_*.format(ref, ctx);
### [23.3.15](#inplace.vector.syn) Header <inplace_vector> synopsis [[inplace.vector.syn]](inplace.vector.syn)
[🔗](#header:%3cinplace_vector%3e)
// mostly freestanding#include <compare> // see [[compare.syn]](compare.syn "17.12.1Header <compare> synopsis")#include <initializer_list> // see [[initializer.list.syn]](initializer.list.syn "17.11.2Header <initializer_­list> synopsis")namespace std {// [[inplace.vector]](#inplace.vector "23.3.16Class template inplace_­vector"), class template inplace_vectortemplate<class T, size_t N> class inplace_vector; // partially freestanding// [[inplace.vector.erasure]](#inplace.vector.erasure "23.3.16.6Erasure"), erasuretemplate<class T, size_t N, class U = T>constexpr typename inplace_vector<T, N>::size_type
erase(inplace_vector<T, N>& c, const U& value); template<class T, size_t N, class Predicate>constexpr typename inplace_vector<T, N>::size_type
erase_if(inplace_vector<T, N>& c, Predicate pred);}
### [23.3.16](#inplace.vector) Class template inplace_vector [[inplace.vector]](inplace.vector)
#### [23.3.16.1](#inplace.vector.overview) Overview [[inplace.vector.overview]](inplace.vector.overview)
[1](#inplace.vector.overview-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10713)
An inplace_vector is a contiguous container[.](#inplace.vector.overview-1.sentence-1)
Its capacity is fixed and
its elements are stored within the inplace_vector object itself[.](#inplace.vector.overview-1.sentence-2)
[2](#inplace.vector.overview-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10719)
An inplace_vector 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 a contiguous container, and
of a sequence container,
including most of the optional sequence container requirements ([[sequence.reqmts]](sequence.reqmts "23.2.4Sequence containers"))[.](#inplace.vector.overview-2.sentence-1)
The exceptions are thepush_front,prepend_range,pop_front, andemplace_front member functions, which are not provided[.](#inplace.vector.overview-2.sentence-2)
Descriptions are provided here only
for operations on inplace_vector that
are not described in one of these tables or
for operations where there is additional semantic information[.](#inplace.vector.overview-2.sentence-3)
[3](#inplace.vector.overview-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10737)
For any N,inplace_vector<T, N>::iterator andinplace_vector<T, N>::const_iterator meet the constexpr iterator requirements[.](#inplace.vector.overview-3.sentence-1)
[4](#inplace.vector.overview-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10743)
Any member function of inplace_vector<T, N> that
would cause the size to exceed N throws an exception of type bad_alloc[.](#inplace.vector.overview-4.sentence-1)
[5](#inplace.vector.overview-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10748)
Let IV denote a specialization of inplace_vector<T, N>[.](#inplace.vector.overview-5.sentence-1)
If N is zero, thenIV is trivially copyable and empty, andstd::is_trivially_default_constructible_v<IV> is true[.](#inplace.vector.overview-5.sentence-2)
Otherwise:
- [(5.1)](#inplace.vector.overview-5.1)
If is_trivially_copy_constructible_v<T> is true, thenIV has a trivial copy constructor[.](#inplace.vector.overview-5.1.sentence-1)
- [(5.2)](#inplace.vector.overview-5.2)
If is_trivially_move_constructible_v<T> is true, thenIV has a trivial move constructor[.](#inplace.vector.overview-5.2.sentence-1)
- [(5.3)](#inplace.vector.overview-5.3)
If is_trivially_destructible_v<T> is true, then:
* [(5.3.1)](#inplace.vector.overview-5.3.1)
IV has a trivial destructor.
* [(5.3.2)](#inplace.vector.overview-5.3.2)
If is_trivially_copy_constructible_v<T> && is_trivially_copy_assignable_v<T> is true, then IV has a trivial copy assignment operator.
* [(5.3.3)](#inplace.vector.overview-5.3.3)
If is_trivially_move_constructible_v<T> && is_trivially_move_assignable_v<T> is true, then IV has a trivial move assignment operator.
namespace std {template<class T, size_t N>class inplace_vector {public:// types:using value_type = T; using pointer = T*; using const_pointer = const T*; using reference = value_type&; using const_reference = const value_type&; using size_type = size_t; using difference_type = ptrdiff_t; 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>; // [[inplace.vector.cons]](#inplace.vector.cons "23.3.16.2Constructors"), construct/copy/destroyconstexpr inplace_vector() noexcept; constexpr explicit inplace_vector(size_type n); // freestanding-deletedconstexpr inplace_vector(size_type n, const T& value); // freestanding-deletedtemplate<class InputIterator>constexpr inplace_vector(InputIterator first, InputIterator last); // freestanding-deletedtemplate<[*container-compatible-range*](container.intro.reqmts#concept:container-compatible-range "23.2.2.1Introduction[container.intro.reqmts]")<T> R>constexpr inplace_vector(from_range_t, R&& rg); // freestanding-deletedconstexpr inplace_vector(const inplace_vector&); constexpr inplace_vector(inplace_vector&&)noexcept(N == 0 || is_nothrow_move_constructible_v<T>); constexpr inplace_vector(initializer_list<T> il); // freestanding-deletedconstexpr ~inplace_vector(); constexpr inplace_vector& operator=(const inplace_vector& other); constexpr inplace_vector& operator=(inplace_vector&& other)noexcept(N == 0 || (is_nothrow_move_assignable_v<T> && is_nothrow_move_constructible_v<T>)); constexpr inplace_vector& operator=(initializer_list<T>); // freestanding-deletedtemplate<class InputIterator>constexpr void assign(InputIterator first, InputIterator last); // freestanding-deletedtemplate<[*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); // freestanding-deletedconstexpr void assign(size_type n, const T& u); // freestanding-deletedconstexpr void assign(initializer_list<T> il); // freestanding-deleted// 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; // [[inplace.vector.capacity]](#inplace.vector.capacity "23.3.16.3Capacity"), capacityconstexpr bool empty() const noexcept; constexpr size_type size() const noexcept; static constexpr size_type max_size() noexcept; static constexpr size_type capacity() noexcept; constexpr void resize(size_type sz); // freestanding-deletedconstexpr void resize(size_type sz, const T& c); // freestanding-deletedstatic constexpr void reserve(size_type n); // freestanding-deletedstatic constexpr void shrink_to_fit() noexcept; // element accessconstexpr reference operator[](size_type n); constexpr const_reference operator[](size_type n) const; constexpr reference at(size_type n); // freestanding-deletedconstexpr const_reference at(size_type n) const; // freestanding-deletedconstexpr reference front(); constexpr const_reference front() const; constexpr reference back(); constexpr const_reference back() const; // [[inplace.vector.data]](#inplace.vector.data "23.3.16.4Data"), data accessconstexpr T* data() noexcept; constexpr const T* data() const noexcept; // [[inplace.vector.modifiers]](#inplace.vector.modifiers "23.3.16.5Modifiers"), modifierstemplate<class... Args>constexpr reference emplace_back(Args&&... args); // freestanding-deletedconstexpr reference push_back(const T& x); // freestanding-deletedconstexpr reference push_back(T&& x); // freestanding-deletedtemplate<[*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); // freestanding-deletedconstexpr void pop_back(); template<class... Args>constexpr pointer try_emplace_back(Args&&... args); constexpr pointer try_push_back(const T& x); constexpr pointer try_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 ranges::borrowed_iterator_t<R> try_append_range(R&& rg); template<class... Args>constexpr reference unchecked_emplace_back(Args&&... args); constexpr reference unchecked_push_back(const T& x); constexpr reference unchecked_push_back(T&& x); template<class... Args>constexpr iterator emplace(const_iterator position, Args&&... args); // freestanding-deletedconstexpr iterator insert(const_iterator position, const T& x); // freestanding-deletedconstexpr iterator insert(const_iterator position, T&& x); // freestanding-deletedconstexpr iterator insert(const_iterator position, size_type n, // freestanding-deletedconst T& x); template<class InputIterator>constexpr iterator insert(const_iterator position, // freestanding-deleted 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); // freestanding-deletedconstexpr iterator insert(const_iterator position, // freestanding-deleted initializer_list<T> il); constexpr iterator erase(const_iterator position); constexpr iterator erase(const_iterator first, const_iterator last); constexpr void swap(inplace_vector& x)noexcept(N == 0 || (is_nothrow_swappable_v<T> && is_nothrow_move_constructible_v<T>)); constexpr void clear() noexcept; friend constexpr bool operator==(const inplace_vector& x, const inplace_vector& y); friend constexpr *synth-three-way-result*<T>operator<=>(const inplace_vector& x, const inplace_vector& y); friend constexpr void swap(inplace_vector& x, inplace_vector& y)noexcept(N == 0 || (is_nothrow_swappable_v<T> && is_nothrow_move_constructible_v<T>)){ x.swap(y); }};}
#### [23.3.16.2](#inplace.vector.cons) Constructors [[inplace.vector.cons]](inplace.vector.cons)
[🔗](#lib:inplace_vector,constructor)
`constexpr explicit inplace_vector(size_type n);
`
[1](#inplace.vector.cons-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10926)
*Preconditions*: T is *Cpp17DefaultInsertable* into inplace_vector[.](#inplace.vector.cons-1.sentence-1)
[2](#inplace.vector.cons-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10930)
*Effects*: Constructs an inplace_vector with n default-inserted elements[.](#inplace.vector.cons-2.sentence-1)
[3](#inplace.vector.cons-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10934)
*Complexity*: Linear in n[.](#inplace.vector.cons-3.sentence-1)
[🔗](#lib:inplace_vector,constructor_)
`constexpr inplace_vector(size_type n, const T& value);
`
[4](#inplace.vector.cons-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10945)
*Preconditions*: T is *Cpp17CopyInsertable* into inplace_vector[.](#inplace.vector.cons-4.sentence-1)
[5](#inplace.vector.cons-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10949)
*Effects*: Constructs an inplace_vector with n copies of value[.](#inplace.vector.cons-5.sentence-1)
[6](#inplace.vector.cons-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10953)
*Complexity*: Linear in n[.](#inplace.vector.cons-6.sentence-1)
[🔗](#lib:inplace_vector,constructor__)
`template<class InputIterator>
constexpr inplace_vector(InputIterator first, InputIterator last);
`
[7](#inplace.vector.cons-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10965)
*Effects*: Constructs an inplace_vector equal to the range [first, last)[.](#inplace.vector.cons-7.sentence-1)
[8](#inplace.vector.cons-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10969)
*Complexity*: Linear in distance(first, last)[.](#inplace.vector.cons-8.sentence-1)
[🔗](#lib:inplace_vector,constructor___)
`template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1Introduction[container.intro.reqmts]")<T> R>
constexpr inplace_vector(from_range_t, R&& rg);
`
[9](#inplace.vector.cons-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10981)
*Effects*: Constructs an inplace_vector with
the elements of the range rg[.](#inplace.vector.cons-9.sentence-1)
[10](#inplace.vector.cons-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10986)
*Complexity*: Linear in ranges::distance(rg)[.](#inplace.vector.cons-10.sentence-1)
#### [23.3.16.3](#inplace.vector.capacity) Capacity [[inplace.vector.capacity]](inplace.vector.capacity)
[🔗](#lib:capacity,inplace_vector)
`static constexpr size_type capacity() noexcept;
static constexpr size_type max_size() noexcept;
`
[1](#inplace.vector.capacity-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11001)
*Returns*: N[.](#inplace.vector.capacity-1.sentence-1)
[🔗](#lib:resize,inplace_vector)
`constexpr void resize(size_type sz);
`
[2](#inplace.vector.capacity-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11012)
*Preconditions*: T is *Cpp17DefaultInsertable* into inplace_vector[.](#inplace.vector.capacity-2.sentence-1)
[3](#inplace.vector.capacity-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11016)
*Effects*: If sz < size(),
erases the last size() - sz elements from the sequence[.](#inplace.vector.capacity-3.sentence-1)
Otherwise,
appends sz - size() default-inserted elements to the sequence[.](#inplace.vector.capacity-3.sentence-2)
[4](#inplace.vector.capacity-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11024)
*Remarks*: If an exception is thrown, there are no effects on *this[.](#inplace.vector.capacity-4.sentence-1)
[🔗](#lib:resize,inplace_vector_)
`constexpr void resize(size_type sz, const T& c);
`
[5](#inplace.vector.capacity-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11035)
*Preconditions*: T is *Cpp17CopyInsertable* into inplace_vector[.](#inplace.vector.capacity-5.sentence-1)
[6](#inplace.vector.capacity-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11039)
*Effects*: If sz < size(),
erases the last size() - sz elements from the sequence[.](#inplace.vector.capacity-6.sentence-1)
Otherwise,
appends sz - size() copies of c to the sequence[.](#inplace.vector.capacity-6.sentence-2)
[7](#inplace.vector.capacity-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11047)
*Remarks*: If an exception is thrown, there are no effects on *this[.](#inplace.vector.capacity-7.sentence-1)
[🔗](#lib:reserve,inplace_vector)
`static constexpr void reserve(size_type n);
`
[8](#inplace.vector.capacity-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11058)
*Effects*: None[.](#inplace.vector.capacity-8.sentence-1)
[9](#inplace.vector.capacity-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11062)
*Throws*: bad_alloc if n > capacity() is true[.](#inplace.vector.capacity-9.sentence-1)
[🔗](#lib:shrink_to_fit,inplace_vector)
`static constexpr void shrink_to_fit() noexcept;
`
[10](#inplace.vector.capacity-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11073)
*Effects*: None[.](#inplace.vector.capacity-10.sentence-1)
#### [23.3.16.4](#inplace.vector.data) Data [[inplace.vector.data]](inplace.vector.data)
[🔗](#lib:data,inplace_vector)
`constexpr T* data() noexcept;
constexpr const T* data() const noexcept;
`
[1](#inplace.vector.data-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11087)
*Returns*: A pointer such that [data(), data() + size()) is a valid range[.](#inplace.vector.data-1.sentence-1)
For a non-empty inplace_vector,data() == addressof(front()) is true[.](#inplace.vector.data-1.sentence-2)
[2](#inplace.vector.data-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11093)
*Complexity*: Constant time[.](#inplace.vector.data-2.sentence-1)
#### [23.3.16.5](#inplace.vector.modifiers) Modifiers [[inplace.vector.modifiers]](inplace.vector.modifiers)
[🔗](#lib:insert,inplace_vector)
`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);
template<class... Args>
constexpr iterator emplace(const_iterator position, Args&&... args);
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](#inplace.vector.modifiers-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11121)
Let n be the value of size() before this call for
the append_range overload, anddistance(begin, position) otherwise[.](#inplace.vector.modifiers-1.sentence-1)
[2](#inplace.vector.modifiers-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11126)
*Complexity*: Linear in the number of elements inserted plus
the distance to the end of the vector[.](#inplace.vector.modifiers-2.sentence-1)
[3](#inplace.vector.modifiers-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11131)
*Remarks*: If an exception is thrown other than by the
copy constructor,
move constructor,
assignment operator, or
move assignment operator
of T or by
any InputIterator operation,
there are no effects[.](#inplace.vector.modifiers-3.sentence-1)
Otherwise,
if an exception is thrown, thensize() ≥ n and
elements in the range begin() + [0, n) are not modified[.](#inplace.vector.modifiers-3.sentence-2)
[🔗](#lib:push_back,inplace_vector)
`constexpr reference push_back(const T& x);
constexpr reference push_back(T&& x);
template<class... Args>
constexpr reference emplace_back(Args&&... args);
`
[4](#inplace.vector.modifiers-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11157)
*Returns*: back()[.](#inplace.vector.modifiers-4.sentence-1)
[5](#inplace.vector.modifiers-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11161)
*Throws*: bad_alloc or
any exception thrown by the initialization of the inserted element[.](#inplace.vector.modifiers-5.sentence-1)
[6](#inplace.vector.modifiers-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11166)
*Complexity*: Constant[.](#inplace.vector.modifiers-6.sentence-1)
[7](#inplace.vector.modifiers-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11170)
*Remarks*: If an exception is thrown, there are no effects on *this[.](#inplace.vector.modifiers-7.sentence-1)
[🔗](#lib:try_emplace_back,inplace_vector)
`template<class... Args>
constexpr pointer try_emplace_back(Args&&... args);
constexpr pointer try_push_back(const T& x);
constexpr pointer try_push_back(T&& x);
`
[8](#inplace.vector.modifiers-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11185)
Let vals denote a pack:
- [(8.1)](#inplace.vector.modifiers-8.1)
std::forward<Args>(args)... for the first overload,
- [(8.2)](#inplace.vector.modifiers-8.2)
x for the second overload,
- [(8.3)](#inplace.vector.modifiers-8.3)
std::move(x) for the third overload[.](#inplace.vector.modifiers-8.sentence-1)
[9](#inplace.vector.modifiers-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11193)
*Preconditions*: value_type is *Cpp17EmplaceConstructible* into inplace_vector from vals...[.](#inplace.vector.modifiers-9.sentence-1)
[10](#inplace.vector.modifiers-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11198)
*Effects*: If size() < capacity() is true,
appends an object of type T direct-non-list-initialized with vals...[.](#inplace.vector.modifiers-10.sentence-1)
Otherwise, there are no effects[.](#inplace.vector.modifiers-10.sentence-2)
[11](#inplace.vector.modifiers-11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11205)
*Returns*: nullptr if size() == capacity() is true,
otherwise addressof(back())[.](#inplace.vector.modifiers-11.sentence-1)
[12](#inplace.vector.modifiers-12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11210)
*Throws*: Nothing unless an exception is thrown by the initialization of the inserted element[.](#inplace.vector.modifiers-12.sentence-1)
[13](#inplace.vector.modifiers-13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11214)
*Complexity*: Constant[.](#inplace.vector.modifiers-13.sentence-1)
[14](#inplace.vector.modifiers-14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11218)
*Remarks*: If an exception is thrown, there are no effects on *this[.](#inplace.vector.modifiers-14.sentence-1)
[🔗](#lib:try_append_range,inplace_vector)
`template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1Introduction[container.intro.reqmts]")<T> R>
constexpr ranges::borrowed_iterator_t<R> try_append_range(R&& rg);
`
[15](#inplace.vector.modifiers-15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11230)
*Preconditions*: value_type is *Cpp17EmplaceConstructible* into inplace_vector from
*ranges::begin(rg)[.](#inplace.vector.modifiers-15.sentence-2)
[16](#inplace.vector.modifiers-16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11235)
*Effects*: Appends copies of initial elements in rg before end(),
until all elements are inserted or size() == capacity() is true[.](#inplace.vector.modifiers-16.sentence-1)
Each iterator in the range rg is dereferenced at most once[.](#inplace.vector.modifiers-16.sentence-2)
[17](#inplace.vector.modifiers-17)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11241)
*Returns*: An iterator pointing to the first element of rg that was not inserted into *this,
or ranges::end(rg) if no such element exists[.](#inplace.vector.modifiers-17.sentence-1)
[18](#inplace.vector.modifiers-18)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11247)
*Complexity*: Linear in the number of elements inserted[.](#inplace.vector.modifiers-18.sentence-1)
[19](#inplace.vector.modifiers-19)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11251)
*Remarks*: Let n be the value of size() prior to this call[.](#inplace.vector.modifiers-19.sentence-1)
If an exception is thrown after the insertion of k elements, thensize() equals n+k,
elements in the range begin() + [0, n) are not modified, and
elements in the range begin() + [n, n+k) correspond to
the inserted elements[.](#inplace.vector.modifiers-19.sentence-2)
[🔗](#lib:unchecked_emplace_back,inplace_vector)
`template<class... Args>
constexpr reference unchecked_emplace_back(Args&&... args);
`
[20](#inplace.vector.modifiers-20)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11268)
*Preconditions*: size() < capacity() is true[.](#inplace.vector.modifiers-20.sentence-1)
[21](#inplace.vector.modifiers-21)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11272)
*Effects*: Equivalent to:return *try_emplace_back(std::forward<Args>(args)...);
[🔗](#lib:unchecked_push_back,inplace_vector)
`constexpr reference unchecked_push_back(const T& x);
constexpr reference unchecked_push_back(T&& x);
`
[22](#inplace.vector.modifiers-22)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11285)
*Preconditions*: size() < capacity() is true[.](#inplace.vector.modifiers-22.sentence-1)
[23](#inplace.vector.modifiers-23)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11289)
*Effects*: Equivalent to:return *try_push_back(std::forward<decltype(x)>(x));
[🔗](#lib:erase,inplace_vector)
`constexpr iterator erase(const_iterator position);
constexpr iterator erase(const_iterator first, const_iterator last);
constexpr void pop_back();
`
[24](#inplace.vector.modifiers-24)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11304)
*Effects*: Invalidates iterators and references at or after the point of the erase[.](#inplace.vector.modifiers-24.sentence-1)
[25](#inplace.vector.modifiers-25)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11308)
*Throws*: Nothing unless an exception is thrown by
the assignment operator or move assignment operator of T[.](#inplace.vector.modifiers-25.sentence-1)
[26](#inplace.vector.modifiers-26)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11313)
*Complexity*: The destructor of T is called the number of times
equal to the number of the elements erased, but
the assignment operator of T is called the number of times
equal to the number of elements after the erased elements[.](#inplace.vector.modifiers-26.sentence-1)
#### [23.3.16.6](#inplace.vector.erasure) Erasure [[inplace.vector.erasure]](inplace.vector.erasure)
[🔗](#lib:erase,inplace_vector_)
`template<class T, size_t N, class U = T>
constexpr size_t erase(inplace_vector<T, N>& c, const U& value);
`
[1](#inplace.vector.erasure-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11330)
*Effects*: Equivalent to:auto it = remove(c.begin(), c.end(), value);auto r = distance(it, c.end());
c.erase(it, c.end());return r;
[🔗](#lib:erase_if,inplace_vector)
`template<class T, size_t N, class Predicate>
constexpr size_t erase_if(inplace_vector<T, N>& c, Predicate pred);
`
[2](#inplace.vector.erasure-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11348)
*Effects*: Equivalent to:auto it = remove_if(c.begin(), c.end(), pred);auto r = distance(it, c.end());
c.erase(it, c.end());return r;