Files
2025-10-25 03:02:53 +03:00

269 lines
8.9 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.

[inplace.vector.modifiers]
# 23 Containers library [[containers]](./#containers)
## 23.3 Sequence containers [[sequences]](sequences#inplace.vector.modifiers)
### 23.3.16 Class template inplace_vector [[inplace.vector]](inplace.vector#modifiers)
#### 23.3.16.5 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](#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[.](#1.sentence-1)
[2](#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[.](#2.sentence-1)
[3](#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[.](#3.sentence-1)
Otherwise,
if an exception is thrown, thensize() ≥ n and
elements in the range begin() + [0, n) are not modified[.](#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](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11157)
*Returns*: back()[.](#4.sentence-1)
[5](#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[.](#5.sentence-1)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11166)
*Complexity*: Constant[.](#6.sentence-1)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11170)
*Remarks*: If an exception is thrown, there are no effects on *this[.](#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](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11185)
Let vals denote a pack:
- [(8.1)](#8.1)
std::forward<Args>(args)... for the first overload,
- [(8.2)](#8.2)
x for the second overload,
- [(8.3)](#8.3)
std::move(x) for the third overload[.](#8.sentence-1)
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11193)
*Preconditions*: value_type is *Cpp17EmplaceConstructible* into inplace_vector from vals...[.](#9.sentence-1)
[10](#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...[.](#10.sentence-1)
Otherwise, there are no effects[.](#10.sentence-2)
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11205)
*Returns*: nullptr if size() == capacity() is true,
otherwise addressof(back())[.](#11.sentence-1)
[12](#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[.](#12.sentence-1)
[13](#13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11214)
*Complexity*: Constant[.](#13.sentence-1)
[14](#14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11218)
*Remarks*: If an exception is thrown, there are no effects on *this[.](#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](#15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11230)
*Preconditions*: value_type is *Cpp17EmplaceConstructible* into inplace_vector from
*ranges::begin(rg)[.](#15.sentence-2)
[16](#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[.](#16.sentence-1)
Each iterator in the range rg is dereferenced at most once[.](#16.sentence-2)
[17](#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[.](#17.sentence-1)
[18](#18)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11247)
*Complexity*: Linear in the number of elements inserted[.](#18.sentence-1)
[19](#19)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11251)
*Remarks*: Let n be the value of size() prior to this call[.](#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[.](#19.sentence-2)
[🔗](#lib:unchecked_emplace_back,inplace_vector)
`template<class... Args>
constexpr reference unchecked_emplace_back(Args&&... args);
`
[20](#20)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11268)
*Preconditions*: size() < capacity() is true[.](#20.sentence-1)
[21](#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](#22)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L11285)
*Preconditions*: size() < capacity() is true[.](#22.sentence-1)
[23](#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](#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[.](#24.sentence-1)
[25](#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[.](#25.sentence-1)
[26](#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[.](#26.sentence-1)