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

8.9 KiB
Raw Blame History

[inplace.vector.modifiers]

23 Containers library [containers]

23.3 Sequence containers [sequences]

23.3.16 Class template inplace_vector [inplace.vector]

23.3.16.5 Modifiers [inplace.vector.modifiers]

🔗

`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 constexpr iterator insert(const_iterator position, InputIterator first, InputIterator last); template<container-compatible-range R> constexpr iterator insert_range(const_iterator position, R&& rg); constexpr iterator insert(const_iterator position, initializer_list il);

template<class... Args> constexpr iterator emplace(const_iterator position, Args&&... args); template<container-compatible-range R> constexpr void append_range(R&& rg); `

1

#

Let n be the value of size() before this call for the append_range overload, anddistance(begin, position) otherwise.

2

#

Complexity: Linear in the number of elements inserted plus the distance to the end of the vector.

3

#

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.

Otherwise, if an exception is thrown, thensize() ≥ n and elements in the range begin() + [0, n) are not modified.

🔗

constexpr reference push_back(const T& x); constexpr reference push_back(T&& x); template<class... Args> constexpr reference emplace_back(Args&&... args);

4

#

Returns: back().

5

#

Throws: bad_alloc or any exception thrown by the initialization of the inserted element.

6

#

Complexity: Constant.

7

#

Remarks: If an exception is thrown, there are no effects on *this.

🔗

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

#

Let vals denote a pack:

std::forward(args)... for the first overload,

x for the second overload,

std::move(x) for the third overload.

9

#

Preconditions: value_type is Cpp17EmplaceConstructible into inplace_vector from vals....

10

#

Effects: If size() < capacity() is true, appends an object of type T direct-non-list-initialized with vals....

Otherwise, there are no effects.

11

#

Returns: nullptr if size() == capacity() is true, otherwise addressof(back()).

12

#

Throws: Nothing unless an exception is thrown by the initialization of the inserted element.

13

#

Complexity: Constant.

14

#

Remarks: If an exception is thrown, there are no effects on *this.

🔗

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

#

Preconditions: value_type is Cpp17EmplaceConstructible into inplace_vector from

*ranges::begin(rg).

16

#

Effects: Appends copies of initial elements in rg before end(), until all elements are inserted or size() == capacity() is true.

Each iterator in the range rg is dereferenced at most once.

17

#

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.

18

#

Complexity: Linear in the number of elements inserted.

19

#

Remarks: Let n be the value of size() prior to this call.

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.

🔗

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

20

#

Preconditions: size() < capacity() is true.

21

#

Effects: Equivalent to:return *try_emplace_back(std::forward(args)...);

🔗

constexpr reference unchecked_push_back(const T& x); constexpr reference unchecked_push_back(T&& x);

22

#

Preconditions: size() < capacity() is true.

23

#

Effects: Equivalent to:return *try_push_back(std::forward<decltype(x)>(x));

🔗

constexpr iterator erase(const_iterator position); constexpr iterator erase(const_iterator first, const_iterator last); constexpr void pop_back();

24

#

Effects: Invalidates iterators and references at or after the point of the erase.

25

#

Throws: Nothing unless an exception is thrown by the assignment operator or move assignment operator of T.

26

#

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.