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