Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
Louis Dionne | 9bd9388 | 2021-11-17 16:25:01 -0500 | [diff] [blame] | 2 | //===----------------------------------------------------------------------===// |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3 | // |
Chandler Carruth | d201210 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP_VECTOR |
| 11 | #define _LIBCPP_VECTOR |
| 12 | |
| 13 | /* |
| 14 | vector synopsis |
| 15 | |
| 16 | namespace std |
| 17 | { |
| 18 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 19 | template <class T, class Allocator = allocator<T> > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 20 | class vector |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 21 | { |
| 22 | public: |
| 23 | typedef T value_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 24 | typedef Allocator allocator_type; |
| 25 | typedef typename allocator_type::reference reference; |
| 26 | typedef typename allocator_type::const_reference const_reference; |
| 27 | typedef implementation-defined iterator; |
| 28 | typedef implementation-defined const_iterator; |
| 29 | typedef typename allocator_type::size_type size_type; |
| 30 | typedef typename allocator_type::difference_type difference_type; |
| 31 | typedef typename allocator_type::pointer pointer; |
| 32 | typedef typename allocator_type::const_pointer const_pointer; |
| 33 | typedef std::reverse_iterator<iterator> reverse_iterator; |
| 34 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
| 35 | |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 36 | vector() |
| 37 | noexcept(is_nothrow_default_constructible<allocator_type>::value); |
| 38 | explicit vector(const allocator_type&); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 39 | explicit vector(size_type n); |
Marshall Clow | d3cbeaa | 2013-09-14 00:47:59 +0000 | [diff] [blame] | 40 | explicit vector(size_type n, const allocator_type&); // C++14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 41 | vector(size_type n, const value_type& value, const allocator_type& = allocator_type()); |
| 42 | template <class InputIterator> |
| 43 | vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type()); |
| 44 | vector(const vector& x); |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 45 | vector(vector&& x) |
| 46 | noexcept(is_nothrow_move_constructible<allocator_type>::value); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 47 | vector(initializer_list<value_type> il); |
| 48 | vector(initializer_list<value_type> il, const allocator_type& a); |
| 49 | ~vector(); |
| 50 | vector& operator=(const vector& x); |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 51 | vector& operator=(vector&& x) |
| 52 | noexcept( |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 53 | allocator_type::propagate_on_container_move_assignment::value || |
| 54 | allocator_type::is_always_equal::value); // C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 55 | vector& operator=(initializer_list<value_type> il); |
| 56 | template <class InputIterator> |
| 57 | void assign(InputIterator first, InputIterator last); |
| 58 | void assign(size_type n, const value_type& u); |
| 59 | void assign(initializer_list<value_type> il); |
| 60 | |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 61 | allocator_type get_allocator() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 62 | |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 63 | iterator begin() noexcept; |
| 64 | const_iterator begin() const noexcept; |
| 65 | iterator end() noexcept; |
| 66 | const_iterator end() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 67 | |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 68 | reverse_iterator rbegin() noexcept; |
| 69 | const_reverse_iterator rbegin() const noexcept; |
| 70 | reverse_iterator rend() noexcept; |
| 71 | const_reverse_iterator rend() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 72 | |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 73 | const_iterator cbegin() const noexcept; |
| 74 | const_iterator cend() const noexcept; |
| 75 | const_reverse_iterator crbegin() const noexcept; |
| 76 | const_reverse_iterator crend() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 77 | |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 78 | size_type size() const noexcept; |
| 79 | size_type max_size() const noexcept; |
| 80 | size_type capacity() const noexcept; |
| 81 | bool empty() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 82 | void reserve(size_type n); |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 83 | void shrink_to_fit() noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 84 | |
| 85 | reference operator[](size_type n); |
| 86 | const_reference operator[](size_type n) const; |
| 87 | reference at(size_type n); |
| 88 | const_reference at(size_type n) const; |
| 89 | |
| 90 | reference front(); |
| 91 | const_reference front() const; |
| 92 | reference back(); |
| 93 | const_reference back() const; |
| 94 | |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 95 | value_type* data() noexcept; |
| 96 | const value_type* data() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 97 | |
| 98 | void push_back(const value_type& x); |
| 99 | void push_back(value_type&& x); |
| 100 | template <class... Args> |
Marshall Clow | ea52cc4 | 2017-01-24 23:09:12 +0000 | [diff] [blame] | 101 | reference emplace_back(Args&&... args); // reference in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 102 | void pop_back(); |
| 103 | |
| 104 | template <class... Args> iterator emplace(const_iterator position, Args&&... args); |
| 105 | iterator insert(const_iterator position, const value_type& x); |
| 106 | iterator insert(const_iterator position, value_type&& x); |
| 107 | iterator insert(const_iterator position, size_type n, const value_type& x); |
| 108 | template <class InputIterator> |
| 109 | iterator insert(const_iterator position, InputIterator first, InputIterator last); |
| 110 | iterator insert(const_iterator position, initializer_list<value_type> il); |
| 111 | |
| 112 | iterator erase(const_iterator position); |
| 113 | iterator erase(const_iterator first, const_iterator last); |
| 114 | |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 115 | void clear() noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 116 | |
| 117 | void resize(size_type sz); |
| 118 | void resize(size_type sz, const value_type& c); |
| 119 | |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 120 | void swap(vector&) |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 121 | noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value || |
| 122 | allocator_traits<allocator_type>::is_always_equal::value); // C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 123 | |
| 124 | bool __invariants() const; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 125 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 126 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 127 | template <class Allocator = allocator<T> > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 128 | class vector<bool, Allocator> |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 129 | { |
| 130 | public: |
| 131 | typedef bool value_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 132 | typedef Allocator allocator_type; |
| 133 | typedef implementation-defined iterator; |
| 134 | typedef implementation-defined const_iterator; |
| 135 | typedef typename allocator_type::size_type size_type; |
| 136 | typedef typename allocator_type::difference_type difference_type; |
| 137 | typedef iterator pointer; |
| 138 | typedef const_iterator const_pointer; |
| 139 | typedef std::reverse_iterator<iterator> reverse_iterator; |
| 140 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
| 141 | |
| 142 | class reference |
| 143 | { |
| 144 | public: |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 145 | reference(const reference&) noexcept; |
| 146 | operator bool() const noexcept; |
Louis Dionne | d9f528e | 2021-06-29 13:52:26 -0400 | [diff] [blame] | 147 | reference& operator=(bool x) noexcept; |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 148 | reference& operator=(const reference& x) noexcept; |
| 149 | iterator operator&() const noexcept; |
| 150 | void flip() noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 151 | }; |
| 152 | |
| 153 | class const_reference |
| 154 | { |
| 155 | public: |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 156 | const_reference(const reference&) noexcept; |
| 157 | operator bool() const noexcept; |
| 158 | const_iterator operator&() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 159 | }; |
| 160 | |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 161 | vector() |
| 162 | noexcept(is_nothrow_default_constructible<allocator_type>::value); |
Howard Hinnant | c273496 | 2011-09-02 20:42:31 +0000 | [diff] [blame] | 163 | explicit vector(const allocator_type&); |
Marshall Clow | d3cbeaa | 2013-09-14 00:47:59 +0000 | [diff] [blame] | 164 | explicit vector(size_type n, const allocator_type& a = allocator_type()); // C++14 |
| 165 | vector(size_type n, const value_type& value, const allocator_type& = allocator_type()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 166 | template <class InputIterator> |
| 167 | vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type()); |
| 168 | vector(const vector& x); |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 169 | vector(vector&& x) |
| 170 | noexcept(is_nothrow_move_constructible<allocator_type>::value); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 171 | vector(initializer_list<value_type> il); |
| 172 | vector(initializer_list<value_type> il, const allocator_type& a); |
| 173 | ~vector(); |
| 174 | vector& operator=(const vector& x); |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 175 | vector& operator=(vector&& x) |
| 176 | noexcept( |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 177 | allocator_type::propagate_on_container_move_assignment::value || |
| 178 | allocator_type::is_always_equal::value); // C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 179 | vector& operator=(initializer_list<value_type> il); |
| 180 | template <class InputIterator> |
| 181 | void assign(InputIterator first, InputIterator last); |
| 182 | void assign(size_type n, const value_type& u); |
| 183 | void assign(initializer_list<value_type> il); |
| 184 | |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 185 | allocator_type get_allocator() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 186 | |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 187 | iterator begin() noexcept; |
| 188 | const_iterator begin() const noexcept; |
| 189 | iterator end() noexcept; |
| 190 | const_iterator end() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 191 | |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 192 | reverse_iterator rbegin() noexcept; |
| 193 | const_reverse_iterator rbegin() const noexcept; |
| 194 | reverse_iterator rend() noexcept; |
| 195 | const_reverse_iterator rend() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 196 | |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 197 | const_iterator cbegin() const noexcept; |
| 198 | const_iterator cend() const noexcept; |
| 199 | const_reverse_iterator crbegin() const noexcept; |
| 200 | const_reverse_iterator crend() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 201 | |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 202 | size_type size() const noexcept; |
| 203 | size_type max_size() const noexcept; |
| 204 | size_type capacity() const noexcept; |
| 205 | bool empty() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 206 | void reserve(size_type n); |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 207 | void shrink_to_fit() noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 208 | |
| 209 | reference operator[](size_type n); |
| 210 | const_reference operator[](size_type n) const; |
| 211 | reference at(size_type n); |
| 212 | const_reference at(size_type n) const; |
| 213 | |
| 214 | reference front(); |
| 215 | const_reference front() const; |
| 216 | reference back(); |
| 217 | const_reference back() const; |
| 218 | |
| 219 | void push_back(const value_type& x); |
Marshall Clow | ea52cc4 | 2017-01-24 23:09:12 +0000 | [diff] [blame] | 220 | template <class... Args> reference emplace_back(Args&&... args); // C++14; reference in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 221 | void pop_back(); |
| 222 | |
Marshall Clow | c46bb8e | 2013-08-13 23:54:12 +0000 | [diff] [blame] | 223 | template <class... Args> iterator emplace(const_iterator position, Args&&... args); // C++14 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 224 | iterator insert(const_iterator position, const value_type& x); |
| 225 | iterator insert(const_iterator position, size_type n, const value_type& x); |
| 226 | template <class InputIterator> |
| 227 | iterator insert(const_iterator position, InputIterator first, InputIterator last); |
| 228 | iterator insert(const_iterator position, initializer_list<value_type> il); |
| 229 | |
| 230 | iterator erase(const_iterator position); |
| 231 | iterator erase(const_iterator first, const_iterator last); |
| 232 | |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 233 | void clear() noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 234 | |
| 235 | void resize(size_type sz); |
| 236 | void resize(size_type sz, value_type x); |
| 237 | |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 238 | void swap(vector&) |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 239 | noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value || |
| 240 | allocator_traits<allocator_type>::is_always_equal::value); // C++17 |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 241 | void flip() noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 242 | |
| 243 | bool __invariants() const; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 244 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 245 | |
Marshall Clow | f0ca149 | 2018-05-21 21:30:12 +0000 | [diff] [blame] | 246 | template <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>> |
| 247 | vector(InputIterator, InputIterator, Allocator = Allocator()) |
Konstantin Varlamov | 53b543c | 2021-11-09 09:21:02 -0800 | [diff] [blame] | 248 | -> vector<typename iterator_traits<InputIterator>::value_type, Allocator>; // C++17 |
Marshall Clow | f0ca149 | 2018-05-21 21:30:12 +0000 | [diff] [blame] | 249 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 250 | template <class Allocator> struct hash<std::vector<bool, Allocator>>; |
| 251 | |
| 252 | template <class T, class Allocator> bool operator==(const vector<T,Allocator>& x, const vector<T,Allocator>& y); |
| 253 | template <class T, class Allocator> bool operator< (const vector<T,Allocator>& x, const vector<T,Allocator>& y); |
| 254 | template <class T, class Allocator> bool operator!=(const vector<T,Allocator>& x, const vector<T,Allocator>& y); |
| 255 | template <class T, class Allocator> bool operator> (const vector<T,Allocator>& x, const vector<T,Allocator>& y); |
| 256 | template <class T, class Allocator> bool operator>=(const vector<T,Allocator>& x, const vector<T,Allocator>& y); |
| 257 | template <class T, class Allocator> bool operator<=(const vector<T,Allocator>& x, const vector<T,Allocator>& y); |
| 258 | |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 259 | template <class T, class Allocator> |
| 260 | void swap(vector<T,Allocator>& x, vector<T,Allocator>& y) |
| 261 | noexcept(noexcept(x.swap(y))); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 262 | |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 263 | template <class T, class Allocator, class U> |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 264 | typename vector<T, Allocator>::size_type |
| 265 | erase(vector<T, Allocator>& c, const U& value); // C++20 |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 266 | template <class T, class Allocator, class Predicate> |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 267 | typename vector<T, Allocator>::size_type |
| 268 | erase_if(vector<T, Allocator>& c, Predicate pred); // C++20 |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 269 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 270 | } // std |
| 271 | |
| 272 | */ |
| 273 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 274 | #include <__bit_reference> |
Arthur O'Dwyer | 65077c0 | 2022-01-07 09:45:05 -0500 | [diff] [blame] | 275 | #include <__config> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame] | 276 | #include <__debug> |
| 277 | #include <__functional_base> |
Konstantin Varlamov | 53b543c | 2021-11-09 09:21:02 -0800 | [diff] [blame] | 278 | #include <__iterator/iterator_traits.h> |
Louis Dionne | 7724952 | 2021-06-11 09:55:11 -0400 | [diff] [blame] | 279 | #include <__iterator/wrap_iter.h> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame] | 280 | #include <__split_buffer> |
Christopher Di Bella | 41f26e8 | 2021-06-05 02:47:47 +0000 | [diff] [blame] | 281 | #include <__utility/forward.h> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame] | 282 | #include <algorithm> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 283 | #include <climits> |
Arthur O'Dwyer | 7deec12 | 2021-03-24 18:19:12 -0400 | [diff] [blame] | 284 | #include <compare> |
Louis Dionne | d24191c | 2021-08-19 12:39:16 -0400 | [diff] [blame] | 285 | #include <cstdlib> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame] | 286 | #include <cstring> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 287 | #include <initializer_list> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame] | 288 | #include <iosfwd> // for forward declaration of vector |
| 289 | #include <limits> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 290 | #include <memory> |
| 291 | #include <stdexcept> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame] | 292 | #include <type_traits> |
Marshall Clow | 0a1e750 | 2018-09-12 19:41:40 +0000 | [diff] [blame] | 293 | #include <version> |
Howard Hinnant | e6ff0b6 | 2013-08-02 00:26:35 +0000 | [diff] [blame] | 294 | |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 295 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Arthur O'Dwyer | 6eeaa00 | 2022-02-01 20:16:40 -0500 | [diff] [blame] | 296 | # pragma GCC system_header |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 297 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 298 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 299 | _LIBCPP_PUSH_MACROS |
| 300 | #include <__undef_macros> |
| 301 | |
| 302 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 303 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 304 | |
Eric Fiselier | 876c686 | 2016-02-20 00:19:45 +0000 | [diff] [blame] | 305 | template <class _Tp, class _Allocator /* = allocator<_Tp> */> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 306 | class _LIBCPP_TEMPLATE_VIS vector |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 307 | { |
| 308 | private: |
Konstantin Varlamov | f287297 | 2021-12-01 11:55:46 -0800 | [diff] [blame] | 309 | typedef allocator<_Tp> __default_allocator_type; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 310 | public: |
Konstantin Varlamov | f287297 | 2021-12-01 11:55:46 -0800 | [diff] [blame] | 311 | typedef vector __self; |
| 312 | typedef _Tp value_type; |
| 313 | typedef _Allocator allocator_type; |
| 314 | typedef allocator_traits<allocator_type> __alloc_traits; |
| 315 | typedef value_type& reference; |
| 316 | typedef const value_type& const_reference; |
| 317 | typedef typename __alloc_traits::size_type size_type; |
| 318 | typedef typename __alloc_traits::difference_type difference_type; |
| 319 | typedef typename __alloc_traits::pointer pointer; |
| 320 | typedef typename __alloc_traits::const_pointer const_pointer; |
| 321 | typedef __wrap_iter<pointer> iterator; |
| 322 | typedef __wrap_iter<const_pointer> const_iterator; |
| 323 | typedef _VSTD::reverse_iterator<iterator> reverse_iterator; |
| 324 | typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 325 | |
Howard Hinnant | a416ff0 | 2013-03-26 19:04:56 +0000 | [diff] [blame] | 326 | static_assert((is_same<typename allocator_type::value_type, value_type>::value), |
| 327 | "Allocator::value_type must be same type as value_type"); |
| 328 | |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 329 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | e546cbb | 2015-06-04 02:05:41 +0000 | [diff] [blame] | 330 | vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) |
Nikolas Klauser | f280773 | 2022-01-11 00:33:35 +0100 | [diff] [blame] | 331 | { |
| 332 | _VSTD::__debug_db_insert_c(this); |
| 333 | } |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 334 | _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a) |
Marshall Clow | 8f282f4 | 2015-06-04 00:10:20 +0000 | [diff] [blame] | 335 | #if _LIBCPP_STD_VER <= 14 |
| 336 | _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value) |
| 337 | #else |
| 338 | _NOEXCEPT |
| 339 | #endif |
Nikolas Klauser | 129974f | 2022-02-03 23:09:37 +0100 | [diff] [blame] | 340 | : __end_cap_(nullptr, __a) |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 341 | { |
Nikolas Klauser | f280773 | 2022-01-11 00:33:35 +0100 | [diff] [blame] | 342 | _VSTD::__debug_db_insert_c(this); |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 343 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 344 | explicit vector(size_type __n); |
Marshall Clow | d3cbeaa | 2013-09-14 00:47:59 +0000 | [diff] [blame] | 345 | #if _LIBCPP_STD_VER > 11 |
| 346 | explicit vector(size_type __n, const allocator_type& __a); |
| 347 | #endif |
Marshall Clow | f0ca149 | 2018-05-21 21:30:12 +0000 | [diff] [blame] | 348 | vector(size_type __n, const value_type& __x); |
Konstantin Varlamov | f287297 | 2021-12-01 11:55:46 -0800 | [diff] [blame] | 349 | |
| 350 | template <class = __enable_if_t<__is_allocator<_Allocator>::value> > |
| 351 | vector(size_type __n, const value_type& __x, const allocator_type& __a) |
Nikolas Klauser | 129974f | 2022-02-03 23:09:37 +0100 | [diff] [blame] | 352 | : __end_cap_(nullptr, __a) |
Konstantin Varlamov | f287297 | 2021-12-01 11:55:46 -0800 | [diff] [blame] | 353 | { |
Nikolas Klauser | f280773 | 2022-01-11 00:33:35 +0100 | [diff] [blame] | 354 | _VSTD::__debug_db_insert_c(this); |
Konstantin Varlamov | f287297 | 2021-12-01 11:55:46 -0800 | [diff] [blame] | 355 | if (__n > 0) |
| 356 | { |
| 357 | __vallocate(__n); |
| 358 | __construct_at_end(__n, __x); |
| 359 | } |
| 360 | } |
| 361 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 362 | template <class _InputIterator> |
Howard Hinnant | 66fce26 | 2013-09-21 21:13:54 +0000 | [diff] [blame] | 363 | vector(_InputIterator __first, |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 364 | typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value && |
| 365 | !__is_cpp17_forward_iterator<_InputIterator>::value && |
Howard Hinnant | 8801025 | 2013-03-28 17:44:32 +0000 | [diff] [blame] | 366 | is_constructible< |
| 367 | value_type, |
Howard Hinnant | 66fce26 | 2013-09-21 21:13:54 +0000 | [diff] [blame] | 368 | typename iterator_traits<_InputIterator>::reference>::value, |
| 369 | _InputIterator>::type __last); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 370 | template <class _InputIterator> |
| 371 | vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 372 | typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value && |
| 373 | !__is_cpp17_forward_iterator<_InputIterator>::value && |
Howard Hinnant | 8801025 | 2013-03-28 17:44:32 +0000 | [diff] [blame] | 374 | is_constructible< |
| 375 | value_type, |
| 376 | typename iterator_traits<_InputIterator>::reference>::value>::type* = 0); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 377 | template <class _ForwardIterator> |
Howard Hinnant | 66fce26 | 2013-09-21 21:13:54 +0000 | [diff] [blame] | 378 | vector(_ForwardIterator __first, |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 379 | typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value && |
Howard Hinnant | 8801025 | 2013-03-28 17:44:32 +0000 | [diff] [blame] | 380 | is_constructible< |
| 381 | value_type, |
Howard Hinnant | 66fce26 | 2013-09-21 21:13:54 +0000 | [diff] [blame] | 382 | typename iterator_traits<_ForwardIterator>::reference>::value, |
| 383 | _ForwardIterator>::type __last); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 384 | template <class _ForwardIterator> |
| 385 | vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 386 | typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value && |
Howard Hinnant | 8801025 | 2013-03-28 17:44:32 +0000 | [diff] [blame] | 387 | is_constructible< |
| 388 | value_type, |
| 389 | typename iterator_traits<_ForwardIterator>::reference>::value>::type* = 0); |
Eric Fiselier | ed9e936 | 2017-04-16 02:40:45 +0000 | [diff] [blame] | 390 | |
Howard Hinnant | 1c265cd | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 391 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 392 | ~vector() |
| 393 | { |
Konstantin Varlamov | 5f23d66 | 2021-11-08 00:10:13 -0800 | [diff] [blame] | 394 | __annotate_delete(); |
Louis Dionne | ba40078 | 2020-10-02 15:02:52 -0400 | [diff] [blame] | 395 | #if _LIBCPP_DEBUG_LEVEL == 2 |
Konstantin Varlamov | 5f23d66 | 2021-11-08 00:10:13 -0800 | [diff] [blame] | 396 | __get_db()->__erase_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 397 | #endif |
Konstantin Varlamov | 5f23d66 | 2021-11-08 00:10:13 -0800 | [diff] [blame] | 398 | |
| 399 | if (this->__begin_ != nullptr) |
| 400 | { |
| 401 | __clear(); |
| 402 | __alloc_traits::deallocate(__alloc(), this->__begin_, capacity()); |
| 403 | } |
Marshall Clow | 68af4f3 | 2018-09-07 15:47:59 +0000 | [diff] [blame] | 404 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 405 | |
| 406 | vector(const vector& __x); |
Arthur O'Dwyer | 9b9662f | 2021-03-01 17:08:24 -0500 | [diff] [blame] | 407 | vector(const vector& __x, const __identity_t<allocator_type>& __a); |
Howard Hinnant | cf82332 | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 408 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 409 | vector& operator=(const vector& __x); |
Eric Fiselier | ed9e936 | 2017-04-16 02:40:45 +0000 | [diff] [blame] | 410 | |
| 411 | #ifndef _LIBCPP_CXX03_LANG |
| 412 | _LIBCPP_INLINE_VISIBILITY |
| 413 | vector(initializer_list<value_type> __il); |
| 414 | |
| 415 | _LIBCPP_INLINE_VISIBILITY |
| 416 | vector(initializer_list<value_type> __il, const allocator_type& __a); |
| 417 | |
Howard Hinnant | cf82332 | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 418 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 419 | vector(vector&& __x) |
Marshall Clow | e510820 | 2015-07-14 14:46:32 +0000 | [diff] [blame] | 420 | #if _LIBCPP_STD_VER > 14 |
| 421 | _NOEXCEPT; |
| 422 | #else |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 423 | _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); |
Marshall Clow | e510820 | 2015-07-14 14:46:32 +0000 | [diff] [blame] | 424 | #endif |
Eric Fiselier | ed9e936 | 2017-04-16 02:40:45 +0000 | [diff] [blame] | 425 | |
Howard Hinnant | cf82332 | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 426 | _LIBCPP_INLINE_VISIBILITY |
Arthur O'Dwyer | 9b9662f | 2021-03-01 17:08:24 -0500 | [diff] [blame] | 427 | vector(vector&& __x, const __identity_t<allocator_type>& __a); |
Howard Hinnant | cf82332 | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 428 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 429 | vector& operator=(vector&& __x) |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 430 | _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)); |
Eric Fiselier | ed9e936 | 2017-04-16 02:40:45 +0000 | [diff] [blame] | 431 | |
Howard Hinnant | 1c265cd | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 432 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 433 | vector& operator=(initializer_list<value_type> __il) |
| 434 | {assign(__il.begin(), __il.end()); return *this;} |
Eric Fiselier | ed9e936 | 2017-04-16 02:40:45 +0000 | [diff] [blame] | 435 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 436 | #endif // !_LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 437 | |
| 438 | template <class _InputIterator> |
| 439 | typename enable_if |
| 440 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 441 | __is_cpp17_input_iterator <_InputIterator>::value && |
| 442 | !__is_cpp17_forward_iterator<_InputIterator>::value && |
Howard Hinnant | 8801025 | 2013-03-28 17:44:32 +0000 | [diff] [blame] | 443 | is_constructible< |
| 444 | value_type, |
| 445 | typename iterator_traits<_InputIterator>::reference>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 446 | void |
| 447 | >::type |
| 448 | assign(_InputIterator __first, _InputIterator __last); |
| 449 | template <class _ForwardIterator> |
| 450 | typename enable_if |
| 451 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 452 | __is_cpp17_forward_iterator<_ForwardIterator>::value && |
Howard Hinnant | 8801025 | 2013-03-28 17:44:32 +0000 | [diff] [blame] | 453 | is_constructible< |
| 454 | value_type, |
| 455 | typename iterator_traits<_ForwardIterator>::reference>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 456 | void |
| 457 | >::type |
| 458 | assign(_ForwardIterator __first, _ForwardIterator __last); |
| 459 | |
| 460 | void assign(size_type __n, const_reference __u); |
Eric Fiselier | ed9e936 | 2017-04-16 02:40:45 +0000 | [diff] [blame] | 461 | |
| 462 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 1c265cd | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 463 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 464 | void assign(initializer_list<value_type> __il) |
| 465 | {assign(__il.begin(), __il.end());} |
Eric Fiselier | ed9e936 | 2017-04-16 02:40:45 +0000 | [diff] [blame] | 466 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 467 | |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 468 | _LIBCPP_INLINE_VISIBILITY |
| 469 | allocator_type get_allocator() const _NOEXCEPT |
| 470 | {return this->__alloc();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 471 | |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 472 | _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT; |
| 473 | _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT; |
| 474 | _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT; |
| 475 | _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 476 | |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 477 | _LIBCPP_INLINE_VISIBILITY |
| 478 | reverse_iterator rbegin() _NOEXCEPT |
| 479 | {return reverse_iterator(end());} |
| 480 | _LIBCPP_INLINE_VISIBILITY |
| 481 | const_reverse_iterator rbegin() const _NOEXCEPT |
| 482 | {return const_reverse_iterator(end());} |
| 483 | _LIBCPP_INLINE_VISIBILITY |
| 484 | reverse_iterator rend() _NOEXCEPT |
| 485 | {return reverse_iterator(begin());} |
| 486 | _LIBCPP_INLINE_VISIBILITY |
| 487 | const_reverse_iterator rend() const _NOEXCEPT |
| 488 | {return const_reverse_iterator(begin());} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 489 | |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 490 | _LIBCPP_INLINE_VISIBILITY |
| 491 | const_iterator cbegin() const _NOEXCEPT |
| 492 | {return begin();} |
| 493 | _LIBCPP_INLINE_VISIBILITY |
| 494 | const_iterator cend() const _NOEXCEPT |
| 495 | {return end();} |
| 496 | _LIBCPP_INLINE_VISIBILITY |
| 497 | const_reverse_iterator crbegin() const _NOEXCEPT |
| 498 | {return rbegin();} |
| 499 | _LIBCPP_INLINE_VISIBILITY |
| 500 | const_reverse_iterator crend() const _NOEXCEPT |
| 501 | {return rend();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 502 | |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 503 | _LIBCPP_INLINE_VISIBILITY |
| 504 | size_type size() const _NOEXCEPT |
| 505 | {return static_cast<size_type>(this->__end_ - this->__begin_);} |
| 506 | _LIBCPP_INLINE_VISIBILITY |
| 507 | size_type capacity() const _NOEXCEPT |
Konstantin Varlamov | 5f23d66 | 2021-11-08 00:10:13 -0800 | [diff] [blame] | 508 | {return static_cast<size_type>(__end_cap() - this->__begin_);} |
Marshall Clow | 425f575 | 2017-11-15 05:51:26 +0000 | [diff] [blame] | 509 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 510 | bool empty() const _NOEXCEPT |
| 511 | {return this->__begin_ == this->__end_;} |
| 512 | size_type max_size() const _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 513 | void reserve(size_type __n); |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 514 | void shrink_to_fit() _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 515 | |
Marshall Clow | d647049 | 2019-03-15 00:29:35 +0000 | [diff] [blame] | 516 | _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) _NOEXCEPT; |
| 517 | _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 518 | reference at(size_type __n); |
| 519 | const_reference at(size_type __n) const; |
| 520 | |
Marshall Clow | d647049 | 2019-03-15 00:29:35 +0000 | [diff] [blame] | 521 | _LIBCPP_INLINE_VISIBILITY reference front() _NOEXCEPT |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 522 | { |
Kristina Bessonova | aeeaa7e | 2021-05-09 19:29:56 +0200 | [diff] [blame] | 523 | _LIBCPP_ASSERT(!empty(), "front() called on an empty vector"); |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 524 | return *this->__begin_; |
| 525 | } |
Marshall Clow | d647049 | 2019-03-15 00:29:35 +0000 | [diff] [blame] | 526 | _LIBCPP_INLINE_VISIBILITY const_reference front() const _NOEXCEPT |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 527 | { |
Kristina Bessonova | aeeaa7e | 2021-05-09 19:29:56 +0200 | [diff] [blame] | 528 | _LIBCPP_ASSERT(!empty(), "front() called on an empty vector"); |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 529 | return *this->__begin_; |
| 530 | } |
Marshall Clow | d647049 | 2019-03-15 00:29:35 +0000 | [diff] [blame] | 531 | _LIBCPP_INLINE_VISIBILITY reference back() _NOEXCEPT |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 532 | { |
Kristina Bessonova | aeeaa7e | 2021-05-09 19:29:56 +0200 | [diff] [blame] | 533 | _LIBCPP_ASSERT(!empty(), "back() called on an empty vector"); |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 534 | return *(this->__end_ - 1); |
| 535 | } |
Marshall Clow | d647049 | 2019-03-15 00:29:35 +0000 | [diff] [blame] | 536 | _LIBCPP_INLINE_VISIBILITY const_reference back() const _NOEXCEPT |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 537 | { |
Kristina Bessonova | aeeaa7e | 2021-05-09 19:29:56 +0200 | [diff] [blame] | 538 | _LIBCPP_ASSERT(!empty(), "back() called on an empty vector"); |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 539 | return *(this->__end_ - 1); |
| 540 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 541 | |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 542 | _LIBCPP_INLINE_VISIBILITY |
| 543 | value_type* data() _NOEXCEPT |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 544 | {return _VSTD::__to_address(this->__begin_);} |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 545 | _LIBCPP_INLINE_VISIBILITY |
| 546 | const value_type* data() const _NOEXCEPT |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 547 | {return _VSTD::__to_address(this->__begin_);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 548 | |
Eric Fiselier | 9691972 | 2017-10-17 13:03:17 +0000 | [diff] [blame] | 549 | #ifdef _LIBCPP_CXX03_LANG |
| 550 | _LIBCPP_INLINE_VISIBILITY |
| 551 | void __emplace_back(const value_type& __x) { push_back(__x); } |
| 552 | #else |
| 553 | template <class _Arg> |
| 554 | _LIBCPP_INLINE_VISIBILITY |
| 555 | void __emplace_back(_Arg&& __arg) { |
| 556 | emplace_back(_VSTD::forward<_Arg>(__arg)); |
| 557 | } |
| 558 | #endif |
| 559 | |
Howard Hinnant | cf82332 | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 560 | _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x); |
Eric Fiselier | ed9e936 | 2017-04-16 02:40:45 +0000 | [diff] [blame] | 561 | |
| 562 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | d2cab2f | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 563 | _LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x); |
Eric Fiselier | ed9e936 | 2017-04-16 02:40:45 +0000 | [diff] [blame] | 564 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 565 | template <class... _Args> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 566 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ea52cc4 | 2017-01-24 23:09:12 +0000 | [diff] [blame] | 567 | #if _LIBCPP_STD_VER > 14 |
Eric Fiselier | 34ba5b9 | 2016-07-21 03:20:17 +0000 | [diff] [blame] | 568 | reference emplace_back(_Args&&... __args); |
Marshall Clow | ea52cc4 | 2017-01-24 23:09:12 +0000 | [diff] [blame] | 569 | #else |
| 570 | void emplace_back(_Args&&... __args); |
| 571 | #endif |
Eric Fiselier | ed9e936 | 2017-04-16 02:40:45 +0000 | [diff] [blame] | 572 | #endif // !_LIBCPP_CXX03_LANG |
| 573 | |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 574 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 575 | void pop_back(); |
| 576 | |
| 577 | iterator insert(const_iterator __position, const_reference __x); |
Eric Fiselier | ed9e936 | 2017-04-16 02:40:45 +0000 | [diff] [blame] | 578 | |
| 579 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 580 | iterator insert(const_iterator __position, value_type&& __x); |
| 581 | template <class... _Args> |
| 582 | iterator emplace(const_iterator __position, _Args&&... __args); |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 583 | #endif // !_LIBCPP_CXX03_LANG |
Eric Fiselier | ed9e936 | 2017-04-16 02:40:45 +0000 | [diff] [blame] | 584 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 585 | iterator insert(const_iterator __position, size_type __n, const_reference __x); |
| 586 | template <class _InputIterator> |
| 587 | typename enable_if |
| 588 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 589 | __is_cpp17_input_iterator <_InputIterator>::value && |
| 590 | !__is_cpp17_forward_iterator<_InputIterator>::value && |
Howard Hinnant | 8801025 | 2013-03-28 17:44:32 +0000 | [diff] [blame] | 591 | is_constructible< |
| 592 | value_type, |
| 593 | typename iterator_traits<_InputIterator>::reference>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 594 | iterator |
| 595 | >::type |
| 596 | insert(const_iterator __position, _InputIterator __first, _InputIterator __last); |
| 597 | template <class _ForwardIterator> |
| 598 | typename enable_if |
| 599 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 600 | __is_cpp17_forward_iterator<_ForwardIterator>::value && |
Howard Hinnant | 8801025 | 2013-03-28 17:44:32 +0000 | [diff] [blame] | 601 | is_constructible< |
| 602 | value_type, |
| 603 | typename iterator_traits<_ForwardIterator>::reference>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 604 | iterator |
| 605 | >::type |
| 606 | insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last); |
Eric Fiselier | ed9e936 | 2017-04-16 02:40:45 +0000 | [diff] [blame] | 607 | |
| 608 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 1c265cd | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 609 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 610 | iterator insert(const_iterator __position, initializer_list<value_type> __il) |
| 611 | {return insert(__position, __il.begin(), __il.end());} |
Eric Fiselier | ed9e936 | 2017-04-16 02:40:45 +0000 | [diff] [blame] | 612 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 613 | |
Howard Hinnant | cf82332 | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 614 | _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 615 | iterator erase(const_iterator __first, const_iterator __last); |
| 616 | |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 617 | _LIBCPP_INLINE_VISIBILITY |
| 618 | void clear() _NOEXCEPT |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 619 | { |
Marshall Clow | 2cd9d37 | 2014-05-08 14:14:06 +0000 | [diff] [blame] | 620 | size_type __old_size = size(); |
Konstantin Varlamov | 5f23d66 | 2021-11-08 00:10:13 -0800 | [diff] [blame] | 621 | __clear(); |
Marshall Clow | 2cd9d37 | 2014-05-08 14:14:06 +0000 | [diff] [blame] | 622 | __annotate_shrink(__old_size); |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 623 | __invalidate_all_iterators(); |
| 624 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 625 | |
| 626 | void resize(size_type __sz); |
| 627 | void resize(size_type __sz, const_reference __x); |
| 628 | |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 629 | void swap(vector&) |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 630 | #if _LIBCPP_STD_VER >= 14 |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 631 | _NOEXCEPT; |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 632 | #else |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 633 | _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 634 | __is_nothrow_swappable<allocator_type>::value); |
| 635 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 636 | |
| 637 | bool __invariants() const; |
| 638 | |
Louis Dionne | ba40078 | 2020-10-02 15:02:52 -0400 | [diff] [blame] | 639 | #if _LIBCPP_DEBUG_LEVEL == 2 |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 640 | |
| 641 | bool __dereferenceable(const const_iterator* __i) const; |
| 642 | bool __decrementable(const const_iterator* __i) const; |
| 643 | bool __addable(const const_iterator* __i, ptrdiff_t __n) const; |
| 644 | bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const; |
| 645 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 646 | #endif // _LIBCPP_DEBUG_LEVEL == 2 |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 647 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 648 | private: |
Nikolas Klauser | 129974f | 2022-02-03 23:09:37 +0100 | [diff] [blame] | 649 | pointer __begin_ = nullptr; |
| 650 | pointer __end_ = nullptr; |
| 651 | __compressed_pair<pointer, allocator_type> __end_cap_ = |
| 652 | __compressed_pair<pointer, allocator_type>(nullptr, __default_init_tag()); |
| 653 | |
Howard Hinnant | cf82332 | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 654 | _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators(); |
Eric Fiselier | 69c5198 | 2016-12-28 06:06:09 +0000 | [diff] [blame] | 655 | _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(pointer __new_last); |
Marshall Clow | 3ff48e0 | 2018-05-22 16:20:28 +0000 | [diff] [blame] | 656 | void __vallocate(size_type __n); |
| 657 | void __vdeallocate() _NOEXCEPT; |
Howard Hinnant | cf82332 | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 658 | _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const; |
Howard Hinnant | a558938 | 2011-01-04 19:53:31 +0000 | [diff] [blame] | 659 | void __construct_at_end(size_type __n); |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 660 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 661 | void __construct_at_end(size_type __n, const_reference __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 662 | template <class _ForwardIterator> |
| 663 | typename enable_if |
| 664 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 665 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 666 | void |
| 667 | >::type |
Eric Fiselier | acfe6f0 | 2015-03-31 16:54:19 +0000 | [diff] [blame] | 668 | __construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 669 | void __append(size_type __n); |
| 670 | void __append(size_type __n, const_reference __x); |
Howard Hinnant | cf82332 | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 671 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 672 | iterator __make_iter(pointer __p) _NOEXCEPT; |
Howard Hinnant | cf82332 | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 673 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 674 | const_iterator __make_iter(const_pointer __p) const _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 675 | void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v); |
| 676 | pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p); |
| 677 | void __move_range(pointer __from_s, pointer __from_e, pointer __to); |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 678 | void __move_assign(vector& __c, true_type) |
| 679 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 680 | void __move_assign(vector& __c, false_type) |
| 681 | _NOEXCEPT_(__alloc_traits::is_always_equal::value); |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 682 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 76053d7 | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 683 | void __destruct_at_end(pointer __new_last) _NOEXCEPT |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 684 | { |
Eric Fiselier | 69c5198 | 2016-12-28 06:06:09 +0000 | [diff] [blame] | 685 | __invalidate_iterators_past(__new_last); |
Marshall Clow | 2cd9d37 | 2014-05-08 14:14:06 +0000 | [diff] [blame] | 686 | size_type __old_size = size(); |
Konstantin Varlamov | 5f23d66 | 2021-11-08 00:10:13 -0800 | [diff] [blame] | 687 | __base_destruct_at_end(__new_last); |
Marshall Clow | 2cd9d37 | 2014-05-08 14:14:06 +0000 | [diff] [blame] | 688 | __annotate_shrink(__old_size); |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 689 | } |
Eric Fiselier | ed9e936 | 2017-04-16 02:40:45 +0000 | [diff] [blame] | 690 | |
| 691 | #ifndef _LIBCPP_CXX03_LANG |
Eric Fiselier | 7110f44 | 2019-03-19 19:19:44 +0000 | [diff] [blame] | 692 | template <class _Up> |
| 693 | _LIBCPP_INLINE_VISIBILITY |
| 694 | inline void __push_back_slow_path(_Up&& __x); |
Eric Fiselier | ed9e936 | 2017-04-16 02:40:45 +0000 | [diff] [blame] | 695 | |
Howard Hinnant | b6c4956 | 2012-02-26 15:30:12 +0000 | [diff] [blame] | 696 | template <class... _Args> |
Eric Fiselier | 7110f44 | 2019-03-19 19:19:44 +0000 | [diff] [blame] | 697 | _LIBCPP_INLINE_VISIBILITY |
| 698 | inline void __emplace_back_slow_path(_Args&&... __args); |
Eric Fiselier | ed9e936 | 2017-04-16 02:40:45 +0000 | [diff] [blame] | 699 | #else |
Eric Fiselier | 7110f44 | 2019-03-19 19:19:44 +0000 | [diff] [blame] | 700 | template <class _Up> |
| 701 | _LIBCPP_INLINE_VISIBILITY |
| 702 | inline void __push_back_slow_path(_Up& __x); |
Howard Hinnant | b6c4956 | 2012-02-26 15:30:12 +0000 | [diff] [blame] | 703 | #endif |
Eric Fiselier | ed9e936 | 2017-04-16 02:40:45 +0000 | [diff] [blame] | 704 | |
Marshall Clow | 2cd9d37 | 2014-05-08 14:14:06 +0000 | [diff] [blame] | 705 | // The following functions are no-ops outside of AddressSanitizer mode. |
| 706 | // We call annotatations only for the default Allocator because other allocators |
| 707 | // may not meet the AddressSanitizer alignment constraints. |
| 708 | // See the documentation for __sanitizer_annotate_contiguous_container for more details. |
Marshall Clow | 2cd9d37 | 2014-05-08 14:14:06 +0000 | [diff] [blame] | 709 | #ifndef _LIBCPP_HAS_NO_ASAN |
Eric Fiselier | 6003c77 | 2016-12-23 23:37:52 +0000 | [diff] [blame] | 710 | void __annotate_contiguous_container(const void *__beg, const void *__end, |
| 711 | const void *__old_mid, |
| 712 | const void *__new_mid) const |
| 713 | { |
| 714 | |
Marshall Clow | 2cd9d37 | 2014-05-08 14:14:06 +0000 | [diff] [blame] | 715 | if (__beg && is_same<allocator_type, __default_allocator_type>::value) |
| 716 | __sanitizer_annotate_contiguous_container(__beg, __end, __old_mid, __new_mid); |
Marshall Clow | 2cd9d37 | 2014-05-08 14:14:06 +0000 | [diff] [blame] | 717 | } |
Eric Fiselier | 6003c77 | 2016-12-23 23:37:52 +0000 | [diff] [blame] | 718 | #else |
| 719 | _LIBCPP_INLINE_VISIBILITY |
| 720 | void __annotate_contiguous_container(const void*, const void*, const void*, |
Eric Fiselier | e7afbd3 | 2019-07-28 04:37:02 +0000 | [diff] [blame] | 721 | const void*) const _NOEXCEPT {} |
Eric Fiselier | 6003c77 | 2016-12-23 23:37:52 +0000 | [diff] [blame] | 722 | #endif |
| 723 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | e7afbd3 | 2019-07-28 04:37:02 +0000 | [diff] [blame] | 724 | void __annotate_new(size_type __current_size) const _NOEXCEPT { |
Marshall Clow | 2cd9d37 | 2014-05-08 14:14:06 +0000 | [diff] [blame] | 725 | __annotate_contiguous_container(data(), data() + capacity(), |
| 726 | data() + capacity(), data() + __current_size); |
| 727 | } |
Eric Fiselier | 6003c77 | 2016-12-23 23:37:52 +0000 | [diff] [blame] | 728 | |
| 729 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | e7afbd3 | 2019-07-28 04:37:02 +0000 | [diff] [blame] | 730 | void __annotate_delete() const _NOEXCEPT { |
Marshall Clow | 2cd9d37 | 2014-05-08 14:14:06 +0000 | [diff] [blame] | 731 | __annotate_contiguous_container(data(), data() + capacity(), |
| 732 | data() + size(), data() + capacity()); |
| 733 | } |
Eric Fiselier | 6003c77 | 2016-12-23 23:37:52 +0000 | [diff] [blame] | 734 | |
| 735 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | e7afbd3 | 2019-07-28 04:37:02 +0000 | [diff] [blame] | 736 | void __annotate_increase(size_type __n) const _NOEXCEPT |
Marshall Clow | 2cd9d37 | 2014-05-08 14:14:06 +0000 | [diff] [blame] | 737 | { |
| 738 | __annotate_contiguous_container(data(), data() + capacity(), |
| 739 | data() + size(), data() + size() + __n); |
| 740 | } |
Eric Fiselier | 6003c77 | 2016-12-23 23:37:52 +0000 | [diff] [blame] | 741 | |
| 742 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | e7afbd3 | 2019-07-28 04:37:02 +0000 | [diff] [blame] | 743 | void __annotate_shrink(size_type __old_size) const _NOEXCEPT |
Marshall Clow | 2cd9d37 | 2014-05-08 14:14:06 +0000 | [diff] [blame] | 744 | { |
| 745 | __annotate_contiguous_container(data(), data() + capacity(), |
| 746 | data() + __old_size, data() + size()); |
| 747 | } |
Marshall Clow | c78ffa5 | 2014-09-03 21:37:43 +0000 | [diff] [blame] | 748 | |
Eric Fiselier | e7afbd3 | 2019-07-28 04:37:02 +0000 | [diff] [blame] | 749 | struct _ConstructTransaction { |
| 750 | explicit _ConstructTransaction(vector &__v, size_type __n) |
Mark de Wever | dcafc46 | 2021-10-21 18:29:14 +0200 | [diff] [blame] | 751 | : __v_(__v), __pos_(__v.__end_), __new_end_(__v.__end_ + __n) { |
Eric Fiselier | e7afbd3 | 2019-07-28 04:37:02 +0000 | [diff] [blame] | 752 | #ifndef _LIBCPP_HAS_NO_ASAN |
| 753 | __v_.__annotate_increase(__n); |
| 754 | #endif |
| 755 | } |
| 756 | ~_ConstructTransaction() { |
| 757 | __v_.__end_ = __pos_; |
| 758 | #ifndef _LIBCPP_HAS_NO_ASAN |
| 759 | if (__pos_ != __new_end_) { |
| 760 | __v_.__annotate_shrink(__new_end_ - __v_.__begin_); |
| 761 | } |
| 762 | #endif |
| 763 | } |
| 764 | |
| 765 | vector &__v_; |
| 766 | pointer __pos_; |
| 767 | const_pointer const __new_end_; |
| 768 | |
| 769 | private: |
| 770 | _ConstructTransaction(_ConstructTransaction const&) = delete; |
| 771 | _ConstructTransaction& operator=(_ConstructTransaction const&) = delete; |
| 772 | }; |
| 773 | |
| 774 | template <class ..._Args> |
| 775 | _LIBCPP_INLINE_VISIBILITY |
| 776 | void __construct_one_at_end(_Args&& ...__args) { |
| 777 | _ConstructTransaction __tx(*this, 1); |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 778 | __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__tx.__pos_), |
Eric Fiselier | e7afbd3 | 2019-07-28 04:37:02 +0000 | [diff] [blame] | 779 | _VSTD::forward<_Args>(__args)...); |
| 780 | ++__tx.__pos_; |
| 781 | } |
Konstantin Varlamov | 5f23d66 | 2021-11-08 00:10:13 -0800 | [diff] [blame] | 782 | |
| 783 | _LIBCPP_INLINE_VISIBILITY |
| 784 | allocator_type& __alloc() _NOEXCEPT |
| 785 | {return this->__end_cap_.second();} |
| 786 | _LIBCPP_INLINE_VISIBILITY |
| 787 | const allocator_type& __alloc() const _NOEXCEPT |
| 788 | {return this->__end_cap_.second();} |
| 789 | _LIBCPP_INLINE_VISIBILITY |
| 790 | pointer& __end_cap() _NOEXCEPT |
| 791 | {return this->__end_cap_.first();} |
| 792 | _LIBCPP_INLINE_VISIBILITY |
| 793 | const pointer& __end_cap() const _NOEXCEPT |
| 794 | {return this->__end_cap_.first();} |
| 795 | |
| 796 | _LIBCPP_INLINE_VISIBILITY |
| 797 | void __clear() _NOEXCEPT {__base_destruct_at_end(this->__begin_);} |
| 798 | |
| 799 | _LIBCPP_INLINE_VISIBILITY |
| 800 | void __base_destruct_at_end(pointer __new_last) _NOEXCEPT { |
| 801 | pointer __soon_to_be_end = this->__end_; |
| 802 | while (__new_last != __soon_to_be_end) |
| 803 | __alloc_traits::destroy(__alloc(), _VSTD::__to_address(--__soon_to_be_end)); |
| 804 | this->__end_ = __new_last; |
| 805 | } |
| 806 | |
| 807 | _LIBCPP_INLINE_VISIBILITY |
| 808 | void __copy_assign_alloc(const vector& __c) |
| 809 | {__copy_assign_alloc(__c, integral_constant<bool, |
| 810 | __alloc_traits::propagate_on_container_copy_assignment::value>());} |
| 811 | |
| 812 | _LIBCPP_INLINE_VISIBILITY |
| 813 | void __move_assign_alloc(vector& __c) |
| 814 | _NOEXCEPT_( |
| 815 | !__alloc_traits::propagate_on_container_move_assignment::value || |
| 816 | is_nothrow_move_assignable<allocator_type>::value) |
| 817 | {__move_assign_alloc(__c, integral_constant<bool, |
| 818 | __alloc_traits::propagate_on_container_move_assignment::value>());} |
| 819 | |
| 820 | _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI |
| 821 | void __throw_length_error() const { |
Nikolas Klauser | 129974f | 2022-02-03 23:09:37 +0100 | [diff] [blame] | 822 | _VSTD::__throw_length_error("vector"); |
Konstantin Varlamov | 5f23d66 | 2021-11-08 00:10:13 -0800 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI |
| 826 | void __throw_out_of_range() const { |
Nikolas Klauser | 129974f | 2022-02-03 23:09:37 +0100 | [diff] [blame] | 827 | _VSTD::__throw_out_of_range("vector"); |
Konstantin Varlamov | 5f23d66 | 2021-11-08 00:10:13 -0800 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | _LIBCPP_INLINE_VISIBILITY |
| 831 | void __copy_assign_alloc(const vector& __c, true_type) |
| 832 | { |
| 833 | if (__alloc() != __c.__alloc()) |
| 834 | { |
| 835 | __clear(); |
| 836 | __alloc_traits::deallocate(__alloc(), this->__begin_, capacity()); |
| 837 | this->__begin_ = this->__end_ = __end_cap() = nullptr; |
| 838 | } |
| 839 | __alloc() = __c.__alloc(); |
| 840 | } |
| 841 | |
| 842 | _LIBCPP_INLINE_VISIBILITY |
| 843 | void __copy_assign_alloc(const vector&, false_type) |
| 844 | {} |
| 845 | |
| 846 | _LIBCPP_INLINE_VISIBILITY |
| 847 | void __move_assign_alloc(vector& __c, true_type) |
| 848 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) |
| 849 | { |
| 850 | __alloc() = _VSTD::move(__c.__alloc()); |
| 851 | } |
| 852 | |
| 853 | _LIBCPP_INLINE_VISIBILITY |
| 854 | void __move_assign_alloc(vector&, false_type) |
| 855 | _NOEXCEPT |
| 856 | {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 857 | }; |
| 858 | |
Louis Dionne | d59f8a5 | 2021-08-17 11:59:07 -0400 | [diff] [blame] | 859 | #if _LIBCPP_STD_VER >= 17 |
Marshall Clow | f0ca149 | 2018-05-21 21:30:12 +0000 | [diff] [blame] | 860 | template<class _InputIterator, |
Arthur O'Dwyer | 5622676 | 2021-03-03 23:02:20 -0500 | [diff] [blame] | 861 | class _Alloc = allocator<__iter_value_type<_InputIterator>>, |
Konstantin Varlamov | 53b543c | 2021-11-09 09:21:02 -0800 | [diff] [blame] | 862 | class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>, |
Louis Dionne | 2554716 | 2021-08-17 12:26:09 -0400 | [diff] [blame] | 863 | class = enable_if_t<__is_allocator<_Alloc>::value> |
Marshall Clow | f0ca149 | 2018-05-21 21:30:12 +0000 | [diff] [blame] | 864 | > |
| 865 | vector(_InputIterator, _InputIterator) |
Arthur O'Dwyer | 5622676 | 2021-03-03 23:02:20 -0500 | [diff] [blame] | 866 | -> vector<__iter_value_type<_InputIterator>, _Alloc>; |
Marshall Clow | f0ca149 | 2018-05-21 21:30:12 +0000 | [diff] [blame] | 867 | |
| 868 | template<class _InputIterator, |
| 869 | class _Alloc, |
Konstantin Varlamov | 53b543c | 2021-11-09 09:21:02 -0800 | [diff] [blame] | 870 | class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>, |
Louis Dionne | 2554716 | 2021-08-17 12:26:09 -0400 | [diff] [blame] | 871 | class = enable_if_t<__is_allocator<_Alloc>::value> |
Marshall Clow | f0ca149 | 2018-05-21 21:30:12 +0000 | [diff] [blame] | 872 | > |
| 873 | vector(_InputIterator, _InputIterator, _Alloc) |
Arthur O'Dwyer | 5622676 | 2021-03-03 23:02:20 -0500 | [diff] [blame] | 874 | -> vector<__iter_value_type<_InputIterator>, _Alloc>; |
Marshall Clow | f0ca149 | 2018-05-21 21:30:12 +0000 | [diff] [blame] | 875 | #endif |
| 876 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 877 | template <class _Tp, class _Allocator> |
| 878 | void |
| 879 | vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v) |
| 880 | { |
Eric Fiselier | 909fe96 | 2019-09-13 16:09:33 +0000 | [diff] [blame] | 881 | |
Marshall Clow | 2cd9d37 | 2014-05-08 14:14:06 +0000 | [diff] [blame] | 882 | __annotate_delete(); |
Arthur O'Dwyer | 4e0de31 | 2020-11-18 18:54:38 -0500 | [diff] [blame] | 883 | _VSTD::__construct_backward_with_exception_guarantees(this->__alloc(), this->__begin_, this->__end_, __v.__begin_); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 884 | _VSTD::swap(this->__begin_, __v.__begin_); |
| 885 | _VSTD::swap(this->__end_, __v.__end_); |
| 886 | _VSTD::swap(this->__end_cap(), __v.__end_cap()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 887 | __v.__first_ = __v.__begin_; |
Marshall Clow | 2cd9d37 | 2014-05-08 14:14:06 +0000 | [diff] [blame] | 888 | __annotate_new(size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 889 | __invalidate_all_iterators(); |
| 890 | } |
| 891 | |
| 892 | template <class _Tp, class _Allocator> |
| 893 | typename vector<_Tp, _Allocator>::pointer |
| 894 | vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p) |
| 895 | { |
Marshall Clow | 2cd9d37 | 2014-05-08 14:14:06 +0000 | [diff] [blame] | 896 | __annotate_delete(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 897 | pointer __r = __v.__begin_; |
Arthur O'Dwyer | 4e0de31 | 2020-11-18 18:54:38 -0500 | [diff] [blame] | 898 | _VSTD::__construct_backward_with_exception_guarantees(this->__alloc(), this->__begin_, __p, __v.__begin_); |
| 899 | _VSTD::__construct_forward_with_exception_guarantees(this->__alloc(), __p, this->__end_, __v.__end_); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 900 | _VSTD::swap(this->__begin_, __v.__begin_); |
| 901 | _VSTD::swap(this->__end_, __v.__end_); |
| 902 | _VSTD::swap(this->__end_cap(), __v.__end_cap()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 903 | __v.__first_ = __v.__begin_; |
Marshall Clow | 2cd9d37 | 2014-05-08 14:14:06 +0000 | [diff] [blame] | 904 | __annotate_new(size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 905 | __invalidate_all_iterators(); |
| 906 | return __r; |
| 907 | } |
| 908 | |
| 909 | // Allocate space for __n objects |
| 910 | // throws length_error if __n > max_size() |
| 911 | // throws (probably bad_alloc) if memory run out |
| 912 | // Precondition: __begin_ == __end_ == __end_cap() == 0 |
| 913 | // Precondition: __n > 0 |
| 914 | // Postcondition: capacity() == __n |
| 915 | // Postcondition: size() == 0 |
| 916 | template <class _Tp, class _Allocator> |
| 917 | void |
Marshall Clow | 3ff48e0 | 2018-05-22 16:20:28 +0000 | [diff] [blame] | 918 | vector<_Tp, _Allocator>::__vallocate(size_type __n) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 919 | { |
| 920 | if (__n > max_size()) |
| 921 | this->__throw_length_error(); |
| 922 | this->__begin_ = this->__end_ = __alloc_traits::allocate(this->__alloc(), __n); |
| 923 | this->__end_cap() = this->__begin_ + __n; |
Marshall Clow | 2cd9d37 | 2014-05-08 14:14:06 +0000 | [diff] [blame] | 924 | __annotate_new(0); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | template <class _Tp, class _Allocator> |
| 928 | void |
Marshall Clow | 3ff48e0 | 2018-05-22 16:20:28 +0000 | [diff] [blame] | 929 | vector<_Tp, _Allocator>::__vdeallocate() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 930 | { |
Howard Hinnant | 76053d7 | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 931 | if (this->__begin_ != nullptr) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 932 | { |
| 933 | clear(); |
| 934 | __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity()); |
Howard Hinnant | 76053d7 | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 935 | this->__begin_ = this->__end_ = this->__end_cap() = nullptr; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 936 | } |
| 937 | } |
| 938 | |
| 939 | template <class _Tp, class _Allocator> |
| 940 | typename vector<_Tp, _Allocator>::size_type |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 941 | vector<_Tp, _Allocator>::max_size() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 942 | { |
Eric Fiselier | b5d9f44 | 2016-11-23 01:18:56 +0000 | [diff] [blame] | 943 | return _VSTD::min<size_type>(__alloc_traits::max_size(this->__alloc()), |
| 944 | numeric_limits<difference_type>::max()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | // Precondition: __new_size > capacity() |
| 948 | template <class _Tp, class _Allocator> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 949 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 950 | typename vector<_Tp, _Allocator>::size_type |
| 951 | vector<_Tp, _Allocator>::__recommend(size_type __new_size) const |
| 952 | { |
| 953 | const size_type __ms = max_size(); |
| 954 | if (__new_size > __ms) |
| 955 | this->__throw_length_error(); |
| 956 | const size_type __cap = capacity(); |
| 957 | if (__cap >= __ms / 2) |
| 958 | return __ms; |
Arthur O'Dwyer | c0fb14b | 2021-07-26 18:23:00 -0400 | [diff] [blame] | 959 | return _VSTD::max<size_type>(2 * __cap, __new_size); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | // Default constructs __n objects starting at __end_ |
| 963 | // throws if construction throws |
| 964 | // Precondition: __n > 0 |
| 965 | // Precondition: size() + __n <= capacity() |
| 966 | // Postcondition: size() == size() + __n |
| 967 | template <class _Tp, class _Allocator> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 968 | void |
| 969 | vector<_Tp, _Allocator>::__construct_at_end(size_type __n) |
| 970 | { |
Eric Fiselier | e7afbd3 | 2019-07-28 04:37:02 +0000 | [diff] [blame] | 971 | _ConstructTransaction __tx(*this, __n); |
Martijn Vels | 1e2e1b8 | 2020-06-18 13:14:02 -0400 | [diff] [blame] | 972 | const_pointer __new_end = __tx.__new_end_; |
Arthur O'Dwyer | 80dbcbe | 2021-09-07 21:35:37 -0400 | [diff] [blame] | 973 | for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) { |
Martijn Vels | 1e2e1b8 | 2020-06-18 13:14:02 -0400 | [diff] [blame] | 974 | __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__pos)); |
Eric Fiselier | e7afbd3 | 2019-07-28 04:37:02 +0000 | [diff] [blame] | 975 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 976 | } |
| 977 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 978 | // Copy constructs __n objects starting at __end_ from __x |
| 979 | // throws if construction throws |
| 980 | // Precondition: __n > 0 |
| 981 | // Precondition: size() + __n <= capacity() |
| 982 | // Postcondition: size() == old size() + __n |
| 983 | // Postcondition: [i] == __x for all i in [size() - __n, __n) |
| 984 | template <class _Tp, class _Allocator> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 985 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 986 | void |
| 987 | vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x) |
| 988 | { |
Eric Fiselier | e7afbd3 | 2019-07-28 04:37:02 +0000 | [diff] [blame] | 989 | _ConstructTransaction __tx(*this, __n); |
Martijn Vels | 1e2e1b8 | 2020-06-18 13:14:02 -0400 | [diff] [blame] | 990 | const_pointer __new_end = __tx.__new_end_; |
Arthur O'Dwyer | 80dbcbe | 2021-09-07 21:35:37 -0400 | [diff] [blame] | 991 | for (pointer __pos = __tx.__pos_; __pos != __new_end; __tx.__pos_ = ++__pos) { |
Martijn Vels | 1e2e1b8 | 2020-06-18 13:14:02 -0400 | [diff] [blame] | 992 | __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__pos), __x); |
Eric Fiselier | e7afbd3 | 2019-07-28 04:37:02 +0000 | [diff] [blame] | 993 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | template <class _Tp, class _Allocator> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 997 | template <class _ForwardIterator> |
| 998 | typename enable_if |
| 999 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 1000 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1001 | void |
| 1002 | >::type |
Eric Fiselier | acfe6f0 | 2015-03-31 16:54:19 +0000 | [diff] [blame] | 1003 | vector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1004 | { |
Eric Fiselier | e7afbd3 | 2019-07-28 04:37:02 +0000 | [diff] [blame] | 1005 | _ConstructTransaction __tx(*this, __n); |
Arthur O'Dwyer | 4e0de31 | 2020-11-18 18:54:38 -0500 | [diff] [blame] | 1006 | _VSTD::__construct_range_forward(this->__alloc(), __first, __last, __tx.__pos_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1007 | } |
| 1008 | |
| 1009 | // Default constructs __n objects starting at __end_ |
| 1010 | // throws if construction throws |
| 1011 | // Postcondition: size() == size() + __n |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1012 | // Exception safety: strong. |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1013 | template <class _Tp, class _Allocator> |
| 1014 | void |
| 1015 | vector<_Tp, _Allocator>::__append(size_type __n) |
| 1016 | { |
| 1017 | if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n) |
| 1018 | this->__construct_at_end(__n); |
| 1019 | else |
| 1020 | { |
| 1021 | allocator_type& __a = this->__alloc(); |
| 1022 | __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a); |
| 1023 | __v.__construct_at_end(__n); |
| 1024 | __swap_out_circular_buffer(__v); |
| 1025 | } |
| 1026 | } |
| 1027 | |
| 1028 | // Default constructs __n objects starting at __end_ |
| 1029 | // throws if construction throws |
| 1030 | // Postcondition: size() == size() + __n |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1031 | // Exception safety: strong. |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1032 | template <class _Tp, class _Allocator> |
| 1033 | void |
| 1034 | vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x) |
| 1035 | { |
| 1036 | if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n) |
| 1037 | this->__construct_at_end(__n, __x); |
| 1038 | else |
| 1039 | { |
| 1040 | allocator_type& __a = this->__alloc(); |
| 1041 | __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a); |
| 1042 | __v.__construct_at_end(__n, __x); |
| 1043 | __swap_out_circular_buffer(__v); |
| 1044 | } |
| 1045 | } |
| 1046 | |
| 1047 | template <class _Tp, class _Allocator> |
| 1048 | vector<_Tp, _Allocator>::vector(size_type __n) |
| 1049 | { |
Nikolas Klauser | f280773 | 2022-01-11 00:33:35 +0100 | [diff] [blame] | 1050 | _VSTD::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1051 | if (__n > 0) |
| 1052 | { |
Marshall Clow | 3ff48e0 | 2018-05-22 16:20:28 +0000 | [diff] [blame] | 1053 | __vallocate(__n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1054 | __construct_at_end(__n); |
| 1055 | } |
| 1056 | } |
| 1057 | |
Marshall Clow | d3cbeaa | 2013-09-14 00:47:59 +0000 | [diff] [blame] | 1058 | #if _LIBCPP_STD_VER > 11 |
| 1059 | template <class _Tp, class _Allocator> |
| 1060 | vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a) |
Nikolas Klauser | 129974f | 2022-02-03 23:09:37 +0100 | [diff] [blame] | 1061 | : __end_cap_(nullptr, __a) |
Marshall Clow | d3cbeaa | 2013-09-14 00:47:59 +0000 | [diff] [blame] | 1062 | { |
Nikolas Klauser | f280773 | 2022-01-11 00:33:35 +0100 | [diff] [blame] | 1063 | _VSTD::__debug_db_insert_c(this); |
Marshall Clow | d3cbeaa | 2013-09-14 00:47:59 +0000 | [diff] [blame] | 1064 | if (__n > 0) |
| 1065 | { |
Marshall Clow | 3ff48e0 | 2018-05-22 16:20:28 +0000 | [diff] [blame] | 1066 | __vallocate(__n); |
Marshall Clow | d3cbeaa | 2013-09-14 00:47:59 +0000 | [diff] [blame] | 1067 | __construct_at_end(__n); |
| 1068 | } |
| 1069 | } |
| 1070 | #endif |
| 1071 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1072 | template <class _Tp, class _Allocator> |
Marshall Clow | f0ca149 | 2018-05-21 21:30:12 +0000 | [diff] [blame] | 1073 | vector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1074 | { |
Nikolas Klauser | f280773 | 2022-01-11 00:33:35 +0100 | [diff] [blame] | 1075 | _VSTD::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1076 | if (__n > 0) |
| 1077 | { |
Marshall Clow | 3ff48e0 | 2018-05-22 16:20:28 +0000 | [diff] [blame] | 1078 | __vallocate(__n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1079 | __construct_at_end(__n, __x); |
| 1080 | } |
| 1081 | } |
| 1082 | |
| 1083 | template <class _Tp, class _Allocator> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1084 | template <class _InputIterator> |
Howard Hinnant | 66fce26 | 2013-09-21 21:13:54 +0000 | [diff] [blame] | 1085 | vector<_Tp, _Allocator>::vector(_InputIterator __first, |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 1086 | typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value && |
| 1087 | !__is_cpp17_forward_iterator<_InputIterator>::value && |
Howard Hinnant | 8801025 | 2013-03-28 17:44:32 +0000 | [diff] [blame] | 1088 | is_constructible< |
| 1089 | value_type, |
Howard Hinnant | 66fce26 | 2013-09-21 21:13:54 +0000 | [diff] [blame] | 1090 | typename iterator_traits<_InputIterator>::reference>::value, |
| 1091 | _InputIterator>::type __last) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1092 | { |
Nikolas Klauser | f280773 | 2022-01-11 00:33:35 +0100 | [diff] [blame] | 1093 | _VSTD::__debug_db_insert_c(this); |
Howard Hinnant | 9cd2230 | 2011-09-16 18:41:29 +0000 | [diff] [blame] | 1094 | for (; __first != __last; ++__first) |
Eric Fiselier | 9691972 | 2017-10-17 13:03:17 +0000 | [diff] [blame] | 1095 | __emplace_back(*__first); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | template <class _Tp, class _Allocator> |
| 1099 | template <class _InputIterator> |
| 1100 | vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 1101 | typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value && |
| 1102 | !__is_cpp17_forward_iterator<_InputIterator>::value && |
Howard Hinnant | 8801025 | 2013-03-28 17:44:32 +0000 | [diff] [blame] | 1103 | is_constructible< |
| 1104 | value_type, |
| 1105 | typename iterator_traits<_InputIterator>::reference>::value>::type*) |
Nikolas Klauser | 129974f | 2022-02-03 23:09:37 +0100 | [diff] [blame] | 1106 | : __end_cap_(nullptr, __a) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1107 | { |
Nikolas Klauser | f280773 | 2022-01-11 00:33:35 +0100 | [diff] [blame] | 1108 | _VSTD::__debug_db_insert_c(this); |
Howard Hinnant | 9cd2230 | 2011-09-16 18:41:29 +0000 | [diff] [blame] | 1109 | for (; __first != __last; ++__first) |
Eric Fiselier | 9691972 | 2017-10-17 13:03:17 +0000 | [diff] [blame] | 1110 | __emplace_back(*__first); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1111 | } |
| 1112 | |
| 1113 | template <class _Tp, class _Allocator> |
| 1114 | template <class _ForwardIterator> |
Howard Hinnant | 66fce26 | 2013-09-21 21:13:54 +0000 | [diff] [blame] | 1115 | vector<_Tp, _Allocator>::vector(_ForwardIterator __first, |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 1116 | typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value && |
Howard Hinnant | 8801025 | 2013-03-28 17:44:32 +0000 | [diff] [blame] | 1117 | is_constructible< |
| 1118 | value_type, |
Howard Hinnant | 66fce26 | 2013-09-21 21:13:54 +0000 | [diff] [blame] | 1119 | typename iterator_traits<_ForwardIterator>::reference>::value, |
| 1120 | _ForwardIterator>::type __last) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1121 | { |
Nikolas Klauser | f280773 | 2022-01-11 00:33:35 +0100 | [diff] [blame] | 1122 | _VSTD::__debug_db_insert_c(this); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1123 | size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1124 | if (__n > 0) |
| 1125 | { |
Marshall Clow | 3ff48e0 | 2018-05-22 16:20:28 +0000 | [diff] [blame] | 1126 | __vallocate(__n); |
Eric Fiselier | acfe6f0 | 2015-03-31 16:54:19 +0000 | [diff] [blame] | 1127 | __construct_at_end(__first, __last, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1128 | } |
| 1129 | } |
| 1130 | |
| 1131 | template <class _Tp, class _Allocator> |
| 1132 | template <class _ForwardIterator> |
| 1133 | vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 1134 | typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value && |
Howard Hinnant | 8801025 | 2013-03-28 17:44:32 +0000 | [diff] [blame] | 1135 | is_constructible< |
| 1136 | value_type, |
| 1137 | typename iterator_traits<_ForwardIterator>::reference>::value>::type*) |
Nikolas Klauser | 129974f | 2022-02-03 23:09:37 +0100 | [diff] [blame] | 1138 | : __end_cap_(nullptr, __a) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1139 | { |
Nikolas Klauser | f280773 | 2022-01-11 00:33:35 +0100 | [diff] [blame] | 1140 | _VSTD::__debug_db_insert_c(this); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1141 | size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1142 | if (__n > 0) |
| 1143 | { |
Marshall Clow | 3ff48e0 | 2018-05-22 16:20:28 +0000 | [diff] [blame] | 1144 | __vallocate(__n); |
Eric Fiselier | acfe6f0 | 2015-03-31 16:54:19 +0000 | [diff] [blame] | 1145 | __construct_at_end(__first, __last, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1146 | } |
| 1147 | } |
| 1148 | |
| 1149 | template <class _Tp, class _Allocator> |
| 1150 | vector<_Tp, _Allocator>::vector(const vector& __x) |
Nikolas Klauser | 129974f | 2022-02-03 23:09:37 +0100 | [diff] [blame] | 1151 | : __end_cap_(nullptr, __alloc_traits::select_on_container_copy_construction(__x.__alloc())) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1152 | { |
Nikolas Klauser | f280773 | 2022-01-11 00:33:35 +0100 | [diff] [blame] | 1153 | _VSTD::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1154 | size_type __n = __x.size(); |
| 1155 | if (__n > 0) |
| 1156 | { |
Marshall Clow | 3ff48e0 | 2018-05-22 16:20:28 +0000 | [diff] [blame] | 1157 | __vallocate(__n); |
Eric Fiselier | acfe6f0 | 2015-03-31 16:54:19 +0000 | [diff] [blame] | 1158 | __construct_at_end(__x.__begin_, __x.__end_, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1159 | } |
| 1160 | } |
| 1161 | |
| 1162 | template <class _Tp, class _Allocator> |
Arthur O'Dwyer | 9b9662f | 2021-03-01 17:08:24 -0500 | [diff] [blame] | 1163 | vector<_Tp, _Allocator>::vector(const vector& __x, const __identity_t<allocator_type>& __a) |
Nikolas Klauser | 129974f | 2022-02-03 23:09:37 +0100 | [diff] [blame] | 1164 | : __end_cap_(nullptr, __a) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1165 | { |
Nikolas Klauser | f280773 | 2022-01-11 00:33:35 +0100 | [diff] [blame] | 1166 | _VSTD::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1167 | size_type __n = __x.size(); |
| 1168 | if (__n > 0) |
| 1169 | { |
Marshall Clow | 3ff48e0 | 2018-05-22 16:20:28 +0000 | [diff] [blame] | 1170 | __vallocate(__n); |
Eric Fiselier | acfe6f0 | 2015-03-31 16:54:19 +0000 | [diff] [blame] | 1171 | __construct_at_end(__x.__begin_, __x.__end_, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1172 | } |
| 1173 | } |
| 1174 | |
Eric Fiselier | ed9e936 | 2017-04-16 02:40:45 +0000 | [diff] [blame] | 1175 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1176 | |
| 1177 | template <class _Tp, class _Allocator> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 1178 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1179 | vector<_Tp, _Allocator>::vector(vector&& __x) |
Marshall Clow | e510820 | 2015-07-14 14:46:32 +0000 | [diff] [blame] | 1180 | #if _LIBCPP_STD_VER > 14 |
| 1181 | _NOEXCEPT |
| 1182 | #else |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1183 | _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) |
Marshall Clow | e510820 | 2015-07-14 14:46:32 +0000 | [diff] [blame] | 1184 | #endif |
Nikolas Klauser | 129974f | 2022-02-03 23:09:37 +0100 | [diff] [blame] | 1185 | : __end_cap_(nullptr, _VSTD::move(__x.__alloc())) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1186 | { |
Nikolas Klauser | f280773 | 2022-01-11 00:33:35 +0100 | [diff] [blame] | 1187 | _VSTD::__debug_db_insert_c(this); |
Louis Dionne | ba40078 | 2020-10-02 15:02:52 -0400 | [diff] [blame] | 1188 | #if _LIBCPP_DEBUG_LEVEL == 2 |
Mark de Wever | 8f72c89 | 2021-10-10 15:40:50 +0200 | [diff] [blame] | 1189 | __get_db()->swap(this, _VSTD::addressof(__x)); |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1190 | #endif |
Howard Hinnant | 9cd2230 | 2011-09-16 18:41:29 +0000 | [diff] [blame] | 1191 | this->__begin_ = __x.__begin_; |
| 1192 | this->__end_ = __x.__end_; |
| 1193 | this->__end_cap() = __x.__end_cap(); |
Howard Hinnant | 76053d7 | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 1194 | __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1195 | } |
| 1196 | |
| 1197 | template <class _Tp, class _Allocator> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 1198 | inline _LIBCPP_INLINE_VISIBILITY |
Arthur O'Dwyer | 9b9662f | 2021-03-01 17:08:24 -0500 | [diff] [blame] | 1199 | vector<_Tp, _Allocator>::vector(vector&& __x, const __identity_t<allocator_type>& __a) |
Nikolas Klauser | 129974f | 2022-02-03 23:09:37 +0100 | [diff] [blame] | 1200 | : __end_cap_(nullptr, __a) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1201 | { |
Nikolas Klauser | f280773 | 2022-01-11 00:33:35 +0100 | [diff] [blame] | 1202 | _VSTD::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1203 | if (__a == __x.__alloc()) |
| 1204 | { |
| 1205 | this->__begin_ = __x.__begin_; |
| 1206 | this->__end_ = __x.__end_; |
| 1207 | this->__end_cap() = __x.__end_cap(); |
| 1208 | __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr; |
Louis Dionne | ba40078 | 2020-10-02 15:02:52 -0400 | [diff] [blame] | 1209 | #if _LIBCPP_DEBUG_LEVEL == 2 |
Mark de Wever | 8f72c89 | 2021-10-10 15:40:50 +0200 | [diff] [blame] | 1210 | __get_db()->swap(this, _VSTD::addressof(__x)); |
Howard Hinnant | a1e60cd | 2011-09-19 16:34:29 +0000 | [diff] [blame] | 1211 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1212 | } |
| 1213 | else |
| 1214 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1215 | typedef move_iterator<iterator> _Ip; |
| 1216 | assign(_Ip(__x.begin()), _Ip(__x.end())); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1217 | } |
| 1218 | } |
| 1219 | |
| 1220 | template <class _Tp, class _Allocator> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 1221 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1222 | vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il) |
| 1223 | { |
Nikolas Klauser | f280773 | 2022-01-11 00:33:35 +0100 | [diff] [blame] | 1224 | _VSTD::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1225 | if (__il.size() > 0) |
| 1226 | { |
Marshall Clow | 3ff48e0 | 2018-05-22 16:20:28 +0000 | [diff] [blame] | 1227 | __vallocate(__il.size()); |
Eric Fiselier | acfe6f0 | 2015-03-31 16:54:19 +0000 | [diff] [blame] | 1228 | __construct_at_end(__il.begin(), __il.end(), __il.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1229 | } |
| 1230 | } |
| 1231 | |
| 1232 | template <class _Tp, class _Allocator> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 1233 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1234 | vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a) |
Nikolas Klauser | 129974f | 2022-02-03 23:09:37 +0100 | [diff] [blame] | 1235 | : __end_cap_(nullptr, __a) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1236 | { |
Nikolas Klauser | f280773 | 2022-01-11 00:33:35 +0100 | [diff] [blame] | 1237 | _VSTD::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1238 | if (__il.size() > 0) |
| 1239 | { |
Marshall Clow | 3ff48e0 | 2018-05-22 16:20:28 +0000 | [diff] [blame] | 1240 | __vallocate(__il.size()); |
Eric Fiselier | acfe6f0 | 2015-03-31 16:54:19 +0000 | [diff] [blame] | 1241 | __construct_at_end(__il.begin(), __il.end(), __il.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1242 | } |
| 1243 | } |
| 1244 | |
| 1245 | template <class _Tp, class _Allocator> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 1246 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1247 | vector<_Tp, _Allocator>& |
| 1248 | vector<_Tp, _Allocator>::operator=(vector&& __x) |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 1249 | _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1250 | { |
| 1251 | __move_assign(__x, integral_constant<bool, |
| 1252 | __alloc_traits::propagate_on_container_move_assignment::value>()); |
| 1253 | return *this; |
| 1254 | } |
| 1255 | |
| 1256 | template <class _Tp, class _Allocator> |
| 1257 | void |
| 1258 | vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type) |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 1259 | _NOEXCEPT_(__alloc_traits::is_always_equal::value) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1260 | { |
Konstantin Varlamov | 5f23d66 | 2021-11-08 00:10:13 -0800 | [diff] [blame] | 1261 | if (__alloc() != __c.__alloc()) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1262 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1263 | typedef move_iterator<iterator> _Ip; |
| 1264 | assign(_Ip(__c.begin()), _Ip(__c.end())); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1265 | } |
| 1266 | else |
| 1267 | __move_assign(__c, true_type()); |
| 1268 | } |
| 1269 | |
| 1270 | template <class _Tp, class _Allocator> |
| 1271 | void |
| 1272 | vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type) |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1273 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1274 | { |
Marshall Clow | 3ff48e0 | 2018-05-22 16:20:28 +0000 | [diff] [blame] | 1275 | __vdeallocate(); |
Konstantin Varlamov | 5f23d66 | 2021-11-08 00:10:13 -0800 | [diff] [blame] | 1276 | __move_assign_alloc(__c); // this can throw |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1277 | this->__begin_ = __c.__begin_; |
| 1278 | this->__end_ = __c.__end_; |
| 1279 | this->__end_cap() = __c.__end_cap(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1280 | __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr; |
Louis Dionne | ba40078 | 2020-10-02 15:02:52 -0400 | [diff] [blame] | 1281 | #if _LIBCPP_DEBUG_LEVEL == 2 |
Mark de Wever | 8f72c89 | 2021-10-10 15:40:50 +0200 | [diff] [blame] | 1282 | __get_db()->swap(this, _VSTD::addressof(__c)); |
Howard Hinnant | a1e60cd | 2011-09-19 16:34:29 +0000 | [diff] [blame] | 1283 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1284 | } |
| 1285 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1286 | #endif // !_LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1287 | |
| 1288 | template <class _Tp, class _Allocator> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 1289 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1290 | vector<_Tp, _Allocator>& |
| 1291 | vector<_Tp, _Allocator>::operator=(const vector& __x) |
| 1292 | { |
Mark de Wever | 357a1fc | 2021-09-28 19:15:18 +0200 | [diff] [blame] | 1293 | if (this != _VSTD::addressof(__x)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1294 | { |
Konstantin Varlamov | 5f23d66 | 2021-11-08 00:10:13 -0800 | [diff] [blame] | 1295 | __copy_assign_alloc(__x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1296 | assign(__x.__begin_, __x.__end_); |
| 1297 | } |
| 1298 | return *this; |
| 1299 | } |
| 1300 | |
| 1301 | template <class _Tp, class _Allocator> |
| 1302 | template <class _InputIterator> |
| 1303 | typename enable_if |
| 1304 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 1305 | __is_cpp17_input_iterator <_InputIterator>::value && |
| 1306 | !__is_cpp17_forward_iterator<_InputIterator>::value && |
Howard Hinnant | 8801025 | 2013-03-28 17:44:32 +0000 | [diff] [blame] | 1307 | is_constructible< |
| 1308 | _Tp, |
| 1309 | typename iterator_traits<_InputIterator>::reference>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1310 | void |
| 1311 | >::type |
| 1312 | vector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last) |
| 1313 | { |
| 1314 | clear(); |
| 1315 | for (; __first != __last; ++__first) |
Eric Fiselier | 9691972 | 2017-10-17 13:03:17 +0000 | [diff] [blame] | 1316 | __emplace_back(*__first); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1317 | } |
| 1318 | |
| 1319 | template <class _Tp, class _Allocator> |
| 1320 | template <class _ForwardIterator> |
| 1321 | typename enable_if |
| 1322 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 1323 | __is_cpp17_forward_iterator<_ForwardIterator>::value && |
Howard Hinnant | 8801025 | 2013-03-28 17:44:32 +0000 | [diff] [blame] | 1324 | is_constructible< |
| 1325 | _Tp, |
| 1326 | typename iterator_traits<_ForwardIterator>::reference>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1327 | void |
| 1328 | >::type |
| 1329 | vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) |
| 1330 | { |
Eric Fiselier | acfe6f0 | 2015-03-31 16:54:19 +0000 | [diff] [blame] | 1331 | size_type __new_size = static_cast<size_type>(_VSTD::distance(__first, __last)); |
| 1332 | if (__new_size <= capacity()) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1333 | { |
| 1334 | _ForwardIterator __mid = __last; |
| 1335 | bool __growing = false; |
Eric Fiselier | acfe6f0 | 2015-03-31 16:54:19 +0000 | [diff] [blame] | 1336 | if (__new_size > size()) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1337 | { |
| 1338 | __growing = true; |
| 1339 | __mid = __first; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1340 | _VSTD::advance(__mid, size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1341 | } |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1342 | pointer __m = _VSTD::copy(__first, __mid, this->__begin_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1343 | if (__growing) |
Eric Fiselier | acfe6f0 | 2015-03-31 16:54:19 +0000 | [diff] [blame] | 1344 | __construct_at_end(__mid, __last, __new_size - size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1345 | else |
| 1346 | this->__destruct_at_end(__m); |
| 1347 | } |
| 1348 | else |
| 1349 | { |
Marshall Clow | 3ff48e0 | 2018-05-22 16:20:28 +0000 | [diff] [blame] | 1350 | __vdeallocate(); |
| 1351 | __vallocate(__recommend(__new_size)); |
Eric Fiselier | acfe6f0 | 2015-03-31 16:54:19 +0000 | [diff] [blame] | 1352 | __construct_at_end(__first, __last, __new_size); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1353 | } |
Eric Fiselier | 69c5198 | 2016-12-28 06:06:09 +0000 | [diff] [blame] | 1354 | __invalidate_all_iterators(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1355 | } |
| 1356 | |
| 1357 | template <class _Tp, class _Allocator> |
| 1358 | void |
| 1359 | vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u) |
| 1360 | { |
| 1361 | if (__n <= capacity()) |
| 1362 | { |
| 1363 | size_type __s = size(); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1364 | _VSTD::fill_n(this->__begin_, _VSTD::min(__n, __s), __u); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1365 | if (__n > __s) |
| 1366 | __construct_at_end(__n - __s, __u); |
| 1367 | else |
Howard Hinnant | 155c2af | 2010-05-24 17:49:41 +0000 | [diff] [blame] | 1368 | this->__destruct_at_end(this->__begin_ + __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1369 | } |
| 1370 | else |
| 1371 | { |
Marshall Clow | 3ff48e0 | 2018-05-22 16:20:28 +0000 | [diff] [blame] | 1372 | __vdeallocate(); |
| 1373 | __vallocate(__recommend(static_cast<size_type>(__n))); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1374 | __construct_at_end(__n, __u); |
| 1375 | } |
Eric Fiselier | 69c5198 | 2016-12-28 06:06:09 +0000 | [diff] [blame] | 1376 | __invalidate_all_iterators(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1377 | } |
| 1378 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1379 | template <class _Tp, class _Allocator> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 1380 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1381 | typename vector<_Tp, _Allocator>::iterator |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1382 | vector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1383 | { |
Louis Dionne | ba40078 | 2020-10-02 15:02:52 -0400 | [diff] [blame] | 1384 | #if _LIBCPP_DEBUG_LEVEL == 2 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1385 | return iterator(this, __p); |
| 1386 | #else |
| 1387 | return iterator(__p); |
| 1388 | #endif |
| 1389 | } |
| 1390 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1391 | template <class _Tp, class _Allocator> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 1392 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1393 | typename vector<_Tp, _Allocator>::const_iterator |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1394 | vector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1395 | { |
Louis Dionne | ba40078 | 2020-10-02 15:02:52 -0400 | [diff] [blame] | 1396 | #if _LIBCPP_DEBUG_LEVEL == 2 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1397 | return const_iterator(this, __p); |
| 1398 | #else |
| 1399 | return const_iterator(__p); |
| 1400 | #endif |
| 1401 | } |
| 1402 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1403 | template <class _Tp, class _Allocator> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 1404 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1405 | typename vector<_Tp, _Allocator>::iterator |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1406 | vector<_Tp, _Allocator>::begin() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1407 | { |
| 1408 | return __make_iter(this->__begin_); |
| 1409 | } |
| 1410 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1411 | template <class _Tp, class _Allocator> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 1412 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1413 | typename vector<_Tp, _Allocator>::const_iterator |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1414 | vector<_Tp, _Allocator>::begin() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1415 | { |
| 1416 | return __make_iter(this->__begin_); |
| 1417 | } |
| 1418 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1419 | template <class _Tp, class _Allocator> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 1420 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1421 | typename vector<_Tp, _Allocator>::iterator |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1422 | vector<_Tp, _Allocator>::end() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1423 | { |
| 1424 | return __make_iter(this->__end_); |
| 1425 | } |
| 1426 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1427 | template <class _Tp, class _Allocator> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 1428 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1429 | typename vector<_Tp, _Allocator>::const_iterator |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1430 | vector<_Tp, _Allocator>::end() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1431 | { |
| 1432 | return __make_iter(this->__end_); |
| 1433 | } |
| 1434 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1435 | template <class _Tp, class _Allocator> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 1436 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1437 | typename vector<_Tp, _Allocator>::reference |
Marshall Clow | d647049 | 2019-03-15 00:29:35 +0000 | [diff] [blame] | 1438 | vector<_Tp, _Allocator>::operator[](size_type __n) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1439 | { |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1440 | _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1441 | return this->__begin_[__n]; |
| 1442 | } |
| 1443 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1444 | template <class _Tp, class _Allocator> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 1445 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1446 | typename vector<_Tp, _Allocator>::const_reference |
Marshall Clow | d647049 | 2019-03-15 00:29:35 +0000 | [diff] [blame] | 1447 | vector<_Tp, _Allocator>::operator[](size_type __n) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1448 | { |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1449 | _LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1450 | return this->__begin_[__n]; |
| 1451 | } |
| 1452 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1453 | template <class _Tp, class _Allocator> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1454 | typename vector<_Tp, _Allocator>::reference |
| 1455 | vector<_Tp, _Allocator>::at(size_type __n) |
| 1456 | { |
| 1457 | if (__n >= size()) |
| 1458 | this->__throw_out_of_range(); |
| 1459 | return this->__begin_[__n]; |
| 1460 | } |
| 1461 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1462 | template <class _Tp, class _Allocator> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1463 | typename vector<_Tp, _Allocator>::const_reference |
| 1464 | vector<_Tp, _Allocator>::at(size_type __n) const |
| 1465 | { |
| 1466 | if (__n >= size()) |
| 1467 | this->__throw_out_of_range(); |
| 1468 | return this->__begin_[__n]; |
| 1469 | } |
| 1470 | |
| 1471 | template <class _Tp, class _Allocator> |
| 1472 | void |
| 1473 | vector<_Tp, _Allocator>::reserve(size_type __n) |
| 1474 | { |
| 1475 | if (__n > capacity()) |
| 1476 | { |
Mikhail Maltsev | 0b0a51d | 2021-10-21 10:40:05 +0100 | [diff] [blame] | 1477 | if (__n > max_size()) |
| 1478 | this->__throw_length_error(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1479 | allocator_type& __a = this->__alloc(); |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1480 | __split_buffer<value_type, allocator_type&> __v(__n, size(), __a); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1481 | __swap_out_circular_buffer(__v); |
| 1482 | } |
| 1483 | } |
| 1484 | |
| 1485 | template <class _Tp, class _Allocator> |
| 1486 | void |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1487 | vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1488 | { |
| 1489 | if (capacity() > size()) |
| 1490 | { |
| 1491 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1492 | try |
| 1493 | { |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1494 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1495 | allocator_type& __a = this->__alloc(); |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1496 | __split_buffer<value_type, allocator_type&> __v(size(), size(), __a); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1497 | __swap_out_circular_buffer(__v); |
| 1498 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1499 | } |
| 1500 | catch (...) |
| 1501 | { |
| 1502 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1503 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1504 | } |
| 1505 | } |
| 1506 | |
| 1507 | template <class _Tp, class _Allocator> |
Howard Hinnant | d2cab2f | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 1508 | template <class _Up> |
| 1509 | void |
Eric Fiselier | ed9e936 | 2017-04-16 02:40:45 +0000 | [diff] [blame] | 1510 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | d2cab2f | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 1511 | vector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x) |
| 1512 | #else |
| 1513 | vector<_Tp, _Allocator>::__push_back_slow_path(_Up& __x) |
| 1514 | #endif |
| 1515 | { |
| 1516 | allocator_type& __a = this->__alloc(); |
| 1517 | __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a); |
| 1518 | // __v.push_back(_VSTD::forward<_Up>(__x)); |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 1519 | __alloc_traits::construct(__a, _VSTD::__to_address(__v.__end_), _VSTD::forward<_Up>(__x)); |
Howard Hinnant | 5adee4c | 2013-01-11 20:36:59 +0000 | [diff] [blame] | 1520 | __v.__end_++; |
Howard Hinnant | d2cab2f | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 1521 | __swap_out_circular_buffer(__v); |
| 1522 | } |
| 1523 | |
| 1524 | template <class _Tp, class _Allocator> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 1525 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1526 | void |
| 1527 | vector<_Tp, _Allocator>::push_back(const_reference __x) |
| 1528 | { |
Howard Hinnant | d2cab2f | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 1529 | if (this->__end_ != this->__end_cap()) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1530 | { |
Eric Fiselier | e7afbd3 | 2019-07-28 04:37:02 +0000 | [diff] [blame] | 1531 | __construct_one_at_end(__x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1532 | } |
| 1533 | else |
Howard Hinnant | d2cab2f | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 1534 | __push_back_slow_path(__x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1535 | } |
| 1536 | |
Eric Fiselier | ed9e936 | 2017-04-16 02:40:45 +0000 | [diff] [blame] | 1537 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1538 | |
| 1539 | template <class _Tp, class _Allocator> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 1540 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1541 | void |
| 1542 | vector<_Tp, _Allocator>::push_back(value_type&& __x) |
| 1543 | { |
| 1544 | if (this->__end_ < this->__end_cap()) |
| 1545 | { |
Eric Fiselier | e7afbd3 | 2019-07-28 04:37:02 +0000 | [diff] [blame] | 1546 | __construct_one_at_end(_VSTD::move(__x)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1547 | } |
| 1548 | else |
Howard Hinnant | d2cab2f | 2012-02-15 00:41:34 +0000 | [diff] [blame] | 1549 | __push_back_slow_path(_VSTD::move(__x)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1550 | } |
| 1551 | |
| 1552 | template <class _Tp, class _Allocator> |
| 1553 | template <class... _Args> |
| 1554 | void |
Howard Hinnant | b6c4956 | 2012-02-26 15:30:12 +0000 | [diff] [blame] | 1555 | vector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args) |
| 1556 | { |
| 1557 | allocator_type& __a = this->__alloc(); |
| 1558 | __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a); |
| 1559 | // __v.emplace_back(_VSTD::forward<_Args>(__args)...); |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 1560 | __alloc_traits::construct(__a, _VSTD::__to_address(__v.__end_), _VSTD::forward<_Args>(__args)...); |
Howard Hinnant | 5adee4c | 2013-01-11 20:36:59 +0000 | [diff] [blame] | 1561 | __v.__end_++; |
Howard Hinnant | b6c4956 | 2012-02-26 15:30:12 +0000 | [diff] [blame] | 1562 | __swap_out_circular_buffer(__v); |
| 1563 | } |
| 1564 | |
| 1565 | template <class _Tp, class _Allocator> |
| 1566 | template <class... _Args> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1567 | inline |
Marshall Clow | ea52cc4 | 2017-01-24 23:09:12 +0000 | [diff] [blame] | 1568 | #if _LIBCPP_STD_VER > 14 |
Eric Fiselier | 34ba5b9 | 2016-07-21 03:20:17 +0000 | [diff] [blame] | 1569 | typename vector<_Tp, _Allocator>::reference |
Marshall Clow | ea52cc4 | 2017-01-24 23:09:12 +0000 | [diff] [blame] | 1570 | #else |
| 1571 | void |
| 1572 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1573 | vector<_Tp, _Allocator>::emplace_back(_Args&&... __args) |
| 1574 | { |
| 1575 | if (this->__end_ < this->__end_cap()) |
| 1576 | { |
Eric Fiselier | e7afbd3 | 2019-07-28 04:37:02 +0000 | [diff] [blame] | 1577 | __construct_one_at_end(_VSTD::forward<_Args>(__args)...); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1578 | } |
| 1579 | else |
Howard Hinnant | b6c4956 | 2012-02-26 15:30:12 +0000 | [diff] [blame] | 1580 | __emplace_back_slow_path(_VSTD::forward<_Args>(__args)...); |
Marshall Clow | ea52cc4 | 2017-01-24 23:09:12 +0000 | [diff] [blame] | 1581 | #if _LIBCPP_STD_VER > 14 |
Eric Fiselier | 34ba5b9 | 2016-07-21 03:20:17 +0000 | [diff] [blame] | 1582 | return this->back(); |
Marshall Clow | ea52cc4 | 2017-01-24 23:09:12 +0000 | [diff] [blame] | 1583 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1584 | } |
| 1585 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1586 | #endif // !_LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1587 | |
| 1588 | template <class _Tp, class _Allocator> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1589 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1590 | void |
| 1591 | vector<_Tp, _Allocator>::pop_back() |
| 1592 | { |
Kristina Bessonova | aeeaa7e | 2021-05-09 19:29:56 +0200 | [diff] [blame] | 1593 | _LIBCPP_ASSERT(!empty(), "vector::pop_back called on an empty vector"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1594 | this->__destruct_at_end(this->__end_ - 1); |
| 1595 | } |
| 1596 | |
| 1597 | template <class _Tp, class _Allocator> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 1598 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1599 | typename vector<_Tp, _Allocator>::iterator |
| 1600 | vector<_Tp, _Allocator>::erase(const_iterator __position) |
| 1601 | { |
Nikolas Klauser | c8984bf | 2022-01-15 20:23:29 +0100 | [diff] [blame] | 1602 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this, |
| 1603 | "vector::erase(iterator) called with an iterator not referring to this vector"); |
Howard Hinnant | 58d52d5 | 2013-03-25 22:12:26 +0000 | [diff] [blame] | 1604 | _LIBCPP_ASSERT(__position != end(), |
| 1605 | "vector::erase(iterator) called with a non-dereferenceable iterator"); |
Howard Hinnant | 76053d7 | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 1606 | difference_type __ps = __position - cbegin(); |
| 1607 | pointer __p = this->__begin_ + __ps; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1608 | this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p)); |
Eric Fiselier | 69c5198 | 2016-12-28 06:06:09 +0000 | [diff] [blame] | 1609 | this->__invalidate_iterators_past(__p-1); |
| 1610 | iterator __r = __make_iter(__p); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1611 | return __r; |
| 1612 | } |
| 1613 | |
| 1614 | template <class _Tp, class _Allocator> |
| 1615 | typename vector<_Tp, _Allocator>::iterator |
| 1616 | vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last) |
| 1617 | { |
Nikolas Klauser | c8984bf | 2022-01-15 20:23:29 +0100 | [diff] [blame] | 1618 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__first)) == this, |
| 1619 | "vector::erase(iterator, iterator) called with an iterator not referring to this vector"); |
| 1620 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__last)) == this, |
| 1621 | "vector::erase(iterator, iterator) called with an iterator not referring to this vector"); |
| 1622 | |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1623 | _LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1624 | pointer __p = this->__begin_ + (__first - begin()); |
Eric Fiselier | 69c5198 | 2016-12-28 06:06:09 +0000 | [diff] [blame] | 1625 | if (__first != __last) { |
Howard Hinnant | c580cc3 | 2013-04-18 15:02:57 +0000 | [diff] [blame] | 1626 | this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p)); |
Eric Fiselier | 69c5198 | 2016-12-28 06:06:09 +0000 | [diff] [blame] | 1627 | this->__invalidate_iterators_past(__p - 1); |
| 1628 | } |
| 1629 | iterator __r = __make_iter(__p); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1630 | return __r; |
| 1631 | } |
| 1632 | |
| 1633 | template <class _Tp, class _Allocator> |
| 1634 | void |
| 1635 | vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to) |
| 1636 | { |
| 1637 | pointer __old_last = this->__end_; |
| 1638 | difference_type __n = __old_last - __to; |
Eric Fiselier | e7afbd3 | 2019-07-28 04:37:02 +0000 | [diff] [blame] | 1639 | { |
| 1640 | pointer __i = __from_s + __n; |
| 1641 | _ConstructTransaction __tx(*this, __from_e - __i); |
Martijn Vels | 1e2e1b8 | 2020-06-18 13:14:02 -0400 | [diff] [blame] | 1642 | for (pointer __pos = __tx.__pos_; __i < __from_e; |
Arthur O'Dwyer | 80dbcbe | 2021-09-07 21:35:37 -0400 | [diff] [blame] | 1643 | ++__i, (void) ++__pos, __tx.__pos_ = __pos) { |
Eric Fiselier | e7afbd3 | 2019-07-28 04:37:02 +0000 | [diff] [blame] | 1644 | __alloc_traits::construct(this->__alloc(), |
Martijn Vels | 1e2e1b8 | 2020-06-18 13:14:02 -0400 | [diff] [blame] | 1645 | _VSTD::__to_address(__pos), |
Eric Fiselier | e7afbd3 | 2019-07-28 04:37:02 +0000 | [diff] [blame] | 1646 | _VSTD::move(*__i)); |
| 1647 | } |
| 1648 | } |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1649 | _VSTD::move_backward(__from_s, __from_s + __n, __old_last); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1650 | } |
| 1651 | |
| 1652 | template <class _Tp, class _Allocator> |
| 1653 | typename vector<_Tp, _Allocator>::iterator |
| 1654 | vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x) |
| 1655 | { |
Nikolas Klauser | c8984bf | 2022-01-15 20:23:29 +0100 | [diff] [blame] | 1656 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this, |
| 1657 | "vector::insert(iterator, x) called with an iterator not referring to this vector"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1658 | pointer __p = this->__begin_ + (__position - begin()); |
| 1659 | if (this->__end_ < this->__end_cap()) |
| 1660 | { |
| 1661 | if (__p == this->__end_) |
| 1662 | { |
Eric Fiselier | e7afbd3 | 2019-07-28 04:37:02 +0000 | [diff] [blame] | 1663 | __construct_one_at_end(__x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1664 | } |
| 1665 | else |
| 1666 | { |
| 1667 | __move_range(__p, this->__end_, __p + 1); |
| 1668 | const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x); |
| 1669 | if (__p <= __xr && __xr < this->__end_) |
| 1670 | ++__xr; |
| 1671 | *__p = *__xr; |
| 1672 | } |
| 1673 | } |
| 1674 | else |
| 1675 | { |
| 1676 | allocator_type& __a = this->__alloc(); |
| 1677 | __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a); |
| 1678 | __v.push_back(__x); |
| 1679 | __p = __swap_out_circular_buffer(__v, __p); |
| 1680 | } |
| 1681 | return __make_iter(__p); |
| 1682 | } |
| 1683 | |
Eric Fiselier | ed9e936 | 2017-04-16 02:40:45 +0000 | [diff] [blame] | 1684 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1685 | |
| 1686 | template <class _Tp, class _Allocator> |
| 1687 | typename vector<_Tp, _Allocator>::iterator |
| 1688 | vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x) |
| 1689 | { |
Nikolas Klauser | c8984bf | 2022-01-15 20:23:29 +0100 | [diff] [blame] | 1690 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this, |
| 1691 | "vector::insert(iterator, x) called with an iterator not referring to this vector"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1692 | pointer __p = this->__begin_ + (__position - begin()); |
| 1693 | if (this->__end_ < this->__end_cap()) |
| 1694 | { |
| 1695 | if (__p == this->__end_) |
| 1696 | { |
Eric Fiselier | e7afbd3 | 2019-07-28 04:37:02 +0000 | [diff] [blame] | 1697 | __construct_one_at_end(_VSTD::move(__x)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1698 | } |
| 1699 | else |
| 1700 | { |
| 1701 | __move_range(__p, this->__end_, __p + 1); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1702 | *__p = _VSTD::move(__x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1703 | } |
| 1704 | } |
| 1705 | else |
| 1706 | { |
| 1707 | allocator_type& __a = this->__alloc(); |
| 1708 | __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1709 | __v.push_back(_VSTD::move(__x)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1710 | __p = __swap_out_circular_buffer(__v, __p); |
| 1711 | } |
| 1712 | return __make_iter(__p); |
| 1713 | } |
| 1714 | |
| 1715 | template <class _Tp, class _Allocator> |
| 1716 | template <class... _Args> |
| 1717 | typename vector<_Tp, _Allocator>::iterator |
| 1718 | vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args) |
| 1719 | { |
Nikolas Klauser | c8984bf | 2022-01-15 20:23:29 +0100 | [diff] [blame] | 1720 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this, |
| 1721 | "vector::emplace(iterator, x) called with an iterator not referring to this vector"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1722 | pointer __p = this->__begin_ + (__position - begin()); |
| 1723 | if (this->__end_ < this->__end_cap()) |
| 1724 | { |
| 1725 | if (__p == this->__end_) |
| 1726 | { |
Eric Fiselier | e7afbd3 | 2019-07-28 04:37:02 +0000 | [diff] [blame] | 1727 | __construct_one_at_end(_VSTD::forward<_Args>(__args)...); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1728 | } |
| 1729 | else |
| 1730 | { |
Marshall Clow | a591b9a | 2016-07-11 21:38:08 +0000 | [diff] [blame] | 1731 | __temp_value<value_type, _Allocator> __tmp(this->__alloc(), _VSTD::forward<_Args>(__args)...); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1732 | __move_range(__p, this->__end_, __p + 1); |
Marshall Clow | a591b9a | 2016-07-11 21:38:08 +0000 | [diff] [blame] | 1733 | *__p = _VSTD::move(__tmp.get()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1734 | } |
| 1735 | } |
| 1736 | else |
| 1737 | { |
| 1738 | allocator_type& __a = this->__alloc(); |
| 1739 | __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1740 | __v.emplace_back(_VSTD::forward<_Args>(__args)...); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1741 | __p = __swap_out_circular_buffer(__v, __p); |
| 1742 | } |
| 1743 | return __make_iter(__p); |
| 1744 | } |
| 1745 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1746 | #endif // !_LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1747 | |
| 1748 | template <class _Tp, class _Allocator> |
| 1749 | typename vector<_Tp, _Allocator>::iterator |
| 1750 | vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x) |
| 1751 | { |
Nikolas Klauser | c8984bf | 2022-01-15 20:23:29 +0100 | [diff] [blame] | 1752 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this, |
| 1753 | "vector::insert(iterator, n, x) called with an iterator not referring to this vector"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1754 | pointer __p = this->__begin_ + (__position - begin()); |
| 1755 | if (__n > 0) |
| 1756 | { |
| 1757 | if (__n <= static_cast<size_type>(this->__end_cap() - this->__end_)) |
| 1758 | { |
| 1759 | size_type __old_n = __n; |
| 1760 | pointer __old_last = this->__end_; |
| 1761 | if (__n > static_cast<size_type>(this->__end_ - __p)) |
| 1762 | { |
| 1763 | size_type __cx = __n - (this->__end_ - __p); |
| 1764 | __construct_at_end(__cx, __x); |
| 1765 | __n -= __cx; |
| 1766 | } |
| 1767 | if (__n > 0) |
| 1768 | { |
| 1769 | __move_range(__p, __old_last, __p + __old_n); |
| 1770 | const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x); |
| 1771 | if (__p <= __xr && __xr < this->__end_) |
| 1772 | __xr += __old_n; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1773 | _VSTD::fill_n(__p, __n, *__xr); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1774 | } |
| 1775 | } |
| 1776 | else |
| 1777 | { |
| 1778 | allocator_type& __a = this->__alloc(); |
| 1779 | __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a); |
| 1780 | __v.__construct_at_end(__n, __x); |
| 1781 | __p = __swap_out_circular_buffer(__v, __p); |
| 1782 | } |
| 1783 | } |
| 1784 | return __make_iter(__p); |
| 1785 | } |
| 1786 | |
| 1787 | template <class _Tp, class _Allocator> |
| 1788 | template <class _InputIterator> |
| 1789 | typename enable_if |
| 1790 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 1791 | __is_cpp17_input_iterator <_InputIterator>::value && |
| 1792 | !__is_cpp17_forward_iterator<_InputIterator>::value && |
Howard Hinnant | 8801025 | 2013-03-28 17:44:32 +0000 | [diff] [blame] | 1793 | is_constructible< |
| 1794 | _Tp, |
| 1795 | typename iterator_traits<_InputIterator>::reference>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1796 | typename vector<_Tp, _Allocator>::iterator |
| 1797 | >::type |
| 1798 | vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last) |
| 1799 | { |
Nikolas Klauser | c8984bf | 2022-01-15 20:23:29 +0100 | [diff] [blame] | 1800 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this, |
| 1801 | "vector::insert(iterator, range) called with an iterator not referring to this vector"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1802 | difference_type __off = __position - begin(); |
| 1803 | pointer __p = this->__begin_ + __off; |
| 1804 | allocator_type& __a = this->__alloc(); |
| 1805 | pointer __old_last = this->__end_; |
| 1806 | for (; this->__end_ != this->__end_cap() && __first != __last; ++__first) |
| 1807 | { |
Eric Fiselier | e7afbd3 | 2019-07-28 04:37:02 +0000 | [diff] [blame] | 1808 | __construct_one_at_end(*__first); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1809 | } |
| 1810 | __split_buffer<value_type, allocator_type&> __v(__a); |
| 1811 | if (__first != __last) |
| 1812 | { |
| 1813 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1814 | try |
| 1815 | { |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1816 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1817 | __v.__construct_at_end(__first, __last); |
| 1818 | difference_type __old_size = __old_last - this->__begin_; |
| 1819 | difference_type __old_p = __p - this->__begin_; |
| 1820 | reserve(__recommend(size() + __v.size())); |
| 1821 | __p = this->__begin_ + __old_p; |
| 1822 | __old_last = this->__begin_ + __old_size; |
| 1823 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1824 | } |
| 1825 | catch (...) |
| 1826 | { |
| 1827 | erase(__make_iter(__old_last), end()); |
| 1828 | throw; |
| 1829 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1830 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1831 | } |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1832 | __p = _VSTD::rotate(__p, __old_last, this->__end_); |
Louis Dionne | 202a4cb | 2020-02-11 10:59:12 +0100 | [diff] [blame] | 1833 | insert(__make_iter(__p), _VSTD::make_move_iterator(__v.begin()), |
| 1834 | _VSTD::make_move_iterator(__v.end())); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1835 | return begin() + __off; |
| 1836 | } |
| 1837 | |
| 1838 | template <class _Tp, class _Allocator> |
| 1839 | template <class _ForwardIterator> |
| 1840 | typename enable_if |
| 1841 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 1842 | __is_cpp17_forward_iterator<_ForwardIterator>::value && |
Howard Hinnant | 8801025 | 2013-03-28 17:44:32 +0000 | [diff] [blame] | 1843 | is_constructible< |
| 1844 | _Tp, |
| 1845 | typename iterator_traits<_ForwardIterator>::reference>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1846 | typename vector<_Tp, _Allocator>::iterator |
| 1847 | >::type |
| 1848 | vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) |
| 1849 | { |
Nikolas Klauser | c8984bf | 2022-01-15 20:23:29 +0100 | [diff] [blame] | 1850 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__position)) == this, |
| 1851 | "vector::insert(iterator, range) called with an iterator not referring to this vector"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1852 | pointer __p = this->__begin_ + (__position - begin()); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1853 | difference_type __n = _VSTD::distance(__first, __last); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1854 | if (__n > 0) |
| 1855 | { |
| 1856 | if (__n <= this->__end_cap() - this->__end_) |
| 1857 | { |
| 1858 | size_type __old_n = __n; |
| 1859 | pointer __old_last = this->__end_; |
| 1860 | _ForwardIterator __m = __last; |
| 1861 | difference_type __dx = this->__end_ - __p; |
| 1862 | if (__n > __dx) |
| 1863 | { |
| 1864 | __m = __first; |
Eric Fiselier | acfe6f0 | 2015-03-31 16:54:19 +0000 | [diff] [blame] | 1865 | difference_type __diff = this->__end_ - __p; |
| 1866 | _VSTD::advance(__m, __diff); |
| 1867 | __construct_at_end(__m, __last, __n - __diff); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1868 | __n = __dx; |
| 1869 | } |
| 1870 | if (__n > 0) |
| 1871 | { |
| 1872 | __move_range(__p, __old_last, __p + __old_n); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1873 | _VSTD::copy(__first, __m, __p); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1874 | } |
| 1875 | } |
| 1876 | else |
| 1877 | { |
| 1878 | allocator_type& __a = this->__alloc(); |
| 1879 | __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a); |
| 1880 | __v.__construct_at_end(__first, __last); |
| 1881 | __p = __swap_out_circular_buffer(__v, __p); |
| 1882 | } |
| 1883 | } |
| 1884 | return __make_iter(__p); |
| 1885 | } |
| 1886 | |
| 1887 | template <class _Tp, class _Allocator> |
| 1888 | void |
| 1889 | vector<_Tp, _Allocator>::resize(size_type __sz) |
| 1890 | { |
| 1891 | size_type __cs = size(); |
| 1892 | if (__cs < __sz) |
| 1893 | this->__append(__sz - __cs); |
| 1894 | else if (__cs > __sz) |
| 1895 | this->__destruct_at_end(this->__begin_ + __sz); |
| 1896 | } |
| 1897 | |
| 1898 | template <class _Tp, class _Allocator> |
| 1899 | void |
| 1900 | vector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x) |
| 1901 | { |
| 1902 | size_type __cs = size(); |
| 1903 | if (__cs < __sz) |
| 1904 | this->__append(__sz - __cs, __x); |
| 1905 | else if (__cs > __sz) |
| 1906 | this->__destruct_at_end(this->__begin_ + __sz); |
| 1907 | } |
| 1908 | |
| 1909 | template <class _Tp, class _Allocator> |
| 1910 | void |
| 1911 | vector<_Tp, _Allocator>::swap(vector& __x) |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 1912 | #if _LIBCPP_STD_VER >= 14 |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1913 | _NOEXCEPT |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 1914 | #else |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1915 | _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 1916 | __is_nothrow_swappable<allocator_type>::value) |
| 1917 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1918 | { |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1919 | _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value || |
| 1920 | this->__alloc() == __x.__alloc(), |
| 1921 | "vector::swap: Either propagate_on_container_swap must be true" |
| 1922 | " or the allocators must compare equal"); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1923 | _VSTD::swap(this->__begin_, __x.__begin_); |
| 1924 | _VSTD::swap(this->__end_, __x.__end_); |
| 1925 | _VSTD::swap(this->__end_cap(), __x.__end_cap()); |
Arthur O'Dwyer | 4e0de31 | 2020-11-18 18:54:38 -0500 | [diff] [blame] | 1926 | _VSTD::__swap_allocator(this->__alloc(), __x.__alloc(), |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 1927 | integral_constant<bool,__alloc_traits::propagate_on_container_swap::value>()); |
Louis Dionne | ba40078 | 2020-10-02 15:02:52 -0400 | [diff] [blame] | 1928 | #if _LIBCPP_DEBUG_LEVEL == 2 |
Mark de Wever | 8f72c89 | 2021-10-10 15:40:50 +0200 | [diff] [blame] | 1929 | __get_db()->swap(this, _VSTD::addressof(__x)); |
Louis Dionne | ba40078 | 2020-10-02 15:02:52 -0400 | [diff] [blame] | 1930 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1931 | } |
| 1932 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1933 | template <class _Tp, class _Allocator> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1934 | bool |
| 1935 | vector<_Tp, _Allocator>::__invariants() const |
| 1936 | { |
Howard Hinnant | 76053d7 | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 1937 | if (this->__begin_ == nullptr) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1938 | { |
Howard Hinnant | 76053d7 | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 1939 | if (this->__end_ != nullptr || this->__end_cap() != nullptr) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1940 | return false; |
| 1941 | } |
| 1942 | else |
| 1943 | { |
| 1944 | if (this->__begin_ > this->__end_) |
| 1945 | return false; |
| 1946 | if (this->__begin_ == this->__end_cap()) |
| 1947 | return false; |
| 1948 | if (this->__end_ > this->__end_cap()) |
| 1949 | return false; |
| 1950 | } |
| 1951 | return true; |
| 1952 | } |
| 1953 | |
Louis Dionne | ba40078 | 2020-10-02 15:02:52 -0400 | [diff] [blame] | 1954 | #if _LIBCPP_DEBUG_LEVEL == 2 |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1955 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1956 | template <class _Tp, class _Allocator> |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1957 | bool |
| 1958 | vector<_Tp, _Allocator>::__dereferenceable(const const_iterator* __i) const |
| 1959 | { |
| 1960 | return this->__begin_ <= __i->base() && __i->base() < this->__end_; |
| 1961 | } |
| 1962 | |
| 1963 | template <class _Tp, class _Allocator> |
| 1964 | bool |
| 1965 | vector<_Tp, _Allocator>::__decrementable(const const_iterator* __i) const |
| 1966 | { |
| 1967 | return this->__begin_ < __i->base() && __i->base() <= this->__end_; |
| 1968 | } |
| 1969 | |
| 1970 | template <class _Tp, class _Allocator> |
| 1971 | bool |
| 1972 | vector<_Tp, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const |
| 1973 | { |
| 1974 | const_pointer __p = __i->base() + __n; |
| 1975 | return this->__begin_ <= __p && __p <= this->__end_; |
| 1976 | } |
| 1977 | |
| 1978 | template <class _Tp, class _Allocator> |
| 1979 | bool |
| 1980 | vector<_Tp, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const |
| 1981 | { |
| 1982 | const_pointer __p = __i->base() + __n; |
| 1983 | return this->__begin_ <= __p && __p < this->__end_; |
| 1984 | } |
| 1985 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1986 | #endif // _LIBCPP_DEBUG_LEVEL == 2 |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1987 | |
| 1988 | template <class _Tp, class _Allocator> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 1989 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1990 | void |
| 1991 | vector<_Tp, _Allocator>::__invalidate_all_iterators() |
| 1992 | { |
Louis Dionne | ba40078 | 2020-10-02 15:02:52 -0400 | [diff] [blame] | 1993 | #if _LIBCPP_DEBUG_LEVEL == 2 |
Howard Hinnant | 27e0e77 | 2011-09-14 18:33:51 +0000 | [diff] [blame] | 1994 | __get_db()->__invalidate_all(this); |
Louis Dionne | ba40078 | 2020-10-02 15:02:52 -0400 | [diff] [blame] | 1995 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1996 | } |
| 1997 | |
Eric Fiselier | 69c5198 | 2016-12-28 06:06:09 +0000 | [diff] [blame] | 1998 | |
| 1999 | template <class _Tp, class _Allocator> |
| 2000 | inline _LIBCPP_INLINE_VISIBILITY |
| 2001 | void |
| 2002 | vector<_Tp, _Allocator>::__invalidate_iterators_past(pointer __new_last) { |
Louis Dionne | ba40078 | 2020-10-02 15:02:52 -0400 | [diff] [blame] | 2003 | #if _LIBCPP_DEBUG_LEVEL == 2 |
Eric Fiselier | 69c5198 | 2016-12-28 06:06:09 +0000 | [diff] [blame] | 2004 | __c_node* __c = __get_db()->__find_c_and_lock(this); |
| 2005 | for (__i_node** __p = __c->end_; __p != __c->beg_; ) { |
| 2006 | --__p; |
| 2007 | const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); |
| 2008 | if (__i->base() > __new_last) { |
| 2009 | (*__p)->__c_ = nullptr; |
| 2010 | if (--__c->end_ != __p) |
Arthur O'Dwyer | 2223663 | 2020-12-07 21:50:15 -0500 | [diff] [blame] | 2011 | _VSTD::memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); |
Eric Fiselier | 69c5198 | 2016-12-28 06:06:09 +0000 | [diff] [blame] | 2012 | } |
| 2013 | } |
| 2014 | __get_db()->unlock(); |
| 2015 | #else |
| 2016 | ((void)__new_last); |
| 2017 | #endif |
| 2018 | } |
| 2019 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2020 | // vector<bool> |
| 2021 | |
| 2022 | template <class _Allocator> class vector<bool, _Allocator>; |
| 2023 | |
| 2024 | template <class _Allocator> struct hash<vector<bool, _Allocator> >; |
| 2025 | |
| 2026 | template <class _Allocator> |
Howard Hinnant | b4ef648 | 2011-07-02 20:33:23 +0000 | [diff] [blame] | 2027 | struct __has_storage_type<vector<bool, _Allocator> > |
| 2028 | { |
| 2029 | static const bool value = true; |
| 2030 | }; |
| 2031 | |
| 2032 | template <class _Allocator> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 2033 | class _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2034 | { |
| 2035 | public: |
| 2036 | typedef vector __self; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2037 | typedef bool value_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2038 | typedef _Allocator allocator_type; |
| 2039 | typedef allocator_traits<allocator_type> __alloc_traits; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2040 | typedef typename __alloc_traits::size_type size_type; |
| 2041 | typedef typename __alloc_traits::difference_type difference_type; |
Howard Hinnant | 896b762 | 2012-05-07 16:50:38 +0000 | [diff] [blame] | 2042 | typedef size_type __storage_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2043 | typedef __bit_iterator<vector, false> pointer; |
| 2044 | typedef __bit_iterator<vector, true> const_pointer; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2045 | typedef pointer iterator; |
| 2046 | typedef const_pointer const_iterator; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2047 | typedef _VSTD::reverse_iterator<iterator> reverse_iterator; |
| 2048 | typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2049 | |
| 2050 | private: |
Marshall Clow | 940e01c | 2015-04-07 05:21:38 +0000 | [diff] [blame] | 2051 | typedef typename __rebind_alloc_helper<__alloc_traits, __storage_type>::type __storage_allocator; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2052 | typedef allocator_traits<__storage_allocator> __storage_traits; |
| 2053 | typedef typename __storage_traits::pointer __storage_pointer; |
| 2054 | typedef typename __storage_traits::const_pointer __const_storage_pointer; |
| 2055 | |
| 2056 | __storage_pointer __begin_; |
| 2057 | size_type __size_; |
| 2058 | __compressed_pair<size_type, __storage_allocator> __cap_alloc_; |
Howard Hinnant | 71d1c19 | 2011-07-09 15:50:42 +0000 | [diff] [blame] | 2059 | public: |
Howard Hinnant | b4ef648 | 2011-07-02 20:33:23 +0000 | [diff] [blame] | 2060 | typedef __bit_reference<vector> reference; |
| 2061 | typedef __bit_const_reference<vector> const_reference; |
Howard Hinnant | 71d1c19 | 2011-07-09 15:50:42 +0000 | [diff] [blame] | 2062 | private: |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2063 | _LIBCPP_INLINE_VISIBILITY |
| 2064 | size_type& __cap() _NOEXCEPT |
| 2065 | {return __cap_alloc_.first();} |
| 2066 | _LIBCPP_INLINE_VISIBILITY |
| 2067 | const size_type& __cap() const _NOEXCEPT |
| 2068 | {return __cap_alloc_.first();} |
| 2069 | _LIBCPP_INLINE_VISIBILITY |
| 2070 | __storage_allocator& __alloc() _NOEXCEPT |
| 2071 | {return __cap_alloc_.second();} |
| 2072 | _LIBCPP_INLINE_VISIBILITY |
| 2073 | const __storage_allocator& __alloc() const _NOEXCEPT |
| 2074 | {return __cap_alloc_.second();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2075 | |
| 2076 | static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); |
| 2077 | |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2078 | _LIBCPP_INLINE_VISIBILITY |
| 2079 | static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2080 | {return __n * __bits_per_word;} |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2081 | _LIBCPP_INLINE_VISIBILITY |
| 2082 | static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2083 | {return (__n - 1) / __bits_per_word + 1;} |
| 2084 | |
| 2085 | public: |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2086 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | e546cbb | 2015-06-04 02:05:41 +0000 | [diff] [blame] | 2087 | vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value); |
Marshall Clow | 8f282f4 | 2015-06-04 00:10:20 +0000 | [diff] [blame] | 2088 | |
| 2089 | _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a) |
| 2090 | #if _LIBCPP_STD_VER <= 14 |
| 2091 | _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value); |
| 2092 | #else |
| 2093 | _NOEXCEPT; |
| 2094 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2095 | ~vector(); |
| 2096 | explicit vector(size_type __n); |
Marshall Clow | d3cbeaa | 2013-09-14 00:47:59 +0000 | [diff] [blame] | 2097 | #if _LIBCPP_STD_VER > 11 |
| 2098 | explicit vector(size_type __n, const allocator_type& __a); |
| 2099 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2100 | vector(size_type __n, const value_type& __v); |
| 2101 | vector(size_type __n, const value_type& __v, const allocator_type& __a); |
| 2102 | template <class _InputIterator> |
| 2103 | vector(_InputIterator __first, _InputIterator __last, |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 2104 | typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value && |
| 2105 | !__is_cpp17_forward_iterator<_InputIterator>::value>::type* = 0); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2106 | template <class _InputIterator> |
| 2107 | vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 2108 | typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value && |
| 2109 | !__is_cpp17_forward_iterator<_InputIterator>::value>::type* = 0); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2110 | template <class _ForwardIterator> |
| 2111 | vector(_ForwardIterator __first, _ForwardIterator __last, |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 2112 | typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type* = 0); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2113 | template <class _ForwardIterator> |
| 2114 | vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 2115 | typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type* = 0); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2116 | |
| 2117 | vector(const vector& __v); |
| 2118 | vector(const vector& __v, const allocator_type& __a); |
| 2119 | vector& operator=(const vector& __v); |
Eric Fiselier | ed9e936 | 2017-04-16 02:40:45 +0000 | [diff] [blame] | 2120 | |
| 2121 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2122 | vector(initializer_list<value_type> __il); |
| 2123 | vector(initializer_list<value_type> __il, const allocator_type& __a); |
| 2124 | |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2125 | _LIBCPP_INLINE_VISIBILITY |
| 2126 | vector(vector&& __v) |
Marshall Clow | e510820 | 2015-07-14 14:46:32 +0000 | [diff] [blame] | 2127 | #if _LIBCPP_STD_VER > 14 |
| 2128 | _NOEXCEPT; |
| 2129 | #else |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2130 | _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); |
Marshall Clow | e510820 | 2015-07-14 14:46:32 +0000 | [diff] [blame] | 2131 | #endif |
Arthur O'Dwyer | 9b9662f | 2021-03-01 17:08:24 -0500 | [diff] [blame] | 2132 | vector(vector&& __v, const __identity_t<allocator_type>& __a); |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2133 | _LIBCPP_INLINE_VISIBILITY |
| 2134 | vector& operator=(vector&& __v) |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 2135 | _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)); |
Eric Fiselier | ed9e936 | 2017-04-16 02:40:45 +0000 | [diff] [blame] | 2136 | |
Howard Hinnant | 1c265cd | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2137 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2138 | vector& operator=(initializer_list<value_type> __il) |
| 2139 | {assign(__il.begin(), __il.end()); return *this;} |
Eric Fiselier | ed9e936 | 2017-04-16 02:40:45 +0000 | [diff] [blame] | 2140 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2141 | #endif // !_LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2142 | |
| 2143 | template <class _InputIterator> |
| 2144 | typename enable_if |
| 2145 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 2146 | __is_cpp17_input_iterator<_InputIterator>::value && |
| 2147 | !__is_cpp17_forward_iterator<_InputIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2148 | void |
| 2149 | >::type |
| 2150 | assign(_InputIterator __first, _InputIterator __last); |
| 2151 | template <class _ForwardIterator> |
| 2152 | typename enable_if |
| 2153 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 2154 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2155 | void |
| 2156 | >::type |
| 2157 | assign(_ForwardIterator __first, _ForwardIterator __last); |
| 2158 | |
| 2159 | void assign(size_type __n, const value_type& __x); |
Eric Fiselier | ed9e936 | 2017-04-16 02:40:45 +0000 | [diff] [blame] | 2160 | |
| 2161 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 1c265cd | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2162 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2163 | void assign(initializer_list<value_type> __il) |
| 2164 | {assign(__il.begin(), __il.end());} |
Eric Fiselier | ed9e936 | 2017-04-16 02:40:45 +0000 | [diff] [blame] | 2165 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2166 | |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2167 | _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2168 | {return allocator_type(this->__alloc());} |
| 2169 | |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2170 | size_type max_size() const _NOEXCEPT; |
| 2171 | _LIBCPP_INLINE_VISIBILITY |
| 2172 | size_type capacity() const _NOEXCEPT |
| 2173 | {return __internal_cap_to_external(__cap());} |
| 2174 | _LIBCPP_INLINE_VISIBILITY |
| 2175 | size_type size() const _NOEXCEPT |
| 2176 | {return __size_;} |
Marshall Clow | 425f575 | 2017-11-15 05:51:26 +0000 | [diff] [blame] | 2177 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2178 | bool empty() const _NOEXCEPT |
| 2179 | {return __size_ == 0;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2180 | void reserve(size_type __n); |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2181 | void shrink_to_fit() _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2182 | |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2183 | _LIBCPP_INLINE_VISIBILITY |
| 2184 | iterator begin() _NOEXCEPT |
| 2185 | {return __make_iter(0);} |
| 2186 | _LIBCPP_INLINE_VISIBILITY |
| 2187 | const_iterator begin() const _NOEXCEPT |
| 2188 | {return __make_iter(0);} |
| 2189 | _LIBCPP_INLINE_VISIBILITY |
| 2190 | iterator end() _NOEXCEPT |
| 2191 | {return __make_iter(__size_);} |
| 2192 | _LIBCPP_INLINE_VISIBILITY |
| 2193 | const_iterator end() const _NOEXCEPT |
| 2194 | {return __make_iter(__size_);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2195 | |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2196 | _LIBCPP_INLINE_VISIBILITY |
| 2197 | reverse_iterator rbegin() _NOEXCEPT |
| 2198 | {return reverse_iterator(end());} |
| 2199 | _LIBCPP_INLINE_VISIBILITY |
| 2200 | const_reverse_iterator rbegin() const _NOEXCEPT |
| 2201 | {return const_reverse_iterator(end());} |
| 2202 | _LIBCPP_INLINE_VISIBILITY |
| 2203 | reverse_iterator rend() _NOEXCEPT |
| 2204 | {return reverse_iterator(begin());} |
| 2205 | _LIBCPP_INLINE_VISIBILITY |
| 2206 | const_reverse_iterator rend() const _NOEXCEPT |
| 2207 | {return const_reverse_iterator(begin());} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2208 | |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2209 | _LIBCPP_INLINE_VISIBILITY |
| 2210 | const_iterator cbegin() const _NOEXCEPT |
| 2211 | {return __make_iter(0);} |
| 2212 | _LIBCPP_INLINE_VISIBILITY |
| 2213 | const_iterator cend() const _NOEXCEPT |
| 2214 | {return __make_iter(__size_);} |
| 2215 | _LIBCPP_INLINE_VISIBILITY |
| 2216 | const_reverse_iterator crbegin() const _NOEXCEPT |
| 2217 | {return rbegin();} |
| 2218 | _LIBCPP_INLINE_VISIBILITY |
| 2219 | const_reverse_iterator crend() const _NOEXCEPT |
| 2220 | {return rend();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2221 | |
| 2222 | _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) {return __make_ref(__n);} |
| 2223 | _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __make_ref(__n);} |
| 2224 | reference at(size_type __n); |
| 2225 | const_reference at(size_type __n) const; |
| 2226 | |
| 2227 | _LIBCPP_INLINE_VISIBILITY reference front() {return __make_ref(0);} |
| 2228 | _LIBCPP_INLINE_VISIBILITY const_reference front() const {return __make_ref(0);} |
| 2229 | _LIBCPP_INLINE_VISIBILITY reference back() {return __make_ref(__size_ - 1);} |
| 2230 | _LIBCPP_INLINE_VISIBILITY const_reference back() const {return __make_ref(__size_ - 1);} |
| 2231 | |
| 2232 | void push_back(const value_type& __x); |
Marshall Clow | c46bb8e | 2013-08-13 23:54:12 +0000 | [diff] [blame] | 2233 | #if _LIBCPP_STD_VER > 11 |
| 2234 | template <class... _Args> |
Marshall Clow | ea52cc4 | 2017-01-24 23:09:12 +0000 | [diff] [blame] | 2235 | #if _LIBCPP_STD_VER > 14 |
| 2236 | _LIBCPP_INLINE_VISIBILITY reference emplace_back(_Args&&... __args) |
| 2237 | #else |
| 2238 | _LIBCPP_INLINE_VISIBILITY void emplace_back(_Args&&... __args) |
| 2239 | #endif |
| 2240 | { |
Eric Fiselier | 34ba5b9 | 2016-07-21 03:20:17 +0000 | [diff] [blame] | 2241 | push_back ( value_type ( _VSTD::forward<_Args>(__args)... )); |
Marshall Clow | ea52cc4 | 2017-01-24 23:09:12 +0000 | [diff] [blame] | 2242 | #if _LIBCPP_STD_VER > 14 |
Eric Fiselier | 34ba5b9 | 2016-07-21 03:20:17 +0000 | [diff] [blame] | 2243 | return this->back(); |
Marshall Clow | ea52cc4 | 2017-01-24 23:09:12 +0000 | [diff] [blame] | 2244 | #endif |
Eric Fiselier | 34ba5b9 | 2016-07-21 03:20:17 +0000 | [diff] [blame] | 2245 | } |
Marshall Clow | c46bb8e | 2013-08-13 23:54:12 +0000 | [diff] [blame] | 2246 | #endif |
| 2247 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2248 | _LIBCPP_INLINE_VISIBILITY void pop_back() {--__size_;} |
| 2249 | |
Marshall Clow | c46bb8e | 2013-08-13 23:54:12 +0000 | [diff] [blame] | 2250 | #if _LIBCPP_STD_VER > 11 |
| 2251 | template <class... _Args> |
| 2252 | _LIBCPP_INLINE_VISIBILITY iterator emplace(const_iterator position, _Args&&... __args) |
| 2253 | { return insert ( position, value_type ( _VSTD::forward<_Args>(__args)... )); } |
| 2254 | #endif |
| 2255 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2256 | iterator insert(const_iterator __position, const value_type& __x); |
| 2257 | iterator insert(const_iterator __position, size_type __n, const value_type& __x); |
| 2258 | iterator insert(const_iterator __position, size_type __n, const_reference __x); |
| 2259 | template <class _InputIterator> |
| 2260 | typename enable_if |
| 2261 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 2262 | __is_cpp17_input_iterator <_InputIterator>::value && |
| 2263 | !__is_cpp17_forward_iterator<_InputIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2264 | iterator |
| 2265 | >::type |
| 2266 | insert(const_iterator __position, _InputIterator __first, _InputIterator __last); |
| 2267 | template <class _ForwardIterator> |
| 2268 | typename enable_if |
| 2269 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 2270 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2271 | iterator |
| 2272 | >::type |
| 2273 | insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last); |
Eric Fiselier | ed9e936 | 2017-04-16 02:40:45 +0000 | [diff] [blame] | 2274 | |
| 2275 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 1c265cd | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2276 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2277 | iterator insert(const_iterator __position, initializer_list<value_type> __il) |
| 2278 | {return insert(__position, __il.begin(), __il.end());} |
Eric Fiselier | ed9e936 | 2017-04-16 02:40:45 +0000 | [diff] [blame] | 2279 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2280 | |
Howard Hinnant | cf82332 | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 2281 | _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2282 | iterator erase(const_iterator __first, const_iterator __last); |
| 2283 | |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2284 | _LIBCPP_INLINE_VISIBILITY |
| 2285 | void clear() _NOEXCEPT {__size_ = 0;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2286 | |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2287 | void swap(vector&) |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 2288 | #if _LIBCPP_STD_VER >= 14 |
| 2289 | _NOEXCEPT; |
| 2290 | #else |
Eric Fiselier | 69c5198 | 2016-12-28 06:06:09 +0000 | [diff] [blame] | 2291 | _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 2292 | __is_nothrow_swappable<allocator_type>::value); |
| 2293 | #endif |
Marshall Clow | 89eb382 | 2016-04-07 14:20:31 +0000 | [diff] [blame] | 2294 | static void swap(reference __x, reference __y) _NOEXCEPT { _VSTD::swap(__x, __y); } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2295 | |
| 2296 | void resize(size_type __sz, value_type __x = false); |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2297 | void flip() _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2298 | |
| 2299 | bool __invariants() const; |
| 2300 | |
| 2301 | private: |
Nikolas Klauser | 129974f | 2022-02-03 23:09:37 +0100 | [diff] [blame] | 2302 | _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI |
| 2303 | void __throw_length_error() const { |
| 2304 | _VSTD::__throw_length_error("vector"); |
| 2305 | } |
| 2306 | |
| 2307 | _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI |
| 2308 | void __throw_out_of_range() const { |
| 2309 | _VSTD::__throw_out_of_range("vector"); |
| 2310 | } |
| 2311 | |
Howard Hinnant | cf82332 | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 2312 | _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators(); |
Marshall Clow | 3ff48e0 | 2018-05-22 16:20:28 +0000 | [diff] [blame] | 2313 | void __vallocate(size_type __n); |
| 2314 | void __vdeallocate() _NOEXCEPT; |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2315 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ea38295 | 2013-08-14 18:00:20 +0000 | [diff] [blame] | 2316 | static size_type __align_it(size_type __new_size) _NOEXCEPT |
Eric Fiselier | b41db9a | 2018-10-01 01:59:37 +0000 | [diff] [blame] | 2317 | {return __new_size + (__bits_per_word-1) & ~((size_type)__bits_per_word-1);} |
Howard Hinnant | cf82332 | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 2318 | _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const; |
| 2319 | _LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, bool __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2320 | template <class _ForwardIterator> |
| 2321 | typename enable_if |
| 2322 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 2323 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2324 | void |
| 2325 | >::type |
| 2326 | __construct_at_end(_ForwardIterator __first, _ForwardIterator __last); |
| 2327 | void __append(size_type __n, const_reference __x); |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2328 | _LIBCPP_INLINE_VISIBILITY |
| 2329 | reference __make_ref(size_type __pos) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2330 | {return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2331 | _LIBCPP_INLINE_VISIBILITY |
| 2332 | const_reference __make_ref(size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2333 | {return const_reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2334 | _LIBCPP_INLINE_VISIBILITY |
| 2335 | iterator __make_iter(size_type __pos) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2336 | {return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));} |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2337 | _LIBCPP_INLINE_VISIBILITY |
| 2338 | const_iterator __make_iter(size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2339 | {return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));} |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2340 | _LIBCPP_INLINE_VISIBILITY |
| 2341 | iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT |
Howard Hinnant | 76053d7 | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2342 | {return begin() + (__p - cbegin());} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2343 | |
Howard Hinnant | 1c265cd | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2344 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2345 | void __copy_assign_alloc(const vector& __v) |
| 2346 | {__copy_assign_alloc(__v, integral_constant<bool, |
| 2347 | __storage_traits::propagate_on_container_copy_assignment::value>());} |
Howard Hinnant | 1c265cd | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2348 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2349 | void __copy_assign_alloc(const vector& __c, true_type) |
| 2350 | { |
| 2351 | if (__alloc() != __c.__alloc()) |
Marshall Clow | 3ff48e0 | 2018-05-22 16:20:28 +0000 | [diff] [blame] | 2352 | __vdeallocate(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2353 | __alloc() = __c.__alloc(); |
| 2354 | } |
| 2355 | |
Howard Hinnant | 1c265cd | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2356 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 2357 | void __copy_assign_alloc(const vector&, false_type) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2358 | {} |
| 2359 | |
| 2360 | void __move_assign(vector& __c, false_type); |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2361 | void __move_assign(vector& __c, true_type) |
| 2362 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); |
Howard Hinnant | 1c265cd | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2363 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2364 | void __move_assign_alloc(vector& __c) |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2365 | _NOEXCEPT_( |
| 2366 | !__storage_traits::propagate_on_container_move_assignment::value || |
| 2367 | is_nothrow_move_assignable<allocator_type>::value) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2368 | {__move_assign_alloc(__c, integral_constant<bool, |
| 2369 | __storage_traits::propagate_on_container_move_assignment::value>());} |
Howard Hinnant | 1c265cd | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2370 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c273496 | 2011-09-02 20:42:31 +0000 | [diff] [blame] | 2371 | void __move_assign_alloc(vector& __c, true_type) |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2372 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2373 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2374 | __alloc() = _VSTD::move(__c.__alloc()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2375 | } |
| 2376 | |
Howard Hinnant | 1c265cd | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2377 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 2378 | void __move_assign_alloc(vector&, false_type) |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2379 | _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2380 | {} |
| 2381 | |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2382 | size_t __hash_code() const _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2383 | |
| 2384 | friend class __bit_reference<vector>; |
| 2385 | friend class __bit_const_reference<vector>; |
| 2386 | friend class __bit_iterator<vector, false>; |
| 2387 | friend class __bit_iterator<vector, true>; |
Howard Hinnant | 4210a0f | 2012-08-17 17:10:18 +0000 | [diff] [blame] | 2388 | friend struct __bit_array<vector>; |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 2389 | friend struct _LIBCPP_TEMPLATE_VIS hash<vector>; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2390 | }; |
| 2391 | |
| 2392 | template <class _Allocator> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 2393 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2394 | void |
| 2395 | vector<bool, _Allocator>::__invalidate_all_iterators() |
| 2396 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2397 | } |
| 2398 | |
| 2399 | // Allocate space for __n objects |
| 2400 | // throws length_error if __n > max_size() |
| 2401 | // throws (probably bad_alloc) if memory run out |
| 2402 | // Precondition: __begin_ == __end_ == __cap() == 0 |
| 2403 | // Precondition: __n > 0 |
| 2404 | // Postcondition: capacity() == __n |
| 2405 | // Postcondition: size() == 0 |
| 2406 | template <class _Allocator> |
| 2407 | void |
Marshall Clow | 3ff48e0 | 2018-05-22 16:20:28 +0000 | [diff] [blame] | 2408 | vector<bool, _Allocator>::__vallocate(size_type __n) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2409 | { |
| 2410 | if (__n > max_size()) |
| 2411 | this->__throw_length_error(); |
| 2412 | __n = __external_cap_to_internal(__n); |
| 2413 | this->__begin_ = __storage_traits::allocate(this->__alloc(), __n); |
| 2414 | this->__size_ = 0; |
| 2415 | this->__cap() = __n; |
| 2416 | } |
| 2417 | |
| 2418 | template <class _Allocator> |
| 2419 | void |
Marshall Clow | 3ff48e0 | 2018-05-22 16:20:28 +0000 | [diff] [blame] | 2420 | vector<bool, _Allocator>::__vdeallocate() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2421 | { |
Howard Hinnant | 76053d7 | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2422 | if (this->__begin_ != nullptr) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2423 | { |
| 2424 | __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap()); |
| 2425 | __invalidate_all_iterators(); |
Howard Hinnant | 76053d7 | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2426 | this->__begin_ = nullptr; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2427 | this->__size_ = this->__cap() = 0; |
| 2428 | } |
| 2429 | } |
| 2430 | |
| 2431 | template <class _Allocator> |
| 2432 | typename vector<bool, _Allocator>::size_type |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2433 | vector<bool, _Allocator>::max_size() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2434 | { |
| 2435 | size_type __amax = __storage_traits::max_size(__alloc()); |
| 2436 | size_type __nmax = numeric_limits<size_type>::max() / 2; // end() >= begin(), always |
| 2437 | if (__nmax / __bits_per_word <= __amax) |
| 2438 | return __nmax; |
| 2439 | return __internal_cap_to_external(__amax); |
| 2440 | } |
| 2441 | |
| 2442 | // Precondition: __new_size > capacity() |
| 2443 | template <class _Allocator> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 2444 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2445 | typename vector<bool, _Allocator>::size_type |
| 2446 | vector<bool, _Allocator>::__recommend(size_type __new_size) const |
| 2447 | { |
| 2448 | const size_type __ms = max_size(); |
| 2449 | if (__new_size > __ms) |
| 2450 | this->__throw_length_error(); |
| 2451 | const size_type __cap = capacity(); |
| 2452 | if (__cap >= __ms / 2) |
| 2453 | return __ms; |
Arthur O'Dwyer | c0fb14b | 2021-07-26 18:23:00 -0400 | [diff] [blame] | 2454 | return _VSTD::max(2 * __cap, __align_it(__new_size)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2455 | } |
| 2456 | |
| 2457 | // Default constructs __n objects starting at __end_ |
| 2458 | // Precondition: __n > 0 |
| 2459 | // Precondition: size() + __n <= capacity() |
| 2460 | // Postcondition: size() == size() + __n |
| 2461 | template <class _Allocator> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 2462 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2463 | void |
| 2464 | vector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x) |
| 2465 | { |
| 2466 | size_type __old_size = this->__size_; |
| 2467 | this->__size_ += __n; |
Marshall Clow | 1893ec7 | 2018-10-23 20:07:45 +0000 | [diff] [blame] | 2468 | if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word)) |
| 2469 | { |
| 2470 | if (this->__size_ <= __bits_per_word) |
| 2471 | this->__begin_[0] = __storage_type(0); |
| 2472 | else |
| 2473 | this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0); |
| 2474 | } |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2475 | _VSTD::fill_n(__make_iter(__old_size), __n, __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2476 | } |
| 2477 | |
| 2478 | template <class _Allocator> |
| 2479 | template <class _ForwardIterator> |
| 2480 | typename enable_if |
| 2481 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 2482 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2483 | void |
| 2484 | >::type |
| 2485 | vector<bool, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last) |
| 2486 | { |
| 2487 | size_type __old_size = this->__size_; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2488 | this->__size_ += _VSTD::distance(__first, __last); |
Marshall Clow | 1893ec7 | 2018-10-23 20:07:45 +0000 | [diff] [blame] | 2489 | if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word)) |
| 2490 | { |
| 2491 | if (this->__size_ <= __bits_per_word) |
| 2492 | this->__begin_[0] = __storage_type(0); |
| 2493 | else |
| 2494 | this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0); |
| 2495 | } |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2496 | _VSTD::copy(__first, __last, __make_iter(__old_size)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2497 | } |
| 2498 | |
| 2499 | template <class _Allocator> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 2500 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2501 | vector<bool, _Allocator>::vector() |
Marshall Clow | e546cbb | 2015-06-04 02:05:41 +0000 | [diff] [blame] | 2502 | _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) |
Howard Hinnant | 76053d7 | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2503 | : __begin_(nullptr), |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2504 | __size_(0), |
Eric Fiselier | 33ebfb6 | 2019-12-16 18:23:39 -0500 | [diff] [blame] | 2505 | __cap_alloc_(0, __default_init_tag()) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2506 | { |
| 2507 | } |
| 2508 | |
| 2509 | template <class _Allocator> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 2510 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2511 | vector<bool, _Allocator>::vector(const allocator_type& __a) |
Marshall Clow | 8f282f4 | 2015-06-04 00:10:20 +0000 | [diff] [blame] | 2512 | #if _LIBCPP_STD_VER <= 14 |
| 2513 | _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value) |
| 2514 | #else |
| 2515 | _NOEXCEPT |
| 2516 | #endif |
Howard Hinnant | 76053d7 | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2517 | : __begin_(nullptr), |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2518 | __size_(0), |
| 2519 | __cap_alloc_(0, static_cast<__storage_allocator>(__a)) |
| 2520 | { |
| 2521 | } |
| 2522 | |
| 2523 | template <class _Allocator> |
| 2524 | vector<bool, _Allocator>::vector(size_type __n) |
Howard Hinnant | 76053d7 | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2525 | : __begin_(nullptr), |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2526 | __size_(0), |
Eric Fiselier | 33ebfb6 | 2019-12-16 18:23:39 -0500 | [diff] [blame] | 2527 | __cap_alloc_(0, __default_init_tag()) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2528 | { |
| 2529 | if (__n > 0) |
| 2530 | { |
Marshall Clow | 3ff48e0 | 2018-05-22 16:20:28 +0000 | [diff] [blame] | 2531 | __vallocate(__n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2532 | __construct_at_end(__n, false); |
| 2533 | } |
| 2534 | } |
| 2535 | |
Marshall Clow | d3cbeaa | 2013-09-14 00:47:59 +0000 | [diff] [blame] | 2536 | #if _LIBCPP_STD_VER > 11 |
| 2537 | template <class _Allocator> |
| 2538 | vector<bool, _Allocator>::vector(size_type __n, const allocator_type& __a) |
| 2539 | : __begin_(nullptr), |
| 2540 | __size_(0), |
| 2541 | __cap_alloc_(0, static_cast<__storage_allocator>(__a)) |
| 2542 | { |
| 2543 | if (__n > 0) |
| 2544 | { |
Marshall Clow | 3ff48e0 | 2018-05-22 16:20:28 +0000 | [diff] [blame] | 2545 | __vallocate(__n); |
Marshall Clow | d3cbeaa | 2013-09-14 00:47:59 +0000 | [diff] [blame] | 2546 | __construct_at_end(__n, false); |
| 2547 | } |
| 2548 | } |
| 2549 | #endif |
| 2550 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2551 | template <class _Allocator> |
| 2552 | vector<bool, _Allocator>::vector(size_type __n, const value_type& __x) |
Howard Hinnant | 76053d7 | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2553 | : __begin_(nullptr), |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2554 | __size_(0), |
Eric Fiselier | 33ebfb6 | 2019-12-16 18:23:39 -0500 | [diff] [blame] | 2555 | __cap_alloc_(0, __default_init_tag()) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2556 | { |
| 2557 | if (__n > 0) |
| 2558 | { |
Marshall Clow | 3ff48e0 | 2018-05-22 16:20:28 +0000 | [diff] [blame] | 2559 | __vallocate(__n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2560 | __construct_at_end(__n, __x); |
| 2561 | } |
| 2562 | } |
| 2563 | |
| 2564 | template <class _Allocator> |
| 2565 | vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a) |
Howard Hinnant | 76053d7 | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2566 | : __begin_(nullptr), |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2567 | __size_(0), |
| 2568 | __cap_alloc_(0, static_cast<__storage_allocator>(__a)) |
| 2569 | { |
| 2570 | if (__n > 0) |
| 2571 | { |
Marshall Clow | 3ff48e0 | 2018-05-22 16:20:28 +0000 | [diff] [blame] | 2572 | __vallocate(__n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2573 | __construct_at_end(__n, __x); |
| 2574 | } |
| 2575 | } |
| 2576 | |
| 2577 | template <class _Allocator> |
| 2578 | template <class _InputIterator> |
| 2579 | vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 2580 | typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value && |
| 2581 | !__is_cpp17_forward_iterator<_InputIterator>::value>::type*) |
Howard Hinnant | 76053d7 | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2582 | : __begin_(nullptr), |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2583 | __size_(0), |
Eric Fiselier | 33ebfb6 | 2019-12-16 18:23:39 -0500 | [diff] [blame] | 2584 | __cap_alloc_(0, __default_init_tag()) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2585 | { |
| 2586 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2587 | try |
| 2588 | { |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2589 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2590 | for (; __first != __last; ++__first) |
| 2591 | push_back(*__first); |
| 2592 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2593 | } |
| 2594 | catch (...) |
| 2595 | { |
Howard Hinnant | 76053d7 | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2596 | if (__begin_ != nullptr) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2597 | __storage_traits::deallocate(__alloc(), __begin_, __cap()); |
| 2598 | __invalidate_all_iterators(); |
| 2599 | throw; |
| 2600 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2601 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2602 | } |
| 2603 | |
| 2604 | template <class _Allocator> |
| 2605 | template <class _InputIterator> |
| 2606 | vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 2607 | typename enable_if<__is_cpp17_input_iterator <_InputIterator>::value && |
| 2608 | !__is_cpp17_forward_iterator<_InputIterator>::value>::type*) |
Howard Hinnant | 76053d7 | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2609 | : __begin_(nullptr), |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2610 | __size_(0), |
| 2611 | __cap_alloc_(0, static_cast<__storage_allocator>(__a)) |
| 2612 | { |
| 2613 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2614 | try |
| 2615 | { |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2616 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2617 | for (; __first != __last; ++__first) |
| 2618 | push_back(*__first); |
| 2619 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2620 | } |
| 2621 | catch (...) |
| 2622 | { |
Howard Hinnant | 76053d7 | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2623 | if (__begin_ != nullptr) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2624 | __storage_traits::deallocate(__alloc(), __begin_, __cap()); |
| 2625 | __invalidate_all_iterators(); |
| 2626 | throw; |
| 2627 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2628 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2629 | } |
| 2630 | |
| 2631 | template <class _Allocator> |
| 2632 | template <class _ForwardIterator> |
| 2633 | vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 2634 | typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type*) |
Howard Hinnant | 76053d7 | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2635 | : __begin_(nullptr), |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2636 | __size_(0), |
Eric Fiselier | 33ebfb6 | 2019-12-16 18:23:39 -0500 | [diff] [blame] | 2637 | __cap_alloc_(0, __default_init_tag()) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2638 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2639 | size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2640 | if (__n > 0) |
| 2641 | { |
Marshall Clow | 3ff48e0 | 2018-05-22 16:20:28 +0000 | [diff] [blame] | 2642 | __vallocate(__n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2643 | __construct_at_end(__first, __last); |
| 2644 | } |
| 2645 | } |
| 2646 | |
| 2647 | template <class _Allocator> |
| 2648 | template <class _ForwardIterator> |
| 2649 | vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 2650 | typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value>::type*) |
Howard Hinnant | 76053d7 | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2651 | : __begin_(nullptr), |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2652 | __size_(0), |
| 2653 | __cap_alloc_(0, static_cast<__storage_allocator>(__a)) |
| 2654 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2655 | size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2656 | if (__n > 0) |
| 2657 | { |
Marshall Clow | 3ff48e0 | 2018-05-22 16:20:28 +0000 | [diff] [blame] | 2658 | __vallocate(__n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2659 | __construct_at_end(__first, __last); |
| 2660 | } |
| 2661 | } |
| 2662 | |
Eric Fiselier | ed9e936 | 2017-04-16 02:40:45 +0000 | [diff] [blame] | 2663 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2664 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2665 | template <class _Allocator> |
| 2666 | vector<bool, _Allocator>::vector(initializer_list<value_type> __il) |
Howard Hinnant | 76053d7 | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2667 | : __begin_(nullptr), |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2668 | __size_(0), |
Eric Fiselier | 33ebfb6 | 2019-12-16 18:23:39 -0500 | [diff] [blame] | 2669 | __cap_alloc_(0, __default_init_tag()) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2670 | { |
| 2671 | size_type __n = static_cast<size_type>(__il.size()); |
| 2672 | if (__n > 0) |
| 2673 | { |
Marshall Clow | 3ff48e0 | 2018-05-22 16:20:28 +0000 | [diff] [blame] | 2674 | __vallocate(__n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2675 | __construct_at_end(__il.begin(), __il.end()); |
| 2676 | } |
| 2677 | } |
| 2678 | |
| 2679 | template <class _Allocator> |
| 2680 | vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a) |
Howard Hinnant | 76053d7 | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2681 | : __begin_(nullptr), |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2682 | __size_(0), |
| 2683 | __cap_alloc_(0, static_cast<__storage_allocator>(__a)) |
| 2684 | { |
| 2685 | size_type __n = static_cast<size_type>(__il.size()); |
| 2686 | if (__n > 0) |
| 2687 | { |
Marshall Clow | 3ff48e0 | 2018-05-22 16:20:28 +0000 | [diff] [blame] | 2688 | __vallocate(__n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2689 | __construct_at_end(__il.begin(), __il.end()); |
| 2690 | } |
| 2691 | } |
| 2692 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2693 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2694 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2695 | template <class _Allocator> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2696 | vector<bool, _Allocator>::~vector() |
| 2697 | { |
Howard Hinnant | 76053d7 | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2698 | if (__begin_ != nullptr) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2699 | __storage_traits::deallocate(__alloc(), __begin_, __cap()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2700 | __invalidate_all_iterators(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2701 | } |
| 2702 | |
| 2703 | template <class _Allocator> |
| 2704 | vector<bool, _Allocator>::vector(const vector& __v) |
Howard Hinnant | 76053d7 | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2705 | : __begin_(nullptr), |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2706 | __size_(0), |
| 2707 | __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc())) |
| 2708 | { |
| 2709 | if (__v.size() > 0) |
| 2710 | { |
Marshall Clow | 3ff48e0 | 2018-05-22 16:20:28 +0000 | [diff] [blame] | 2711 | __vallocate(__v.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2712 | __construct_at_end(__v.begin(), __v.end()); |
| 2713 | } |
| 2714 | } |
| 2715 | |
| 2716 | template <class _Allocator> |
| 2717 | vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a) |
Howard Hinnant | 76053d7 | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2718 | : __begin_(nullptr), |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2719 | __size_(0), |
| 2720 | __cap_alloc_(0, __a) |
| 2721 | { |
| 2722 | if (__v.size() > 0) |
| 2723 | { |
Marshall Clow | 3ff48e0 | 2018-05-22 16:20:28 +0000 | [diff] [blame] | 2724 | __vallocate(__v.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2725 | __construct_at_end(__v.begin(), __v.end()); |
| 2726 | } |
| 2727 | } |
| 2728 | |
| 2729 | template <class _Allocator> |
| 2730 | vector<bool, _Allocator>& |
| 2731 | vector<bool, _Allocator>::operator=(const vector& __v) |
| 2732 | { |
Mark de Wever | 357a1fc | 2021-09-28 19:15:18 +0200 | [diff] [blame] | 2733 | if (this != _VSTD::addressof(__v)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2734 | { |
| 2735 | __copy_assign_alloc(__v); |
| 2736 | if (__v.__size_) |
| 2737 | { |
| 2738 | if (__v.__size_ > capacity()) |
| 2739 | { |
Marshall Clow | 3ff48e0 | 2018-05-22 16:20:28 +0000 | [diff] [blame] | 2740 | __vdeallocate(); |
| 2741 | __vallocate(__v.__size_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2742 | } |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2743 | _VSTD::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2744 | } |
| 2745 | __size_ = __v.__size_; |
| 2746 | } |
| 2747 | return *this; |
| 2748 | } |
| 2749 | |
Eric Fiselier | ed9e936 | 2017-04-16 02:40:45 +0000 | [diff] [blame] | 2750 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2751 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2752 | template <class _Allocator> |
Eric Fiselier | 4f1534c | 2018-06-05 22:32:52 +0000 | [diff] [blame] | 2753 | inline _LIBCPP_INLINE_VISIBILITY vector<bool, _Allocator>::vector(vector&& __v) |
Marshall Clow | e510820 | 2015-07-14 14:46:32 +0000 | [diff] [blame] | 2754 | #if _LIBCPP_STD_VER > 14 |
Eric Fiselier | 4f1534c | 2018-06-05 22:32:52 +0000 | [diff] [blame] | 2755 | _NOEXCEPT |
Marshall Clow | e510820 | 2015-07-14 14:46:32 +0000 | [diff] [blame] | 2756 | #else |
Eric Fiselier | 4f1534c | 2018-06-05 22:32:52 +0000 | [diff] [blame] | 2757 | _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) |
Marshall Clow | e510820 | 2015-07-14 14:46:32 +0000 | [diff] [blame] | 2758 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2759 | : __begin_(__v.__begin_), |
| 2760 | __size_(__v.__size_), |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 2761 | __cap_alloc_(_VSTD::move(__v.__cap_alloc_)) { |
Howard Hinnant | 76053d7 | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2762 | __v.__begin_ = nullptr; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2763 | __v.__size_ = 0; |
| 2764 | __v.__cap() = 0; |
| 2765 | } |
| 2766 | |
| 2767 | template <class _Allocator> |
Arthur O'Dwyer | 9b9662f | 2021-03-01 17:08:24 -0500 | [diff] [blame] | 2768 | vector<bool, _Allocator>::vector(vector&& __v, const __identity_t<allocator_type>& __a) |
Howard Hinnant | 76053d7 | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 2769 | : __begin_(nullptr), |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2770 | __size_(0), |
| 2771 | __cap_alloc_(0, __a) |
| 2772 | { |
| 2773 | if (__a == allocator_type(__v.__alloc())) |
| 2774 | { |
| 2775 | this->__begin_ = __v.__begin_; |
| 2776 | this->__size_ = __v.__size_; |
| 2777 | this->__cap() = __v.__cap(); |
| 2778 | __v.__begin_ = nullptr; |
| 2779 | __v.__cap() = __v.__size_ = 0; |
| 2780 | } |
| 2781 | else if (__v.size() > 0) |
| 2782 | { |
Marshall Clow | 3ff48e0 | 2018-05-22 16:20:28 +0000 | [diff] [blame] | 2783 | __vallocate(__v.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2784 | __construct_at_end(__v.begin(), __v.end()); |
| 2785 | } |
| 2786 | } |
| 2787 | |
| 2788 | template <class _Allocator> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 2789 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2790 | vector<bool, _Allocator>& |
| 2791 | vector<bool, _Allocator>::operator=(vector&& __v) |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 2792 | _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2793 | { |
| 2794 | __move_assign(__v, integral_constant<bool, |
| 2795 | __storage_traits::propagate_on_container_move_assignment::value>()); |
Argyrios Kyrtzidis | af90465 | 2012-10-13 02:03:45 +0000 | [diff] [blame] | 2796 | return *this; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2797 | } |
| 2798 | |
| 2799 | template <class _Allocator> |
| 2800 | void |
| 2801 | vector<bool, _Allocator>::__move_assign(vector& __c, false_type) |
| 2802 | { |
| 2803 | if (__alloc() != __c.__alloc()) |
| 2804 | assign(__c.begin(), __c.end()); |
| 2805 | else |
| 2806 | __move_assign(__c, true_type()); |
| 2807 | } |
| 2808 | |
| 2809 | template <class _Allocator> |
| 2810 | void |
| 2811 | vector<bool, _Allocator>::__move_assign(vector& __c, true_type) |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2812 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2813 | { |
Marshall Clow | 3ff48e0 | 2018-05-22 16:20:28 +0000 | [diff] [blame] | 2814 | __vdeallocate(); |
Marshall Clow | b4871fa | 2014-07-21 15:15:15 +0000 | [diff] [blame] | 2815 | __move_assign_alloc(__c); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2816 | this->__begin_ = __c.__begin_; |
| 2817 | this->__size_ = __c.__size_; |
| 2818 | this->__cap() = __c.__cap(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2819 | __c.__begin_ = nullptr; |
| 2820 | __c.__cap() = __c.__size_ = 0; |
| 2821 | } |
Howard Hinnant | 74279a5 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2822 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2823 | #endif // !_LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2824 | |
| 2825 | template <class _Allocator> |
| 2826 | void |
| 2827 | vector<bool, _Allocator>::assign(size_type __n, const value_type& __x) |
| 2828 | { |
| 2829 | __size_ = 0; |
| 2830 | if (__n > 0) |
| 2831 | { |
| 2832 | size_type __c = capacity(); |
| 2833 | if (__n <= __c) |
| 2834 | __size_ = __n; |
| 2835 | else |
| 2836 | { |
Mikhail Maltsev | f56b069 | 2021-10-21 10:38:56 +0100 | [diff] [blame] | 2837 | vector __v(get_allocator()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2838 | __v.reserve(__recommend(__n)); |
| 2839 | __v.__size_ = __n; |
| 2840 | swap(__v); |
| 2841 | } |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2842 | _VSTD::fill_n(begin(), __n, __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2843 | } |
Eric Fiselier | 69c5198 | 2016-12-28 06:06:09 +0000 | [diff] [blame] | 2844 | __invalidate_all_iterators(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2845 | } |
| 2846 | |
| 2847 | template <class _Allocator> |
| 2848 | template <class _InputIterator> |
| 2849 | typename enable_if |
| 2850 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 2851 | __is_cpp17_input_iterator<_InputIterator>::value && |
| 2852 | !__is_cpp17_forward_iterator<_InputIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2853 | void |
| 2854 | >::type |
| 2855 | vector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last) |
| 2856 | { |
| 2857 | clear(); |
| 2858 | for (; __first != __last; ++__first) |
| 2859 | push_back(*__first); |
| 2860 | } |
| 2861 | |
| 2862 | template <class _Allocator> |
| 2863 | template <class _ForwardIterator> |
| 2864 | typename enable_if |
| 2865 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 2866 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2867 | void |
| 2868 | >::type |
| 2869 | vector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) |
| 2870 | { |
| 2871 | clear(); |
Eric Fiselier | 6003c77 | 2016-12-23 23:37:52 +0000 | [diff] [blame] | 2872 | difference_type __ns = _VSTD::distance(__first, __last); |
| 2873 | _LIBCPP_ASSERT(__ns >= 0, "invalid range specified"); |
| 2874 | const size_t __n = static_cast<size_type>(__ns); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2875 | if (__n) |
| 2876 | { |
| 2877 | if (__n > capacity()) |
| 2878 | { |
Marshall Clow | 3ff48e0 | 2018-05-22 16:20:28 +0000 | [diff] [blame] | 2879 | __vdeallocate(); |
| 2880 | __vallocate(__n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2881 | } |
| 2882 | __construct_at_end(__first, __last); |
| 2883 | } |
| 2884 | } |
| 2885 | |
| 2886 | template <class _Allocator> |
| 2887 | void |
| 2888 | vector<bool, _Allocator>::reserve(size_type __n) |
| 2889 | { |
| 2890 | if (__n > capacity()) |
| 2891 | { |
Mikhail Maltsev | 0b0a51d | 2021-10-21 10:40:05 +0100 | [diff] [blame] | 2892 | if (__n > max_size()) |
| 2893 | this->__throw_length_error(); |
Mikhail Maltsev | f56b069 | 2021-10-21 10:38:56 +0100 | [diff] [blame] | 2894 | vector __v(this->get_allocator()); |
Marshall Clow | 3ff48e0 | 2018-05-22 16:20:28 +0000 | [diff] [blame] | 2895 | __v.__vallocate(__n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2896 | __v.__construct_at_end(this->begin(), this->end()); |
| 2897 | swap(__v); |
| 2898 | __invalidate_all_iterators(); |
| 2899 | } |
| 2900 | } |
| 2901 | |
| 2902 | template <class _Allocator> |
| 2903 | void |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2904 | vector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2905 | { |
| 2906 | if (__external_cap_to_internal(size()) > __cap()) |
| 2907 | { |
| 2908 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2909 | try |
| 2910 | { |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2911 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2912 | vector(*this, allocator_type(__alloc())).swap(*this); |
| 2913 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2914 | } |
| 2915 | catch (...) |
| 2916 | { |
| 2917 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2918 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2919 | } |
| 2920 | } |
| 2921 | |
| 2922 | template <class _Allocator> |
| 2923 | typename vector<bool, _Allocator>::reference |
| 2924 | vector<bool, _Allocator>::at(size_type __n) |
| 2925 | { |
| 2926 | if (__n >= size()) |
| 2927 | this->__throw_out_of_range(); |
| 2928 | return (*this)[__n]; |
| 2929 | } |
| 2930 | |
| 2931 | template <class _Allocator> |
| 2932 | typename vector<bool, _Allocator>::const_reference |
| 2933 | vector<bool, _Allocator>::at(size_type __n) const |
| 2934 | { |
| 2935 | if (__n >= size()) |
| 2936 | this->__throw_out_of_range(); |
| 2937 | return (*this)[__n]; |
| 2938 | } |
| 2939 | |
| 2940 | template <class _Allocator> |
| 2941 | void |
| 2942 | vector<bool, _Allocator>::push_back(const value_type& __x) |
| 2943 | { |
| 2944 | if (this->__size_ == this->capacity()) |
| 2945 | reserve(__recommend(this->__size_ + 1)); |
| 2946 | ++this->__size_; |
| 2947 | back() = __x; |
| 2948 | } |
| 2949 | |
| 2950 | template <class _Allocator> |
| 2951 | typename vector<bool, _Allocator>::iterator |
| 2952 | vector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x) |
| 2953 | { |
| 2954 | iterator __r; |
| 2955 | if (size() < capacity()) |
| 2956 | { |
| 2957 | const_iterator __old_end = end(); |
| 2958 | ++__size_; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2959 | _VSTD::copy_backward(__position, __old_end, end()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2960 | __r = __const_iterator_cast(__position); |
| 2961 | } |
| 2962 | else |
| 2963 | { |
Mikhail Maltsev | f56b069 | 2021-10-21 10:38:56 +0100 | [diff] [blame] | 2964 | vector __v(get_allocator()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2965 | __v.reserve(__recommend(__size_ + 1)); |
| 2966 | __v.__size_ = __size_ + 1; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2967 | __r = _VSTD::copy(cbegin(), __position, __v.begin()); |
| 2968 | _VSTD::copy_backward(__position, cend(), __v.end()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2969 | swap(__v); |
| 2970 | } |
| 2971 | *__r = __x; |
| 2972 | return __r; |
| 2973 | } |
| 2974 | |
| 2975 | template <class _Allocator> |
| 2976 | typename vector<bool, _Allocator>::iterator |
| 2977 | vector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x) |
| 2978 | { |
| 2979 | iterator __r; |
| 2980 | size_type __c = capacity(); |
| 2981 | if (__n <= __c && size() <= __c - __n) |
| 2982 | { |
| 2983 | const_iterator __old_end = end(); |
| 2984 | __size_ += __n; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2985 | _VSTD::copy_backward(__position, __old_end, end()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2986 | __r = __const_iterator_cast(__position); |
| 2987 | } |
| 2988 | else |
| 2989 | { |
Mikhail Maltsev | f56b069 | 2021-10-21 10:38:56 +0100 | [diff] [blame] | 2990 | vector __v(get_allocator()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2991 | __v.reserve(__recommend(__size_ + __n)); |
| 2992 | __v.__size_ = __size_ + __n; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2993 | __r = _VSTD::copy(cbegin(), __position, __v.begin()); |
| 2994 | _VSTD::copy_backward(__position, cend(), __v.end()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2995 | swap(__v); |
| 2996 | } |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2997 | _VSTD::fill_n(__r, __n, __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2998 | return __r; |
| 2999 | } |
| 3000 | |
| 3001 | template <class _Allocator> |
| 3002 | template <class _InputIterator> |
| 3003 | typename enable_if |
| 3004 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 3005 | __is_cpp17_input_iterator <_InputIterator>::value && |
| 3006 | !__is_cpp17_forward_iterator<_InputIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3007 | typename vector<bool, _Allocator>::iterator |
| 3008 | >::type |
| 3009 | vector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last) |
| 3010 | { |
| 3011 | difference_type __off = __position - begin(); |
| 3012 | iterator __p = __const_iterator_cast(__position); |
| 3013 | iterator __old_end = end(); |
| 3014 | for (; size() != capacity() && __first != __last; ++__first) |
| 3015 | { |
| 3016 | ++this->__size_; |
| 3017 | back() = *__first; |
| 3018 | } |
Mikhail Maltsev | f56b069 | 2021-10-21 10:38:56 +0100 | [diff] [blame] | 3019 | vector __v(get_allocator()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3020 | if (__first != __last) |
| 3021 | { |
| 3022 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3023 | try |
| 3024 | { |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 3025 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3026 | __v.assign(__first, __last); |
| 3027 | difference_type __old_size = static_cast<difference_type>(__old_end - begin()); |
| 3028 | difference_type __old_p = __p - begin(); |
| 3029 | reserve(__recommend(size() + __v.size())); |
| 3030 | __p = begin() + __old_p; |
| 3031 | __old_end = begin() + __old_size; |
| 3032 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3033 | } |
| 3034 | catch (...) |
| 3035 | { |
| 3036 | erase(__old_end, end()); |
| 3037 | throw; |
| 3038 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 3039 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3040 | } |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3041 | __p = _VSTD::rotate(__p, __old_end, end()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3042 | insert(__p, __v.begin(), __v.end()); |
| 3043 | return begin() + __off; |
| 3044 | } |
| 3045 | |
| 3046 | template <class _Allocator> |
| 3047 | template <class _ForwardIterator> |
| 3048 | typename enable_if |
| 3049 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 3050 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3051 | typename vector<bool, _Allocator>::iterator |
| 3052 | >::type |
| 3053 | vector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) |
| 3054 | { |
Eric Fiselier | 654dd33 | 2016-12-11 05:31:00 +0000 | [diff] [blame] | 3055 | const difference_type __n_signed = _VSTD::distance(__first, __last); |
| 3056 | _LIBCPP_ASSERT(__n_signed >= 0, "invalid range specified"); |
| 3057 | const size_type __n = static_cast<size_type>(__n_signed); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3058 | iterator __r; |
| 3059 | size_type __c = capacity(); |
| 3060 | if (__n <= __c && size() <= __c - __n) |
| 3061 | { |
| 3062 | const_iterator __old_end = end(); |
| 3063 | __size_ += __n; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3064 | _VSTD::copy_backward(__position, __old_end, end()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3065 | __r = __const_iterator_cast(__position); |
| 3066 | } |
| 3067 | else |
| 3068 | { |
Mikhail Maltsev | f56b069 | 2021-10-21 10:38:56 +0100 | [diff] [blame] | 3069 | vector __v(get_allocator()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3070 | __v.reserve(__recommend(__size_ + __n)); |
| 3071 | __v.__size_ = __size_ + __n; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3072 | __r = _VSTD::copy(cbegin(), __position, __v.begin()); |
| 3073 | _VSTD::copy_backward(__position, cend(), __v.end()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3074 | swap(__v); |
| 3075 | } |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3076 | _VSTD::copy(__first, __last, __r); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3077 | return __r; |
| 3078 | } |
| 3079 | |
| 3080 | template <class _Allocator> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3081 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3082 | typename vector<bool, _Allocator>::iterator |
| 3083 | vector<bool, _Allocator>::erase(const_iterator __position) |
| 3084 | { |
| 3085 | iterator __r = __const_iterator_cast(__position); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3086 | _VSTD::copy(__position + 1, this->cend(), __r); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3087 | --__size_; |
| 3088 | return __r; |
| 3089 | } |
| 3090 | |
| 3091 | template <class _Allocator> |
| 3092 | typename vector<bool, _Allocator>::iterator |
| 3093 | vector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last) |
| 3094 | { |
| 3095 | iterator __r = __const_iterator_cast(__first); |
| 3096 | difference_type __d = __last - __first; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3097 | _VSTD::copy(__last, this->cend(), __r); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3098 | __size_ -= __d; |
| 3099 | return __r; |
| 3100 | } |
| 3101 | |
| 3102 | template <class _Allocator> |
| 3103 | void |
| 3104 | vector<bool, _Allocator>::swap(vector& __x) |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 3105 | #if _LIBCPP_STD_VER >= 14 |
| 3106 | _NOEXCEPT |
| 3107 | #else |
Eric Fiselier | 69c5198 | 2016-12-28 06:06:09 +0000 | [diff] [blame] | 3108 | _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 3109 | __is_nothrow_swappable<allocator_type>::value) |
| 3110 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3111 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3112 | _VSTD::swap(this->__begin_, __x.__begin_); |
| 3113 | _VSTD::swap(this->__size_, __x.__size_); |
| 3114 | _VSTD::swap(this->__cap(), __x.__cap()); |
Arthur O'Dwyer | 4e0de31 | 2020-11-18 18:54:38 -0500 | [diff] [blame] | 3115 | _VSTD::__swap_allocator(this->__alloc(), __x.__alloc(), |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 3116 | integral_constant<bool, __alloc_traits::propagate_on_container_swap::value>()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3117 | } |
| 3118 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3119 | template <class _Allocator> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3120 | void |
| 3121 | vector<bool, _Allocator>::resize(size_type __sz, value_type __x) |
| 3122 | { |
| 3123 | size_type __cs = size(); |
| 3124 | if (__cs < __sz) |
| 3125 | { |
| 3126 | iterator __r; |
| 3127 | size_type __c = capacity(); |
| 3128 | size_type __n = __sz - __cs; |
| 3129 | if (__n <= __c && __cs <= __c - __n) |
| 3130 | { |
| 3131 | __r = end(); |
| 3132 | __size_ += __n; |
| 3133 | } |
| 3134 | else |
| 3135 | { |
Mikhail Maltsev | f56b069 | 2021-10-21 10:38:56 +0100 | [diff] [blame] | 3136 | vector __v(get_allocator()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3137 | __v.reserve(__recommend(__size_ + __n)); |
| 3138 | __v.__size_ = __size_ + __n; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3139 | __r = _VSTD::copy(cbegin(), cend(), __v.begin()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3140 | swap(__v); |
| 3141 | } |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3142 | _VSTD::fill_n(__r, __n, __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3143 | } |
| 3144 | else |
| 3145 | __size_ = __sz; |
| 3146 | } |
| 3147 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3148 | template <class _Allocator> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3149 | void |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 3150 | vector<bool, _Allocator>::flip() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3151 | { |
| 3152 | // do middle whole words |
| 3153 | size_type __n = __size_; |
| 3154 | __storage_pointer __p = __begin_; |
| 3155 | for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) |
| 3156 | *__p = ~*__p; |
| 3157 | // do last partial word |
| 3158 | if (__n > 0) |
| 3159 | { |
| 3160 | __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); |
| 3161 | __storage_type __b = *__p & __m; |
| 3162 | *__p &= ~__m; |
| 3163 | *__p |= ~__b & __m; |
| 3164 | } |
| 3165 | } |
| 3166 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3167 | template <class _Allocator> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3168 | bool |
| 3169 | vector<bool, _Allocator>::__invariants() const |
| 3170 | { |
Howard Hinnant | 76053d7 | 2013-06-27 19:35:32 +0000 | [diff] [blame] | 3171 | if (this->__begin_ == nullptr) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3172 | { |
| 3173 | if (this->__size_ != 0 || this->__cap() != 0) |
| 3174 | return false; |
| 3175 | } |
| 3176 | else |
| 3177 | { |
| 3178 | if (this->__cap() == 0) |
| 3179 | return false; |
| 3180 | if (this->__size_ > this->capacity()) |
| 3181 | return false; |
| 3182 | } |
| 3183 | return true; |
| 3184 | } |
| 3185 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3186 | template <class _Allocator> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3187 | size_t |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 3188 | vector<bool, _Allocator>::__hash_code() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3189 | { |
| 3190 | size_t __h = 0; |
| 3191 | // do middle whole words |
| 3192 | size_type __n = __size_; |
| 3193 | __storage_pointer __p = __begin_; |
| 3194 | for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) |
| 3195 | __h ^= *__p; |
| 3196 | // do last partial word |
| 3197 | if (__n > 0) |
| 3198 | { |
| 3199 | const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); |
| 3200 | __h ^= *__p & __m; |
| 3201 | } |
| 3202 | return __h; |
| 3203 | } |
| 3204 | |
| 3205 | template <class _Allocator> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3206 | struct _LIBCPP_TEMPLATE_VIS hash<vector<bool, _Allocator> > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3207 | : public unary_function<vector<bool, _Allocator>, size_t> |
| 3208 | { |
Howard Hinnant | 1c265cd | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 3209 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 3210 | size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3211 | {return __vec.__hash_code();} |
| 3212 | }; |
| 3213 | |
| 3214 | template <class _Tp, class _Allocator> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3215 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3216 | bool |
| 3217 | operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) |
| 3218 | { |
| 3219 | const typename vector<_Tp, _Allocator>::size_type __sz = __x.size(); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3220 | return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3221 | } |
| 3222 | |
| 3223 | template <class _Tp, class _Allocator> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3224 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3225 | bool |
| 3226 | operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) |
| 3227 | { |
| 3228 | return !(__x == __y); |
| 3229 | } |
| 3230 | |
| 3231 | template <class _Tp, class _Allocator> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3232 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3233 | bool |
| 3234 | operator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) |
| 3235 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3236 | return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3237 | } |
| 3238 | |
| 3239 | template <class _Tp, class _Allocator> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3240 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3241 | bool |
| 3242 | operator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) |
| 3243 | { |
| 3244 | return __y < __x; |
| 3245 | } |
| 3246 | |
| 3247 | template <class _Tp, class _Allocator> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3248 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3249 | bool |
| 3250 | operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) |
| 3251 | { |
| 3252 | return !(__x < __y); |
| 3253 | } |
| 3254 | |
| 3255 | template <class _Tp, class _Allocator> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3256 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3257 | bool |
| 3258 | operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) |
| 3259 | { |
| 3260 | return !(__y < __x); |
| 3261 | } |
| 3262 | |
| 3263 | template <class _Tp, class _Allocator> |
Howard Hinnant | b8a8ca2 | 2013-10-04 22:09:00 +0000 | [diff] [blame] | 3264 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3265 | void |
| 3266 | swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y) |
Howard Hinnant | 1c93678 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 3267 | _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3268 | { |
| 3269 | __x.swap(__y); |
| 3270 | } |
| 3271 | |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 3272 | #if _LIBCPP_STD_VER > 17 |
| 3273 | template <class _Tp, class _Allocator, class _Up> |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 3274 | inline _LIBCPP_INLINE_VISIBILITY typename vector<_Tp, _Allocator>::size_type |
| 3275 | erase(vector<_Tp, _Allocator>& __c, const _Up& __v) { |
| 3276 | auto __old_size = __c.size(); |
| 3277 | __c.erase(_VSTD::remove(__c.begin(), __c.end(), __v), __c.end()); |
| 3278 | return __old_size - __c.size(); |
| 3279 | } |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 3280 | |
| 3281 | template <class _Tp, class _Allocator, class _Predicate> |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 3282 | inline _LIBCPP_INLINE_VISIBILITY typename vector<_Tp, _Allocator>::size_type |
| 3283 | erase_if(vector<_Tp, _Allocator>& __c, _Predicate __pred) { |
| 3284 | auto __old_size = __c.size(); |
| 3285 | __c.erase(_VSTD::remove_if(__c.begin(), __c.end(), __pred), __c.end()); |
| 3286 | return __old_size - __c.size(); |
| 3287 | } |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 3288 | #endif |
| 3289 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3290 | _LIBCPP_END_NAMESPACE_STD |
| 3291 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 3292 | _LIBCPP_POP_MACROS |
| 3293 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 3294 | #endif // _LIBCPP_VECTOR |