[vector] # 23 Containers library [[containers]](./#containers) ## 23.3 Sequence containers [[sequences]](sequences#vector) ### 23.3.13 Class template vector [vector] #### [23.3.13.1](#overview) Overview [[vector.overview]](vector.overview) [1](#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[.](#overview-1.sentence-1) Storage management is handled automatically, though hints can be given to improve efficiency[.](#overview-1.sentence-2) [2](#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.2 Container requirements")), of a reversible container ([[container.rev.reqmts]](container.rev.reqmts "23.2.2.3 Reversible container requirements")), of an allocator-aware container ([[container.alloc.reqmts]](container.alloc.reqmts "23.2.2.5 Allocator-aware containers")), of a sequence container, including most of the optional sequence container requirements ([[sequence.reqmts]](sequence.reqmts "23.2.4 Sequence containers")), and, for an element type other than bool, of a [contiguous container](container.reqmts#def:container,contiguous "23.2.2.2 Container requirements [container.reqmts]")[.](#overview-2.sentence-1) The exceptions are thepush_front, prepend_range, pop_front, and emplace_front member functions, which are not provided[.](#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[.](#overview-2.sentence-3) [3](#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.1 General"))[.](#overview-3.sentence-1) namespace std {template>class vector {public:// typesusing value_type = T; using allocator_type = Allocator; using pointer = typename allocator_traits::pointer; using const_pointer = typename allocator_traits::const_pointer; using reference = value_type&; using const_reference = const value_type&; using size_type = *implementation-defined*; // see [[container.requirements]](container.requirements "23.2 Requirements")using difference_type = *implementation-defined*; // see [[container.requirements]](container.requirements "23.2 Requirements")using iterator = *implementation-defined*; // see [[container.requirements]](container.requirements "23.2 Requirements")using const_iterator = *implementation-defined*; // see [[container.requirements]](container.requirements "23.2 Requirements")using reverse_iterator = std::reverse_iterator; using const_reverse_iterator = std::reverse_iterator; // [[vector.cons]](#cons "23.3.13.2 Constructors"), 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()); templateconstexpr vector(InputIterator first, InputIterator last, const Allocator& = Allocator()); template<[*container-compatible-range*](container.intro.reqmts#concept:container-compatible-range "23.2.2.1 Introduction [container.intro.reqmts]") 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&); constexpr vector(vector&&, const type_identity_t&); constexpr vector(initializer_list, const Allocator& = Allocator()); constexpr ~vector(); constexpr vector& operator=(const vector& x); constexpr vector& operator=(vector&& x)noexcept(allocator_traits::propagate_on_container_move_assignment::value || allocator_traits::is_always_equal::value); constexpr vector& operator=(initializer_list); templateconstexpr void assign(InputIterator first, InputIterator last); template<[*container-compatible-range*](container.intro.reqmts#concept:container-compatible-range "23.2.2.1 Introduction [container.intro.reqmts]") R>constexpr void assign_range(R&& rg); constexpr void assign(size_type n, const T& u); constexpr void assign(initializer_list); 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]](#capacity "23.3.13.3 Capacity"), 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]](#data "23.3.13.4 Data"), data accessconstexpr T* data() noexcept; constexpr const T* data() const noexcept; // [[vector.modifiers]](#modifiers "23.3.13.5 Modifiers"), modifierstemplate 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.1 Introduction [container.intro.reqmts]") R>constexpr void append_range(R&& rg); constexpr void pop_back(); template 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); templateconstexpr iterator insert(const_iterator position, InputIterator first, InputIterator last); template<[*container-compatible-range*](container.intro.reqmts#concept:container-compatible-range "23.2.2.1 Introduction [container.intro.reqmts]") R>constexpr iterator insert_range(const_iterator position, R&& rg); constexpr iterator insert(const_iterator position, initializer_list il); constexpr iterator erase(const_iterator position); constexpr iterator erase(const_iterator first, const_iterator last); constexpr void swap(vector&)noexcept(allocator_traits::propagate_on_container_swap::value || allocator_traits::is_always_equal::value); constexpr void clear() noexcept; }; template>> vector(InputIterator, InputIterator, Allocator = Allocator())-> vector<*iter-value-type*, Allocator>; template>> vector(from_range_t, R&&, Allocator = Allocator())-> vector, Allocator>;} [4](#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.2 Allocator completeness requirements [allocator.requirements.completeness]")[.](#overview-4.sentence-1) T shall be complete before any member of the resulting specialization of vector is referenced[.](#overview-4.sentence-2) #### [23.3.13.2](#cons) Constructors [[vector.cons]](vector.cons) [🔗](#lib:vector,constructor) `constexpr explicit vector(const Allocator&) noexcept; ` [1](#cons-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9992) *Effects*: Constructs an empty vector, using the specified allocator[.](#cons-1.sentence-1) [2](#cons-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9997) *Complexity*: Constant[.](#cons-2.sentence-1) [🔗](#lib:vector,constructor_) `constexpr explicit vector(size_type n, const Allocator& = Allocator()); ` [3](#cons-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10008) *Preconditions*: T is *Cpp17DefaultInsertable* into vector[.](#cons-3.sentence-1) [4](#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[.](#cons-4.sentence-1) [5](#cons-5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10017) *Complexity*: Linear in n[.](#cons-5.sentence-1) [🔗](#lib:vector,constructor__) `constexpr vector(size_type n, const T& value, const Allocator& = Allocator()); ` [6](#cons-6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10029) *Preconditions*: T is*Cpp17CopyInsertable* into vector[.](#cons-6.sentence-1) [7](#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[.](#cons-7.sentence-1) [8](#cons-8) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10039) *Complexity*: Linear in n[.](#cons-8.sentence-1) [🔗](#lib:vector,constructor___) `template constexpr vector(InputIterator first, InputIterator last, const Allocator& = Allocator()); ` [9](#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[.](#cons-9.sentence-1) [10](#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[.](#cons-10.sentence-1) It makes orderN calls to the copy constructor ofT and orderlogN reallocations if they are just input iterators[.](#cons-10.sentence-2) [🔗](#lib:vector,constructor____) `template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1 Introduction [container.intro.reqmts]") R> constexpr vector(from_range_t, R&& rg, const Allocator& = Allocator()); ` [11](#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[.](#cons-11.sentence-1) [12](#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)[.](#cons-12.sentence-1) [13](#cons-13) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10096) Performs no reallocations if: - [(13.1)](#cons-13.1) R models ranges​::​[approximately_sized_range](range.approximately.sized#concept:approximately_sized_range "25.4.3 Approximately sized ranges [range.approximately.sized]"), andranges​::​distance(rg) <= ranges​::​reserve_hint(rg) is true, or - [(13.2)](#cons-13.2) R models ranges​::​[forward_range](range.refinements#concept:forward_range "25.4.6 Other range refinements [range.refinements]") andR does not model ranges​::​[approximately_sized_range](range.approximately.sized#concept:approximately_sized_range "25.4.3 Approximately sized ranges [range.approximately.sized]")[.](#cons-13.sentence-1) Otherwise, performs order logN reallocations and order N calls to the copy or move constructor of T[.](#cons-13.sentence-2) #### [23.3.13.3](#capacity) Capacity [[vector.capacity]](vector.capacity) [🔗](#lib:capacity,vector) `constexpr size_type capacity() const noexcept; ` [1](#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[.](#capacity-1.sentence-1) [2](#capacity-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10123) *Complexity*: Constant time[.](#capacity-2.sentence-1) [🔗](#lib:reserve,vector) `constexpr void reserve(size_type n); ` [3](#capacity-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10134) *Preconditions*: T is *Cpp17MoveInsertable* into vector[.](#capacity-3.sentence-1) [4](#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[.](#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[.](#capacity-4.sentence-2) Reallocation happens at this point if and only if the current capacity is less than the argument ofreserve()[.](#capacity-4.sentence-3) If an exception is thrown other than by the move constructor of a non-*Cpp17CopyInsertable* type, there are no effects[.](#capacity-4.sentence-4) [5](#capacity-5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10157) *Throws*: length_error if n > max_size()[.](#capacity-5.sentence-1)[197](#footnote-197 "reserve() uses Allocator​::​allocate() which can throw an appropriate exception.") [6](#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[.](#capacity-6.sentence-1) [7](#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[.](#capacity-7.sentence-1) [*Note [1](#capacity-note-1)*: If no reallocation happens, they remain valid[.](#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()[.](#capacity-7.sentence-3) [🔗](#lib:shrink_to_fit,vector) `constexpr void shrink_to_fit(); ` [8](#capacity-8) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10190) *Preconditions*: T is *Cpp17MoveInsertable* into vector[.](#capacity-8.sentence-1) [9](#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()[.](#capacity-9.sentence-1) [*Note [2](#capacity-note-2)*: The request is non-binding to allow latitude for implementation-specific optimizations[.](#capacity-9.sentence-2) — *end note*] It does not increase capacity(), but may reduce capacity() by causing reallocation[.](#capacity-9.sentence-3) If an exception is thrown other than by the move constructor of a non-*Cpp17CopyInsertable* T, there are no effects[.](#capacity-9.sentence-4) [10](#capacity-10) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10207) *Complexity*: If reallocation happens, linear in the size of the sequence[.](#capacity-10.sentence-1) [11](#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[.](#capacity-11.sentence-1) [*Note [3](#capacity-note-3)*: If no reallocation happens, they remain valid[.](#capacity-11.sentence-2) — *end note*] [🔗](#lib:swap,vector) `constexpr void swap(vector& x) noexcept(allocator_traits::propagate_on_container_swap::value || allocator_traits::is_always_equal::value); ` [12](#capacity-12) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10229) *Effects*: Exchanges the contents andcapacity() of*this with that of x[.](#capacity-12.sentence-1) [13](#capacity-13) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10237) *Complexity*: Constant time[.](#capacity-13.sentence-1) [🔗](#lib:resize,vector) `constexpr void resize(size_type sz); ` [14](#capacity-14) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10248) *Preconditions*: T is*Cpp17MoveInsertable* and *Cpp17DefaultInsertable* into vector[.](#capacity-14.sentence-1) [15](#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[.](#capacity-15.sentence-1) Otherwise, appends sz - size() default-inserted elements to the sequence[.](#capacity-15.sentence-2) [16](#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[.](#capacity-16.sentence-1) [🔗](#lib:resize,vector_) `constexpr void resize(size_type sz, const T& c); ` [17](#capacity-17) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10271) *Preconditions*: T is*Cpp17CopyInsertable* into vector[.](#capacity-17.sentence-1) [18](#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[.](#capacity-18.sentence-1) Otherwise, appends sz - size() copies of c to the sequence[.](#capacity-18.sentence-2) [19](#capacity-19) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10282) *Remarks*: If an exception is thrown, there are no effects[.](#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](#data) Data [[vector.data]](vector.data) [🔗](#lib:data,vector) `constexpr T* data() noexcept; constexpr const T* data() const noexcept; ` [1](#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[.](#data-1.sentence-1) For a non-empty vector, data() == addressof(front()) is true[.](#data-1.sentence-2) [2](#data-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10301) *Complexity*: Constant time[.](#data-2.sentence-1) #### [23.3.13.5](#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 constexpr iterator insert(const_iterator position, InputIterator first, InputIterator last); template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1 Introduction [container.intro.reqmts]") R> constexpr iterator insert_range(const_iterator position, R&& rg); constexpr iterator insert(const_iterator position, initializer_list); template constexpr reference emplace_back(Args&&... args); template 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.1 Introduction [container.intro.reqmts]") R> constexpr void append_range(R&& rg); ` [1](#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[.](#modifiers-1.sentence-1) [2](#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[.](#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[.](#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[.](#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[.](#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 is true, there are no effects[.](#modifiers-2.sentence-5) Otherwise, if an exception is thrown by the move constructor of a non-*Cpp17CopyInsertable*T, the effects are unspecified[.](#modifiers-2.sentence-6) [3](#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)](#modifiers-3.1) R models ranges​::​[approximately_sized_range](range.approximately.sized#concept:approximately_sized_range "25.4.3 Approximately sized ranges [range.approximately.sized]") andranges​::​distance(rg) <= ranges​::​reserve_hint(rg) is true, or - [(3.2)](#modifiers-3.2) R models ranges​::​[forward_range](range.refinements#concept:forward_range "25.4.6 Other range refinements [range.refinements]") andR does not model ranges​::​[approximately_sized_range](range.approximately.sized#concept:approximately_sized_range "25.4.3 Approximately sized ranges [range.approximately.sized]")[.](#modifiers-3.sentence-1) For the declarations taking a pair of InputIterator, performs at most one reallocation ifInputIterator meets the *Cpp17ForwardIterator* requirements[.](#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](#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[.](#modifiers-4.sentence-1) [5](#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[.](#modifiers-5.sentence-1) [6](#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[.](#modifiers-6.sentence-1) #### [23.3.13.6](#erasure) Erasure [[vector.erasure]](vector.erasure) [🔗](#lib:erase,vector_) `template constexpr typename vector::size_type erase(vector& c, const U& value); ` [1](#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 constexpr typename vector::size_type erase_if(vector& c, Predicate pred); ` [2](#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;