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

114 lines
4.7 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.

[deque.modifiers]
# 23 Containers library [[containers]](./#containers)
## 23.3 Sequence containers [[sequences]](sequences#deque.modifiers)
### 23.3.5 Class template deque [[deque]](deque#modifiers)
#### 23.3.5.4 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](#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[.](#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[.](#1.sentence-2)
[2](#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[.](#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[.](#2.sentence-2)
[3](#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[.](#3.sentence-1)
If an exception is thrown while inserting a single element at either end,
there are no effects[.](#3.sentence-2)
Otherwise, if an exception is thrown by the move constructor of a
non-*Cpp17CopyInsertable*T, the effects are unspecified[.](#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](#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[.](#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[.](#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[.](#4.sentence-3)
[*Note [1](#note-1)*:
pop_front and pop_back are erase operations[.](#4.sentence-4)
— *end note*]
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L6869)
*Throws*: Nothing unless an exception is thrown by the assignment operator ofT[.](#5.sentence-1)
[6](#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[.](#6.sentence-1)