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