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