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