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