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