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