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