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