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