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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 163 | explicit vector(const allocator_type& = allocator_type()); |
| 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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 405 | void __move_assign_alloc(const __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 | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 412 | void __move_assign_alloc(const __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) |
| 516 | {} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 517 | _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a) : __base(__a) {} |
| 518 | explicit vector(size_type __n); |
| 519 | vector(size_type __n, const_reference __x); |
| 520 | vector(size_type __n, const_reference __x, const allocator_type& __a); |
| 521 | template <class _InputIterator> |
| 522 | vector(_InputIterator __first, _InputIterator __last, |
| 523 | typename enable_if<__is_input_iterator <_InputIterator>::value && |
| 524 | !__is_forward_iterator<_InputIterator>::value>::type* = 0); |
| 525 | template <class _InputIterator> |
| 526 | vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, |
| 527 | typename enable_if<__is_input_iterator <_InputIterator>::value && |
| 528 | !__is_forward_iterator<_InputIterator>::value>::type* = 0); |
| 529 | template <class _ForwardIterator> |
| 530 | vector(_ForwardIterator __first, _ForwardIterator __last, |
| 531 | typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0); |
| 532 | template <class _ForwardIterator> |
| 533 | vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, |
| 534 | typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0); |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame^] | 535 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 536 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 537 | vector(initializer_list<value_type> __il); |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 538 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 539 | vector(initializer_list<value_type> __il, const allocator_type& __a); |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame^] | 540 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 541 | #ifdef _LIBCPP_DEBUG |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 542 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 543 | ~vector() {__invalidate_all_iterators();} |
| 544 | #endif |
| 545 | |
| 546 | vector(const vector& __x); |
| 547 | vector(const vector& __x, const allocator_type& __a); |
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& operator=(const vector& __x); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 550 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 551 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 552 | vector(vector&& __x) |
| 553 | _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 554 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 555 | vector(vector&& __x, const allocator_type& __a); |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 556 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 557 | vector& operator=(vector&& __x) |
| 558 | _NOEXCEPT_( |
| 559 | __alloc_traits::propagate_on_container_move_assignment::value && |
| 560 | is_nothrow_move_assignable<allocator_type>::value); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 561 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame^] | 562 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 563 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 564 | vector& operator=(initializer_list<value_type> __il) |
| 565 | {assign(__il.begin(), __il.end()); return *this;} |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame^] | 566 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 567 | |
| 568 | template <class _InputIterator> |
| 569 | typename enable_if |
| 570 | < |
| 571 | __is_input_iterator <_InputIterator>::value && |
| 572 | !__is_forward_iterator<_InputIterator>::value, |
| 573 | void |
| 574 | >::type |
| 575 | assign(_InputIterator __first, _InputIterator __last); |
| 576 | template <class _ForwardIterator> |
| 577 | typename enable_if |
| 578 | < |
| 579 | __is_forward_iterator<_ForwardIterator>::value, |
| 580 | void |
| 581 | >::type |
| 582 | assign(_ForwardIterator __first, _ForwardIterator __last); |
| 583 | |
| 584 | void assign(size_type __n, const_reference __u); |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame^] | 585 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 586 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 587 | void assign(initializer_list<value_type> __il) |
| 588 | {assign(__il.begin(), __il.end());} |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame^] | 589 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 590 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 591 | _LIBCPP_INLINE_VISIBILITY |
| 592 | allocator_type get_allocator() const _NOEXCEPT |
| 593 | {return this->__alloc();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 594 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 595 | _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT; |
| 596 | _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT; |
| 597 | _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT; |
| 598 | _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 599 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 600 | _LIBCPP_INLINE_VISIBILITY |
| 601 | reverse_iterator rbegin() _NOEXCEPT |
| 602 | {return reverse_iterator(end());} |
| 603 | _LIBCPP_INLINE_VISIBILITY |
| 604 | const_reverse_iterator rbegin() const _NOEXCEPT |
| 605 | {return const_reverse_iterator(end());} |
| 606 | _LIBCPP_INLINE_VISIBILITY |
| 607 | reverse_iterator rend() _NOEXCEPT |
| 608 | {return reverse_iterator(begin());} |
| 609 | _LIBCPP_INLINE_VISIBILITY |
| 610 | const_reverse_iterator rend() const _NOEXCEPT |
| 611 | {return const_reverse_iterator(begin());} |
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 | const_iterator cbegin() const _NOEXCEPT |
| 615 | {return begin();} |
| 616 | _LIBCPP_INLINE_VISIBILITY |
| 617 | const_iterator cend() const _NOEXCEPT |
| 618 | {return end();} |
| 619 | _LIBCPP_INLINE_VISIBILITY |
| 620 | const_reverse_iterator crbegin() const _NOEXCEPT |
| 621 | {return rbegin();} |
| 622 | _LIBCPP_INLINE_VISIBILITY |
| 623 | const_reverse_iterator crend() const _NOEXCEPT |
| 624 | {return rend();} |
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 | size_type size() const _NOEXCEPT |
| 628 | {return static_cast<size_type>(this->__end_ - this->__begin_);} |
| 629 | _LIBCPP_INLINE_VISIBILITY |
| 630 | size_type capacity() const _NOEXCEPT |
| 631 | {return __base::capacity();} |
| 632 | _LIBCPP_INLINE_VISIBILITY |
| 633 | bool empty() const _NOEXCEPT |
| 634 | {return this->__begin_ == this->__end_;} |
| 635 | size_type max_size() const _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 636 | void reserve(size_type __n); |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 637 | void shrink_to_fit() _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 638 | |
| 639 | _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n); |
| 640 | _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const; |
| 641 | reference at(size_type __n); |
| 642 | const_reference at(size_type __n) const; |
| 643 | |
| 644 | _LIBCPP_INLINE_VISIBILITY reference front() {return *this->__begin_;} |
| 645 | _LIBCPP_INLINE_VISIBILITY const_reference front() const {return *this->__begin_;} |
| 646 | _LIBCPP_INLINE_VISIBILITY reference back() {return *(this->__end_ - 1);} |
| 647 | _LIBCPP_INLINE_VISIBILITY const_reference back() const {return *(this->__end_ - 1);} |
| 648 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 649 | _LIBCPP_INLINE_VISIBILITY |
| 650 | value_type* data() _NOEXCEPT |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 651 | {return _VSTD::__to_raw_pointer(this->__begin_);} |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 652 | _LIBCPP_INLINE_VISIBILITY |
| 653 | const value_type* data() const _NOEXCEPT |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 654 | {return _VSTD::__to_raw_pointer(this->__begin_);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 655 | |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 656 | _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 657 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 658 | void push_back(value_type&& __x); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 659 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 660 | template <class... _Args> |
| 661 | void emplace_back(_Args&&... __args); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 662 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 663 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 664 | void pop_back(); |
| 665 | |
| 666 | iterator insert(const_iterator __position, const_reference __x); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 667 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 668 | iterator insert(const_iterator __position, value_type&& __x); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 669 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 670 | template <class... _Args> |
| 671 | iterator emplace(const_iterator __position, _Args&&... __args); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 672 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 673 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 674 | iterator insert(const_iterator __position, size_type __n, const_reference __x); |
| 675 | template <class _InputIterator> |
| 676 | typename enable_if |
| 677 | < |
| 678 | __is_input_iterator <_InputIterator>::value && |
| 679 | !__is_forward_iterator<_InputIterator>::value, |
| 680 | iterator |
| 681 | >::type |
| 682 | insert(const_iterator __position, _InputIterator __first, _InputIterator __last); |
| 683 | template <class _ForwardIterator> |
| 684 | typename enable_if |
| 685 | < |
| 686 | __is_forward_iterator<_ForwardIterator>::value, |
| 687 | iterator |
| 688 | >::type |
| 689 | insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame^] | 690 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 691 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 692 | iterator insert(const_iterator __position, initializer_list<value_type> __il) |
| 693 | {return insert(__position, __il.begin(), __il.end());} |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame^] | 694 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 695 | |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 696 | _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 697 | iterator erase(const_iterator __first, const_iterator __last); |
| 698 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 699 | _LIBCPP_INLINE_VISIBILITY |
| 700 | void clear() _NOEXCEPT |
| 701 | {__base::clear();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 702 | |
| 703 | void resize(size_type __sz); |
| 704 | void resize(size_type __sz, const_reference __x); |
| 705 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 706 | void swap(vector&) |
| 707 | _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || |
| 708 | __is_nothrow_swappable<allocator_type>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 709 | |
| 710 | bool __invariants() const; |
| 711 | |
| 712 | private: |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 713 | _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 714 | void allocate(size_type __n); |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 715 | void deallocate() _NOEXCEPT; |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 716 | _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const; |
Howard Hinnant | 04240d9 | 2011-01-04 19:53:31 +0000 | [diff] [blame] | 717 | void __construct_at_end(size_type __n); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 718 | void __construct_at_end(size_type __n, const_reference __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 719 | template <class _ForwardIterator> |
| 720 | typename enable_if |
| 721 | < |
| 722 | __is_forward_iterator<_ForwardIterator>::value, |
| 723 | void |
| 724 | >::type |
| 725 | __construct_at_end(_ForwardIterator __first, _ForwardIterator __last); |
| 726 | void __move_construct_at_end(pointer __first, pointer __last); |
| 727 | void __append(size_type __n); |
| 728 | void __append(size_type __n, const_reference __x); |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 729 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 730 | iterator __make_iter(pointer __p) _NOEXCEPT; |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 731 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 732 | const_iterator __make_iter(const_pointer __p) const _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 733 | void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v); |
| 734 | pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p); |
| 735 | void __move_range(pointer __from_s, pointer __from_e, pointer __to); |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 736 | void __move_assign(vector& __c, true_type) |
| 737 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 738 | void __move_assign(vector& __c, false_type); |
| 739 | }; |
| 740 | |
| 741 | template <class _Tp, class _Allocator> |
| 742 | void |
| 743 | vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v) |
| 744 | { |
| 745 | for (pointer __p = this->__end_; this->__begin_ < __p;) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 746 | __v.push_front(_VSTD::move_if_noexcept(*--__p)); |
| 747 | _VSTD::swap(this->__begin_, __v.__begin_); |
| 748 | _VSTD::swap(this->__end_, __v.__end_); |
| 749 | _VSTD::swap(this->__end_cap(), __v.__end_cap()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 750 | __v.__first_ = __v.__begin_; |
| 751 | __invalidate_all_iterators(); |
| 752 | } |
| 753 | |
| 754 | template <class _Tp, class _Allocator> |
| 755 | typename vector<_Tp, _Allocator>::pointer |
| 756 | vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p) |
| 757 | { |
| 758 | pointer __r = __v.__begin_; |
| 759 | for (pointer __i = __p; this->__begin_ < __i;) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 760 | __v.push_front(_VSTD::move_if_noexcept(*--__i)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 761 | for (pointer __i = __p; __i < this->__end_; ++__i) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 762 | __v.push_back(_VSTD::move_if_noexcept(*__i)); |
| 763 | _VSTD::swap(this->__begin_, __v.__begin_); |
| 764 | _VSTD::swap(this->__end_, __v.__end_); |
| 765 | _VSTD::swap(this->__end_cap(), __v.__end_cap()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 766 | __v.__first_ = __v.__begin_; |
| 767 | __invalidate_all_iterators(); |
| 768 | return __r; |
| 769 | } |
| 770 | |
| 771 | // Allocate space for __n objects |
| 772 | // throws length_error if __n > max_size() |
| 773 | // throws (probably bad_alloc) if memory run out |
| 774 | // Precondition: __begin_ == __end_ == __end_cap() == 0 |
| 775 | // Precondition: __n > 0 |
| 776 | // Postcondition: capacity() == __n |
| 777 | // Postcondition: size() == 0 |
| 778 | template <class _Tp, class _Allocator> |
| 779 | void |
| 780 | vector<_Tp, _Allocator>::allocate(size_type __n) |
| 781 | { |
| 782 | if (__n > max_size()) |
| 783 | this->__throw_length_error(); |
| 784 | this->__begin_ = this->__end_ = __alloc_traits::allocate(this->__alloc(), __n); |
| 785 | this->__end_cap() = this->__begin_ + __n; |
| 786 | } |
| 787 | |
| 788 | template <class _Tp, class _Allocator> |
| 789 | void |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 790 | vector<_Tp, _Allocator>::deallocate() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 791 | { |
| 792 | if (this->__begin_ != 0) |
| 793 | { |
| 794 | clear(); |
| 795 | __alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity()); |
| 796 | __invalidate_all_iterators(); |
| 797 | this->__begin_ = this->__end_ = this->__end_cap() = 0; |
| 798 | } |
| 799 | } |
| 800 | |
| 801 | template <class _Tp, class _Allocator> |
| 802 | typename vector<_Tp, _Allocator>::size_type |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 803 | vector<_Tp, _Allocator>::max_size() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 804 | { |
Sean Hunt | 110b8bf | 2011-07-29 23:31:58 +0000 | [diff] [blame] | 805 | 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] | 806 | } |
| 807 | |
| 808 | // Precondition: __new_size > capacity() |
| 809 | template <class _Tp, class _Allocator> |
| 810 | _LIBCPP_INLINE_VISIBILITY inline |
| 811 | typename vector<_Tp, _Allocator>::size_type |
| 812 | vector<_Tp, _Allocator>::__recommend(size_type __new_size) const |
| 813 | { |
| 814 | const size_type __ms = max_size(); |
| 815 | if (__new_size > __ms) |
| 816 | this->__throw_length_error(); |
| 817 | const size_type __cap = capacity(); |
| 818 | if (__cap >= __ms / 2) |
| 819 | return __ms; |
Sean Hunt | 110b8bf | 2011-07-29 23:31:58 +0000 | [diff] [blame] | 820 | return _VSTD::max<size_type>(2*__cap, __new_size); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | // Default constructs __n objects starting at __end_ |
| 824 | // throws if construction throws |
| 825 | // Precondition: __n > 0 |
| 826 | // Precondition: size() + __n <= capacity() |
| 827 | // Postcondition: size() == size() + __n |
| 828 | template <class _Tp, class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 829 | void |
| 830 | vector<_Tp, _Allocator>::__construct_at_end(size_type __n) |
| 831 | { |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 832 | allocator_type& __a = this->__alloc(); |
| 833 | do |
| 834 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 835 | __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 836 | ++this->__end_; |
| 837 | --__n; |
| 838 | } while (__n > 0); |
| 839 | } |
| 840 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 841 | // Copy constructs __n objects starting at __end_ from __x |
| 842 | // throws if construction throws |
| 843 | // Precondition: __n > 0 |
| 844 | // Precondition: size() + __n <= capacity() |
| 845 | // Postcondition: size() == old size() + __n |
| 846 | // Postcondition: [i] == __x for all i in [size() - __n, __n) |
| 847 | template <class _Tp, class _Allocator> |
| 848 | _LIBCPP_INLINE_VISIBILITY inline |
| 849 | void |
| 850 | vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x) |
| 851 | { |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 852 | allocator_type& __a = this->__alloc(); |
| 853 | do |
| 854 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 855 | __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 856 | ++this->__end_; |
| 857 | --__n; |
| 858 | } while (__n > 0); |
| 859 | } |
| 860 | |
| 861 | template <class _Tp, class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 862 | template <class _ForwardIterator> |
| 863 | typename enable_if |
| 864 | < |
| 865 | __is_forward_iterator<_ForwardIterator>::value, |
| 866 | void |
| 867 | >::type |
| 868 | vector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last) |
| 869 | { |
| 870 | allocator_type& __a = this->__alloc(); |
| 871 | for (; __first != __last; ++__first) |
| 872 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 873 | __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), *__first); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 874 | ++this->__end_; |
| 875 | } |
| 876 | } |
| 877 | |
| 878 | template <class _Tp, class _Allocator> |
| 879 | void |
| 880 | vector<_Tp, _Allocator>::__move_construct_at_end(pointer __first, pointer __last) |
| 881 | { |
| 882 | allocator_type& __a = this->__alloc(); |
| 883 | for (; __first != __last; ++__first) |
| 884 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 885 | __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), |
| 886 | _VSTD::move(*__first)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 887 | ++this->__end_; |
| 888 | } |
| 889 | } |
| 890 | |
| 891 | // Default constructs __n objects starting at __end_ |
| 892 | // throws if construction throws |
| 893 | // Postcondition: size() == size() + __n |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 894 | // Exception safety: strong. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 895 | template <class _Tp, class _Allocator> |
| 896 | void |
| 897 | vector<_Tp, _Allocator>::__append(size_type __n) |
| 898 | { |
| 899 | if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n) |
| 900 | this->__construct_at_end(__n); |
| 901 | else |
| 902 | { |
| 903 | allocator_type& __a = this->__alloc(); |
| 904 | __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a); |
| 905 | __v.__construct_at_end(__n); |
| 906 | __swap_out_circular_buffer(__v); |
| 907 | } |
| 908 | } |
| 909 | |
| 910 | // Default constructs __n objects starting at __end_ |
| 911 | // throws if construction throws |
| 912 | // Postcondition: size() == size() + __n |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 913 | // Exception safety: strong. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 914 | template <class _Tp, class _Allocator> |
| 915 | void |
| 916 | vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x) |
| 917 | { |
| 918 | if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n) |
| 919 | this->__construct_at_end(__n, __x); |
| 920 | else |
| 921 | { |
| 922 | allocator_type& __a = this->__alloc(); |
| 923 | __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a); |
| 924 | __v.__construct_at_end(__n, __x); |
| 925 | __swap_out_circular_buffer(__v); |
| 926 | } |
| 927 | } |
| 928 | |
| 929 | template <class _Tp, class _Allocator> |
| 930 | vector<_Tp, _Allocator>::vector(size_type __n) |
| 931 | { |
| 932 | if (__n > 0) |
| 933 | { |
| 934 | allocate(__n); |
| 935 | __construct_at_end(__n); |
| 936 | } |
| 937 | } |
| 938 | |
| 939 | template <class _Tp, class _Allocator> |
| 940 | vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x) |
| 941 | { |
| 942 | if (__n > 0) |
| 943 | { |
| 944 | allocate(__n); |
| 945 | __construct_at_end(__n, __x); |
| 946 | } |
| 947 | } |
| 948 | |
| 949 | template <class _Tp, class _Allocator> |
| 950 | vector<_Tp, _Allocator>::vector(size_type __n, const_reference __x, const allocator_type& __a) |
| 951 | : __base(__a) |
| 952 | { |
| 953 | if (__n > 0) |
| 954 | { |
| 955 | allocate(__n); |
| 956 | __construct_at_end(__n, __x); |
| 957 | } |
| 958 | } |
| 959 | |
| 960 | template <class _Tp, class _Allocator> |
| 961 | template <class _InputIterator> |
| 962 | vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, |
| 963 | typename enable_if<__is_input_iterator <_InputIterator>::value && |
| 964 | !__is_forward_iterator<_InputIterator>::value>::type*) |
| 965 | { |
| 966 | for (; __first != __last; ++__first) |
| 967 | push_back(*__first); |
| 968 | } |
| 969 | |
| 970 | template <class _Tp, class _Allocator> |
| 971 | template <class _InputIterator> |
| 972 | vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, |
| 973 | typename enable_if<__is_input_iterator <_InputIterator>::value && |
| 974 | !__is_forward_iterator<_InputIterator>::value>::type*) |
| 975 | : __base(__a) |
| 976 | { |
| 977 | for (; __first != __last; ++__first) |
| 978 | push_back(*__first); |
| 979 | } |
| 980 | |
| 981 | template <class _Tp, class _Allocator> |
| 982 | template <class _ForwardIterator> |
| 983 | vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, |
| 984 | typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*) |
| 985 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 986 | size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 987 | if (__n > 0) |
| 988 | { |
| 989 | allocate(__n); |
| 990 | __construct_at_end(__first, __last); |
| 991 | } |
| 992 | } |
| 993 | |
| 994 | template <class _Tp, class _Allocator> |
| 995 | template <class _ForwardIterator> |
| 996 | vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, |
| 997 | typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*) |
| 998 | : __base(__a) |
| 999 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1000 | size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1001 | if (__n > 0) |
| 1002 | { |
| 1003 | allocate(__n); |
| 1004 | __construct_at_end(__first, __last); |
| 1005 | } |
| 1006 | } |
| 1007 | |
| 1008 | template <class _Tp, class _Allocator> |
| 1009 | vector<_Tp, _Allocator>::vector(const vector& __x) |
| 1010 | : __base(__alloc_traits::select_on_container_copy_construction(__x.__alloc())) |
| 1011 | { |
| 1012 | size_type __n = __x.size(); |
| 1013 | if (__n > 0) |
| 1014 | { |
| 1015 | allocate(__n); |
| 1016 | __construct_at_end(__x.__begin_, __x.__end_); |
| 1017 | } |
| 1018 | } |
| 1019 | |
| 1020 | template <class _Tp, class _Allocator> |
| 1021 | vector<_Tp, _Allocator>::vector(const vector& __x, const allocator_type& __a) |
| 1022 | : __base(__a) |
| 1023 | { |
| 1024 | size_type __n = __x.size(); |
| 1025 | if (__n > 0) |
| 1026 | { |
| 1027 | allocate(__n); |
| 1028 | __construct_at_end(__x.__begin_, __x.__end_); |
| 1029 | } |
| 1030 | } |
| 1031 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1032 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1033 | |
| 1034 | template <class _Tp, class _Allocator> |
| 1035 | _LIBCPP_INLINE_VISIBILITY inline |
| 1036 | vector<_Tp, _Allocator>::vector(vector&& __x) |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1037 | _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1038 | : __base(_VSTD::move(__x.__alloc())) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1039 | { |
| 1040 | this->__begin_ = __x.__begin_; |
| 1041 | this->__end_ = __x.__end_; |
| 1042 | this->__end_cap() = __x.__end_cap(); |
| 1043 | __x.__begin_ = __x.__end_ = __x.__end_cap() = 0; |
| 1044 | __x.__invalidate_all_iterators(); |
| 1045 | } |
| 1046 | |
| 1047 | template <class _Tp, class _Allocator> |
| 1048 | _LIBCPP_INLINE_VISIBILITY inline |
| 1049 | vector<_Tp, _Allocator>::vector(vector&& __x, const allocator_type& __a) |
| 1050 | : __base(__a) |
| 1051 | { |
| 1052 | if (__a == __x.__alloc()) |
| 1053 | { |
| 1054 | this->__begin_ = __x.__begin_; |
| 1055 | this->__end_ = __x.__end_; |
| 1056 | this->__end_cap() = __x.__end_cap(); |
| 1057 | __x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr; |
| 1058 | __x.__invalidate_all_iterators(); |
| 1059 | } |
| 1060 | else |
| 1061 | { |
| 1062 | typedef move_iterator<iterator> _I; |
| 1063 | assign(_I(__x.begin()), _I(__x.end())); |
| 1064 | } |
| 1065 | } |
| 1066 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame^] | 1067 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 1068 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1069 | template <class _Tp, class _Allocator> |
| 1070 | _LIBCPP_INLINE_VISIBILITY inline |
| 1071 | vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il) |
| 1072 | { |
| 1073 | if (__il.size() > 0) |
| 1074 | { |
| 1075 | allocate(__il.size()); |
| 1076 | __construct_at_end(__il.begin(), __il.end()); |
| 1077 | } |
| 1078 | } |
| 1079 | |
| 1080 | template <class _Tp, class _Allocator> |
| 1081 | _LIBCPP_INLINE_VISIBILITY inline |
| 1082 | vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a) |
| 1083 | : __base(__a) |
| 1084 | { |
| 1085 | if (__il.size() > 0) |
| 1086 | { |
| 1087 | allocate(__il.size()); |
| 1088 | __construct_at_end(__il.begin(), __il.end()); |
| 1089 | } |
| 1090 | } |
| 1091 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame^] | 1092 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 1093 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1094 | template <class _Tp, class _Allocator> |
| 1095 | _LIBCPP_INLINE_VISIBILITY inline |
| 1096 | vector<_Tp, _Allocator>& |
| 1097 | vector<_Tp, _Allocator>::operator=(vector&& __x) |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1098 | _NOEXCEPT_( |
| 1099 | __alloc_traits::propagate_on_container_move_assignment::value && |
| 1100 | is_nothrow_move_assignable<allocator_type>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1101 | { |
| 1102 | __move_assign(__x, integral_constant<bool, |
| 1103 | __alloc_traits::propagate_on_container_move_assignment::value>()); |
| 1104 | return *this; |
| 1105 | } |
| 1106 | |
| 1107 | template <class _Tp, class _Allocator> |
| 1108 | void |
| 1109 | vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type) |
| 1110 | { |
| 1111 | if (__base::__alloc() != __c.__alloc()) |
| 1112 | { |
| 1113 | typedef move_iterator<iterator> _I; |
| 1114 | assign(_I(__c.begin()), _I(__c.end())); |
| 1115 | } |
| 1116 | else |
| 1117 | __move_assign(__c, true_type()); |
| 1118 | } |
| 1119 | |
| 1120 | template <class _Tp, class _Allocator> |
| 1121 | void |
| 1122 | vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type) |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1123 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1124 | { |
| 1125 | deallocate(); |
| 1126 | this->__begin_ = __c.__begin_; |
| 1127 | this->__end_ = __c.__end_; |
| 1128 | this->__end_cap() = __c.__end_cap(); |
| 1129 | __base::__move_assign_alloc(__c); |
| 1130 | __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr; |
| 1131 | } |
| 1132 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1133 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1134 | |
| 1135 | template <class _Tp, class _Allocator> |
| 1136 | _LIBCPP_INLINE_VISIBILITY inline |
| 1137 | vector<_Tp, _Allocator>& |
| 1138 | vector<_Tp, _Allocator>::operator=(const vector& __x) |
| 1139 | { |
| 1140 | if (this != &__x) |
| 1141 | { |
| 1142 | __base::__copy_assign_alloc(__x); |
| 1143 | assign(__x.__begin_, __x.__end_); |
| 1144 | } |
| 1145 | return *this; |
| 1146 | } |
| 1147 | |
| 1148 | template <class _Tp, class _Allocator> |
| 1149 | template <class _InputIterator> |
| 1150 | typename enable_if |
| 1151 | < |
| 1152 | __is_input_iterator <_InputIterator>::value && |
| 1153 | !__is_forward_iterator<_InputIterator>::value, |
| 1154 | void |
| 1155 | >::type |
| 1156 | vector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last) |
| 1157 | { |
| 1158 | clear(); |
| 1159 | for (; __first != __last; ++__first) |
| 1160 | push_back(*__first); |
| 1161 | } |
| 1162 | |
| 1163 | template <class _Tp, class _Allocator> |
| 1164 | template <class _ForwardIterator> |
| 1165 | typename enable_if |
| 1166 | < |
| 1167 | __is_forward_iterator<_ForwardIterator>::value, |
| 1168 | void |
| 1169 | >::type |
| 1170 | vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) |
| 1171 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1172 | typename iterator_traits<_ForwardIterator>::difference_type __new_size = _VSTD::distance(__first, __last); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1173 | if (static_cast<size_type>(__new_size) <= capacity()) |
| 1174 | { |
| 1175 | _ForwardIterator __mid = __last; |
| 1176 | bool __growing = false; |
| 1177 | if (static_cast<size_type>(__new_size) > size()) |
| 1178 | { |
| 1179 | __growing = true; |
| 1180 | __mid = __first; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1181 | _VSTD::advance(__mid, size()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1182 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1183 | pointer __m = _VSTD::copy(__first, __mid, this->__begin_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1184 | if (__growing) |
| 1185 | __construct_at_end(__mid, __last); |
| 1186 | else |
| 1187 | this->__destruct_at_end(__m); |
| 1188 | } |
| 1189 | else |
| 1190 | { |
| 1191 | deallocate(); |
| 1192 | allocate(__recommend(static_cast<size_type>(__new_size))); |
| 1193 | __construct_at_end(__first, __last); |
| 1194 | } |
| 1195 | } |
| 1196 | |
| 1197 | template <class _Tp, class _Allocator> |
| 1198 | void |
| 1199 | vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u) |
| 1200 | { |
| 1201 | if (__n <= capacity()) |
| 1202 | { |
| 1203 | size_type __s = size(); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1204 | _VSTD::fill_n(this->__begin_, _VSTD::min(__n, __s), __u); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1205 | if (__n > __s) |
| 1206 | __construct_at_end(__n - __s, __u); |
| 1207 | else |
Howard Hinnant | adff489 | 2010-05-24 17:49:41 +0000 | [diff] [blame] | 1208 | this->__destruct_at_end(this->__begin_ + __n); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1209 | } |
| 1210 | else |
| 1211 | { |
| 1212 | deallocate(); |
| 1213 | allocate(__recommend(static_cast<size_type>(__n))); |
| 1214 | __construct_at_end(__n, __u); |
| 1215 | } |
| 1216 | } |
| 1217 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1218 | template <class _Tp, class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1219 | _LIBCPP_INLINE_VISIBILITY inline |
| 1220 | typename vector<_Tp, _Allocator>::iterator |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1221 | vector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1222 | { |
| 1223 | #ifdef _LIBCPP_DEBUG |
| 1224 | return iterator(this, __p); |
| 1225 | #else |
| 1226 | return iterator(__p); |
| 1227 | #endif |
| 1228 | } |
| 1229 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1230 | template <class _Tp, class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1231 | _LIBCPP_INLINE_VISIBILITY inline |
| 1232 | typename vector<_Tp, _Allocator>::const_iterator |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1233 | vector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1234 | { |
| 1235 | #ifdef _LIBCPP_DEBUG |
| 1236 | return const_iterator(this, __p); |
| 1237 | #else |
| 1238 | return const_iterator(__p); |
| 1239 | #endif |
| 1240 | } |
| 1241 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1242 | template <class _Tp, class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1243 | _LIBCPP_INLINE_VISIBILITY inline |
| 1244 | typename vector<_Tp, _Allocator>::iterator |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1245 | vector<_Tp, _Allocator>::begin() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1246 | { |
| 1247 | return __make_iter(this->__begin_); |
| 1248 | } |
| 1249 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1250 | template <class _Tp, class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1251 | _LIBCPP_INLINE_VISIBILITY inline |
| 1252 | typename vector<_Tp, _Allocator>::const_iterator |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1253 | vector<_Tp, _Allocator>::begin() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1254 | { |
| 1255 | return __make_iter(this->__begin_); |
| 1256 | } |
| 1257 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1258 | template <class _Tp, class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1259 | _LIBCPP_INLINE_VISIBILITY inline |
| 1260 | typename vector<_Tp, _Allocator>::iterator |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1261 | vector<_Tp, _Allocator>::end() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1262 | { |
| 1263 | return __make_iter(this->__end_); |
| 1264 | } |
| 1265 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1266 | template <class _Tp, class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1267 | _LIBCPP_INLINE_VISIBILITY inline |
| 1268 | typename vector<_Tp, _Allocator>::const_iterator |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1269 | vector<_Tp, _Allocator>::end() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1270 | { |
| 1271 | return __make_iter(this->__end_); |
| 1272 | } |
| 1273 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1274 | template <class _Tp, class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1275 | _LIBCPP_INLINE_VISIBILITY inline |
| 1276 | typename vector<_Tp, _Allocator>::reference |
| 1277 | vector<_Tp, _Allocator>::operator[](size_type __n) |
| 1278 | { |
| 1279 | #ifdef _LIBCPP_DEBUG |
| 1280 | assert(__n < size()); |
| 1281 | #endif |
| 1282 | return this->__begin_[__n]; |
| 1283 | } |
| 1284 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1285 | template <class _Tp, class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1286 | _LIBCPP_INLINE_VISIBILITY inline |
| 1287 | typename vector<_Tp, _Allocator>::const_reference |
| 1288 | vector<_Tp, _Allocator>::operator[](size_type __n) const |
| 1289 | { |
| 1290 | #ifdef _LIBCPP_DEBUG |
| 1291 | assert(__n < size()); |
| 1292 | #endif |
| 1293 | return this->__begin_[__n]; |
| 1294 | } |
| 1295 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1296 | template <class _Tp, class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1297 | typename vector<_Tp, _Allocator>::reference |
| 1298 | vector<_Tp, _Allocator>::at(size_type __n) |
| 1299 | { |
| 1300 | if (__n >= size()) |
| 1301 | this->__throw_out_of_range(); |
| 1302 | return this->__begin_[__n]; |
| 1303 | } |
| 1304 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1305 | template <class _Tp, class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1306 | typename vector<_Tp, _Allocator>::const_reference |
| 1307 | vector<_Tp, _Allocator>::at(size_type __n) const |
| 1308 | { |
| 1309 | if (__n >= size()) |
| 1310 | this->__throw_out_of_range(); |
| 1311 | return this->__begin_[__n]; |
| 1312 | } |
| 1313 | |
| 1314 | template <class _Tp, class _Allocator> |
| 1315 | void |
| 1316 | vector<_Tp, _Allocator>::reserve(size_type __n) |
| 1317 | { |
| 1318 | if (__n > capacity()) |
| 1319 | { |
| 1320 | allocator_type& __a = this->__alloc(); |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1321 | __split_buffer<value_type, allocator_type&> __v(__n, size(), __a); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1322 | __swap_out_circular_buffer(__v); |
| 1323 | } |
| 1324 | } |
| 1325 | |
| 1326 | template <class _Tp, class _Allocator> |
| 1327 | void |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1328 | vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1329 | { |
| 1330 | if (capacity() > size()) |
| 1331 | { |
| 1332 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1333 | try |
| 1334 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1335 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1336 | allocator_type& __a = this->__alloc(); |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1337 | __split_buffer<value_type, allocator_type&> __v(size(), size(), __a); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1338 | __swap_out_circular_buffer(__v); |
| 1339 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1340 | } |
| 1341 | catch (...) |
| 1342 | { |
| 1343 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1344 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1345 | } |
| 1346 | } |
| 1347 | |
| 1348 | template <class _Tp, class _Allocator> |
| 1349 | void |
| 1350 | vector<_Tp, _Allocator>::push_back(const_reference __x) |
| 1351 | { |
| 1352 | if (this->__end_ < this->__end_cap()) |
| 1353 | { |
| 1354 | __alloc_traits::construct(this->__alloc(), |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1355 | _VSTD::__to_raw_pointer(this->__end_), __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1356 | ++this->__end_; |
| 1357 | } |
| 1358 | else |
| 1359 | { |
| 1360 | allocator_type& __a = this->__alloc(); |
| 1361 | __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a); |
| 1362 | __v.push_back(__x); |
| 1363 | __swap_out_circular_buffer(__v); |
| 1364 | } |
| 1365 | } |
| 1366 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1367 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1368 | |
| 1369 | template <class _Tp, class _Allocator> |
| 1370 | void |
| 1371 | vector<_Tp, _Allocator>::push_back(value_type&& __x) |
| 1372 | { |
| 1373 | if (this->__end_ < this->__end_cap()) |
| 1374 | { |
| 1375 | __alloc_traits::construct(this->__alloc(), |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1376 | _VSTD::__to_raw_pointer(this->__end_), |
| 1377 | _VSTD::move(__x)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1378 | ++this->__end_; |
| 1379 | } |
| 1380 | else |
| 1381 | { |
| 1382 | allocator_type& __a = this->__alloc(); |
| 1383 | __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1384 | __v.push_back(_VSTD::move(__x)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1385 | __swap_out_circular_buffer(__v); |
| 1386 | } |
| 1387 | } |
| 1388 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1389 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 1390 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1391 | template <class _Tp, class _Allocator> |
| 1392 | template <class... _Args> |
| 1393 | void |
| 1394 | vector<_Tp, _Allocator>::emplace_back(_Args&&... __args) |
| 1395 | { |
| 1396 | if (this->__end_ < this->__end_cap()) |
| 1397 | { |
| 1398 | __alloc_traits::construct(this->__alloc(), |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1399 | _VSTD::__to_raw_pointer(this->__end_), |
| 1400 | _VSTD::forward<_Args>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1401 | ++this->__end_; |
| 1402 | } |
| 1403 | else |
| 1404 | { |
| 1405 | allocator_type& __a = this->__alloc(); |
| 1406 | __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1407 | __v.emplace_back(_VSTD::forward<_Args>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1408 | __swap_out_circular_buffer(__v); |
| 1409 | } |
| 1410 | } |
| 1411 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1412 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 1413 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1414 | |
| 1415 | template <class _Tp, class _Allocator> |
| 1416 | _LIBCPP_INLINE_VISIBILITY inline |
| 1417 | void |
| 1418 | vector<_Tp, _Allocator>::pop_back() |
| 1419 | { |
| 1420 | this->__destruct_at_end(this->__end_ - 1); |
| 1421 | } |
| 1422 | |
| 1423 | template <class _Tp, class _Allocator> |
| 1424 | _LIBCPP_INLINE_VISIBILITY inline |
| 1425 | typename vector<_Tp, _Allocator>::iterator |
| 1426 | vector<_Tp, _Allocator>::erase(const_iterator __position) |
| 1427 | { |
| 1428 | pointer __p = const_cast<pointer>(&*__position); |
| 1429 | iterator __r = __make_iter(__p); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1430 | this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1431 | return __r; |
| 1432 | } |
| 1433 | |
| 1434 | template <class _Tp, class _Allocator> |
| 1435 | typename vector<_Tp, _Allocator>::iterator |
| 1436 | vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last) |
| 1437 | { |
| 1438 | pointer __p = this->__begin_ + (__first - begin()); |
| 1439 | iterator __r = __make_iter(__p); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1440 | this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1441 | return __r; |
| 1442 | } |
| 1443 | |
| 1444 | template <class _Tp, class _Allocator> |
| 1445 | void |
| 1446 | vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to) |
| 1447 | { |
| 1448 | pointer __old_last = this->__end_; |
| 1449 | difference_type __n = __old_last - __to; |
| 1450 | for (pointer __i = __from_s + __n; __i < __from_e; ++__i, ++this->__end_) |
| 1451 | __alloc_traits::construct(this->__alloc(), |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1452 | _VSTD::__to_raw_pointer(this->__end_), |
| 1453 | _VSTD::move(*__i)); |
| 1454 | _VSTD::move_backward(__from_s, __from_s + __n, __old_last); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1455 | } |
| 1456 | |
| 1457 | template <class _Tp, class _Allocator> |
| 1458 | typename vector<_Tp, _Allocator>::iterator |
| 1459 | vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x) |
| 1460 | { |
| 1461 | pointer __p = this->__begin_ + (__position - begin()); |
| 1462 | if (this->__end_ < this->__end_cap()) |
| 1463 | { |
| 1464 | if (__p == this->__end_) |
| 1465 | { |
| 1466 | __alloc_traits::construct(this->__alloc(), |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1467 | _VSTD::__to_raw_pointer(this->__end_), __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1468 | ++this->__end_; |
| 1469 | } |
| 1470 | else |
| 1471 | { |
| 1472 | __move_range(__p, this->__end_, __p + 1); |
| 1473 | const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x); |
| 1474 | if (__p <= __xr && __xr < this->__end_) |
| 1475 | ++__xr; |
| 1476 | *__p = *__xr; |
| 1477 | } |
| 1478 | } |
| 1479 | else |
| 1480 | { |
| 1481 | allocator_type& __a = this->__alloc(); |
| 1482 | __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a); |
| 1483 | __v.push_back(__x); |
| 1484 | __p = __swap_out_circular_buffer(__v, __p); |
| 1485 | } |
| 1486 | return __make_iter(__p); |
| 1487 | } |
| 1488 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1489 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1490 | |
| 1491 | template <class _Tp, class _Allocator> |
| 1492 | typename vector<_Tp, _Allocator>::iterator |
| 1493 | vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x) |
| 1494 | { |
| 1495 | pointer __p = this->__begin_ + (__position - begin()); |
| 1496 | if (this->__end_ < this->__end_cap()) |
| 1497 | { |
| 1498 | if (__p == this->__end_) |
| 1499 | { |
| 1500 | __alloc_traits::construct(this->__alloc(), |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1501 | _VSTD::__to_raw_pointer(this->__end_), |
| 1502 | _VSTD::move(__x)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1503 | ++this->__end_; |
| 1504 | } |
| 1505 | else |
| 1506 | { |
| 1507 | __move_range(__p, this->__end_, __p + 1); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1508 | *__p = _VSTD::move(__x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1509 | } |
| 1510 | } |
| 1511 | else |
| 1512 | { |
| 1513 | allocator_type& __a = this->__alloc(); |
| 1514 | __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] | 1515 | __v.push_back(_VSTD::move(__x)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1516 | __p = __swap_out_circular_buffer(__v, __p); |
| 1517 | } |
| 1518 | return __make_iter(__p); |
| 1519 | } |
| 1520 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1521 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 1522 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1523 | template <class _Tp, class _Allocator> |
| 1524 | template <class... _Args> |
| 1525 | typename vector<_Tp, _Allocator>::iterator |
| 1526 | vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args) |
| 1527 | { |
| 1528 | pointer __p = this->__begin_ + (__position - begin()); |
| 1529 | if (this->__end_ < this->__end_cap()) |
| 1530 | { |
| 1531 | if (__p == this->__end_) |
| 1532 | { |
| 1533 | __alloc_traits::construct(this->__alloc(), |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1534 | _VSTD::__to_raw_pointer(this->__end_), |
| 1535 | _VSTD::forward<_Args>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1536 | ++this->__end_; |
| 1537 | } |
| 1538 | else |
| 1539 | { |
| 1540 | __move_range(__p, this->__end_, __p + 1); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1541 | *__p = value_type(_VSTD::forward<_Args>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1542 | } |
| 1543 | } |
| 1544 | else |
| 1545 | { |
| 1546 | allocator_type& __a = this->__alloc(); |
| 1547 | __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] | 1548 | __v.emplace_back(_VSTD::forward<_Args>(__args)...); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1549 | __p = __swap_out_circular_buffer(__v, __p); |
| 1550 | } |
| 1551 | return __make_iter(__p); |
| 1552 | } |
| 1553 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1554 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 1555 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1556 | |
| 1557 | template <class _Tp, class _Allocator> |
| 1558 | typename vector<_Tp, _Allocator>::iterator |
| 1559 | vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x) |
| 1560 | { |
| 1561 | pointer __p = this->__begin_ + (__position - begin()); |
| 1562 | if (__n > 0) |
| 1563 | { |
| 1564 | if (__n <= static_cast<size_type>(this->__end_cap() - this->__end_)) |
| 1565 | { |
| 1566 | size_type __old_n = __n; |
| 1567 | pointer __old_last = this->__end_; |
| 1568 | if (__n > static_cast<size_type>(this->__end_ - __p)) |
| 1569 | { |
| 1570 | size_type __cx = __n - (this->__end_ - __p); |
| 1571 | __construct_at_end(__cx, __x); |
| 1572 | __n -= __cx; |
| 1573 | } |
| 1574 | if (__n > 0) |
| 1575 | { |
| 1576 | __move_range(__p, __old_last, __p + __old_n); |
| 1577 | const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x); |
| 1578 | if (__p <= __xr && __xr < this->__end_) |
| 1579 | __xr += __old_n; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1580 | _VSTD::fill_n(__p, __n, *__xr); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1581 | } |
| 1582 | } |
| 1583 | else |
| 1584 | { |
| 1585 | allocator_type& __a = this->__alloc(); |
| 1586 | __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a); |
| 1587 | __v.__construct_at_end(__n, __x); |
| 1588 | __p = __swap_out_circular_buffer(__v, __p); |
| 1589 | } |
| 1590 | } |
| 1591 | return __make_iter(__p); |
| 1592 | } |
| 1593 | |
| 1594 | template <class _Tp, class _Allocator> |
| 1595 | template <class _InputIterator> |
| 1596 | typename enable_if |
| 1597 | < |
| 1598 | __is_input_iterator <_InputIterator>::value && |
| 1599 | !__is_forward_iterator<_InputIterator>::value, |
| 1600 | typename vector<_Tp, _Allocator>::iterator |
| 1601 | >::type |
| 1602 | vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last) |
| 1603 | { |
| 1604 | difference_type __off = __position - begin(); |
| 1605 | pointer __p = this->__begin_ + __off; |
| 1606 | allocator_type& __a = this->__alloc(); |
| 1607 | pointer __old_last = this->__end_; |
| 1608 | for (; this->__end_ != this->__end_cap() && __first != __last; ++__first) |
| 1609 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1610 | __alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1611 | *__first); |
| 1612 | ++this->__end_; |
| 1613 | } |
| 1614 | __split_buffer<value_type, allocator_type&> __v(__a); |
| 1615 | if (__first != __last) |
| 1616 | { |
| 1617 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1618 | try |
| 1619 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1620 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1621 | __v.__construct_at_end(__first, __last); |
| 1622 | difference_type __old_size = __old_last - this->__begin_; |
| 1623 | difference_type __old_p = __p - this->__begin_; |
| 1624 | reserve(__recommend(size() + __v.size())); |
| 1625 | __p = this->__begin_ + __old_p; |
| 1626 | __old_last = this->__begin_ + __old_size; |
| 1627 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1628 | } |
| 1629 | catch (...) |
| 1630 | { |
| 1631 | erase(__make_iter(__old_last), end()); |
| 1632 | throw; |
| 1633 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1634 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1635 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1636 | __p = _VSTD::rotate(__p, __old_last, this->__end_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1637 | insert(__make_iter(__p), move_iterator<iterator>(__v.begin()), |
| 1638 | move_iterator<iterator>(__v.end())); |
| 1639 | return begin() + __off; |
| 1640 | } |
| 1641 | |
| 1642 | template <class _Tp, class _Allocator> |
| 1643 | template <class _ForwardIterator> |
| 1644 | typename enable_if |
| 1645 | < |
| 1646 | __is_forward_iterator<_ForwardIterator>::value, |
| 1647 | typename vector<_Tp, _Allocator>::iterator |
| 1648 | >::type |
| 1649 | vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) |
| 1650 | { |
| 1651 | pointer __p = this->__begin_ + (__position - begin()); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1652 | difference_type __n = _VSTD::distance(__first, __last); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1653 | if (__n > 0) |
| 1654 | { |
| 1655 | if (__n <= this->__end_cap() - this->__end_) |
| 1656 | { |
| 1657 | size_type __old_n = __n; |
| 1658 | pointer __old_last = this->__end_; |
| 1659 | _ForwardIterator __m = __last; |
| 1660 | difference_type __dx = this->__end_ - __p; |
| 1661 | if (__n > __dx) |
| 1662 | { |
| 1663 | __m = __first; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1664 | _VSTD::advance(__m, this->__end_ - __p); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1665 | __construct_at_end(__m, __last); |
| 1666 | __n = __dx; |
| 1667 | } |
| 1668 | if (__n > 0) |
| 1669 | { |
| 1670 | __move_range(__p, __old_last, __p + __old_n); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1671 | _VSTD::copy(__first, __m, __p); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1672 | } |
| 1673 | } |
| 1674 | else |
| 1675 | { |
| 1676 | allocator_type& __a = this->__alloc(); |
| 1677 | __split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a); |
| 1678 | __v.__construct_at_end(__first, __last); |
| 1679 | __p = __swap_out_circular_buffer(__v, __p); |
| 1680 | } |
| 1681 | } |
| 1682 | return __make_iter(__p); |
| 1683 | } |
| 1684 | |
| 1685 | template <class _Tp, class _Allocator> |
| 1686 | void |
| 1687 | vector<_Tp, _Allocator>::resize(size_type __sz) |
| 1688 | { |
| 1689 | size_type __cs = size(); |
| 1690 | if (__cs < __sz) |
| 1691 | this->__append(__sz - __cs); |
| 1692 | else if (__cs > __sz) |
| 1693 | this->__destruct_at_end(this->__begin_ + __sz); |
| 1694 | } |
| 1695 | |
| 1696 | template <class _Tp, class _Allocator> |
| 1697 | void |
| 1698 | vector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x) |
| 1699 | { |
| 1700 | size_type __cs = size(); |
| 1701 | if (__cs < __sz) |
| 1702 | this->__append(__sz - __cs, __x); |
| 1703 | else if (__cs > __sz) |
| 1704 | this->__destruct_at_end(this->__begin_ + __sz); |
| 1705 | } |
| 1706 | |
| 1707 | template <class _Tp, class _Allocator> |
| 1708 | void |
| 1709 | vector<_Tp, _Allocator>::swap(vector& __x) |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1710 | _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || |
| 1711 | __is_nothrow_swappable<allocator_type>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1712 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1713 | _VSTD::swap(this->__begin_, __x.__begin_); |
| 1714 | _VSTD::swap(this->__end_, __x.__end_); |
| 1715 | _VSTD::swap(this->__end_cap(), __x.__end_cap()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1716 | __base::__swap_alloc(this->__alloc(), __x.__alloc()); |
| 1717 | #ifdef _LIBCPP_DEBUG |
| 1718 | iterator::swap(this, &__x); |
| 1719 | const_iterator::swap(this, &__x); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1720 | #endif // _LIBCPP_DEBUG |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1721 | } |
| 1722 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1723 | template <class _Tp, class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1724 | bool |
| 1725 | vector<_Tp, _Allocator>::__invariants() const |
| 1726 | { |
| 1727 | if (this->__begin_ == 0) |
| 1728 | { |
| 1729 | if (this->__end_ != 0 || this->__end_cap() != 0) |
| 1730 | return false; |
| 1731 | } |
| 1732 | else |
| 1733 | { |
| 1734 | if (this->__begin_ > this->__end_) |
| 1735 | return false; |
| 1736 | if (this->__begin_ == this->__end_cap()) |
| 1737 | return false; |
| 1738 | if (this->__end_ > this->__end_cap()) |
| 1739 | return false; |
| 1740 | } |
| 1741 | return true; |
| 1742 | } |
| 1743 | |
| 1744 | template <class _Tp, class _Allocator> |
| 1745 | #ifndef _LIBCPP_DEBUG |
| 1746 | _LIBCPP_INLINE_VISIBILITY inline |
| 1747 | #endif |
| 1748 | void |
| 1749 | vector<_Tp, _Allocator>::__invalidate_all_iterators() |
| 1750 | { |
| 1751 | #ifdef _LIBCPP_DEBUG |
| 1752 | iterator::__remove_all(this); |
| 1753 | const_iterator::__remove_all(this); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1754 | #endif // _LIBCPP_DEBUG |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1755 | } |
| 1756 | |
| 1757 | // vector<bool> |
| 1758 | |
| 1759 | template <class _Allocator> class vector<bool, _Allocator>; |
| 1760 | |
| 1761 | template <class _Allocator> struct hash<vector<bool, _Allocator> >; |
| 1762 | |
| 1763 | template <class _Allocator> |
Howard Hinnant | f03c3b4 | 2011-07-02 20:33:23 +0000 | [diff] [blame] | 1764 | struct __has_storage_type<vector<bool, _Allocator> > |
| 1765 | { |
| 1766 | static const bool value = true; |
| 1767 | }; |
| 1768 | |
| 1769 | template <class _Allocator> |
Howard Hinnant | 36cdf02 | 2010-09-10 16:42:26 +0000 | [diff] [blame] | 1770 | class _LIBCPP_VISIBLE vector<bool, _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1771 | : private __vector_base_common<true> |
| 1772 | { |
| 1773 | public: |
| 1774 | typedef vector __self; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1775 | typedef bool value_type; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1776 | typedef _Allocator allocator_type; |
| 1777 | typedef allocator_traits<allocator_type> __alloc_traits; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1778 | typedef typename __alloc_traits::size_type size_type; |
| 1779 | typedef typename __alloc_traits::difference_type difference_type; |
| 1780 | typedef __bit_iterator<vector, false> pointer; |
| 1781 | typedef __bit_iterator<vector, true> const_pointer; |
| 1782 | #ifdef _LIBCPP_DEBUG |
| 1783 | typedef __debug_iter<vector, pointer> iterator; |
| 1784 | typedef __debug_iter<vector, const_pointer> const_iterator; |
| 1785 | |
| 1786 | friend class __debug_iter<vector, pointer>; |
| 1787 | friend class __debug_iter<vector, const_pointer>; |
| 1788 | |
| 1789 | pair<iterator*, const_iterator*> __iterator_list_; |
| 1790 | |
| 1791 | _LIBCPP_INLINE_VISIBILITY iterator*& __get_iterator_list(iterator*) {return __iterator_list_.first;} |
| 1792 | _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] | 1793 | #else // _LIBCPP_DEBUG |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1794 | typedef pointer iterator; |
| 1795 | typedef const_pointer const_iterator; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1796 | #endif // _LIBCPP_DEBUG |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1797 | typedef _VSTD::reverse_iterator<iterator> reverse_iterator; |
| 1798 | typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1799 | |
| 1800 | private: |
| 1801 | typedef size_type __storage_type; |
| 1802 | typedef typename __alloc_traits::template |
| 1803 | #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES |
| 1804 | rebind_alloc<__storage_type> |
| 1805 | #else |
| 1806 | rebind_alloc<__storage_type>::other |
| 1807 | #endif |
| 1808 | __storage_allocator; |
| 1809 | typedef allocator_traits<__storage_allocator> __storage_traits; |
| 1810 | typedef typename __storage_traits::pointer __storage_pointer; |
| 1811 | typedef typename __storage_traits::const_pointer __const_storage_pointer; |
| 1812 | |
| 1813 | __storage_pointer __begin_; |
| 1814 | size_type __size_; |
| 1815 | __compressed_pair<size_type, __storage_allocator> __cap_alloc_; |
Howard Hinnant | 2bf1c08 | 2011-07-09 15:50:42 +0000 | [diff] [blame] | 1816 | public: |
Howard Hinnant | f03c3b4 | 2011-07-02 20:33:23 +0000 | [diff] [blame] | 1817 | typedef __bit_reference<vector> reference; |
| 1818 | typedef __bit_const_reference<vector> const_reference; |
Howard Hinnant | 2bf1c08 | 2011-07-09 15:50:42 +0000 | [diff] [blame] | 1819 | private: |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1820 | _LIBCPP_INLINE_VISIBILITY |
| 1821 | size_type& __cap() _NOEXCEPT |
| 1822 | {return __cap_alloc_.first();} |
| 1823 | _LIBCPP_INLINE_VISIBILITY |
| 1824 | const size_type& __cap() const _NOEXCEPT |
| 1825 | {return __cap_alloc_.first();} |
| 1826 | _LIBCPP_INLINE_VISIBILITY |
| 1827 | __storage_allocator& __alloc() _NOEXCEPT |
| 1828 | {return __cap_alloc_.second();} |
| 1829 | _LIBCPP_INLINE_VISIBILITY |
| 1830 | const __storage_allocator& __alloc() const _NOEXCEPT |
| 1831 | {return __cap_alloc_.second();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1832 | |
| 1833 | static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT); |
| 1834 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1835 | _LIBCPP_INLINE_VISIBILITY |
| 1836 | static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1837 | {return __n * __bits_per_word;} |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1838 | _LIBCPP_INLINE_VISIBILITY |
| 1839 | static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1840 | {return (__n - 1) / __bits_per_word + 1;} |
| 1841 | |
| 1842 | public: |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1843 | _LIBCPP_INLINE_VISIBILITY |
| 1844 | vector() |
| 1845 | _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value); |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 1846 | _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1847 | ~vector(); |
| 1848 | explicit vector(size_type __n); |
| 1849 | vector(size_type __n, const value_type& __v); |
| 1850 | vector(size_type __n, const value_type& __v, const allocator_type& __a); |
| 1851 | template <class _InputIterator> |
| 1852 | vector(_InputIterator __first, _InputIterator __last, |
| 1853 | typename enable_if<__is_input_iterator <_InputIterator>::value && |
| 1854 | !__is_forward_iterator<_InputIterator>::value>::type* = 0); |
| 1855 | template <class _InputIterator> |
| 1856 | vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, |
| 1857 | typename enable_if<__is_input_iterator <_InputIterator>::value && |
| 1858 | !__is_forward_iterator<_InputIterator>::value>::type* = 0); |
| 1859 | template <class _ForwardIterator> |
| 1860 | vector(_ForwardIterator __first, _ForwardIterator __last, |
| 1861 | typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0); |
| 1862 | template <class _ForwardIterator> |
| 1863 | vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, |
| 1864 | typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0); |
| 1865 | |
| 1866 | vector(const vector& __v); |
| 1867 | vector(const vector& __v, const allocator_type& __a); |
| 1868 | vector& operator=(const vector& __v); |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame^] | 1869 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1870 | vector(initializer_list<value_type> __il); |
| 1871 | vector(initializer_list<value_type> __il, const allocator_type& __a); |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame^] | 1872 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1873 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1874 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1875 | _LIBCPP_INLINE_VISIBILITY |
| 1876 | vector(vector&& __v) |
| 1877 | _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1878 | vector(vector&& __v, const allocator_type& __a); |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1879 | _LIBCPP_INLINE_VISIBILITY |
| 1880 | vector& operator=(vector&& __v) |
| 1881 | _NOEXCEPT_( |
| 1882 | __alloc_traits::propagate_on_container_move_assignment::value && |
| 1883 | is_nothrow_move_assignable<allocator_type>::value); |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1884 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame^] | 1885 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1886 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1887 | vector& operator=(initializer_list<value_type> __il) |
| 1888 | {assign(__il.begin(), __il.end()); return *this;} |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame^] | 1889 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1890 | |
| 1891 | template <class _InputIterator> |
| 1892 | typename enable_if |
| 1893 | < |
| 1894 | __is_input_iterator<_InputIterator>::value && |
| 1895 | !__is_forward_iterator<_InputIterator>::value, |
| 1896 | void |
| 1897 | >::type |
| 1898 | assign(_InputIterator __first, _InputIterator __last); |
| 1899 | template <class _ForwardIterator> |
| 1900 | typename enable_if |
| 1901 | < |
| 1902 | __is_forward_iterator<_ForwardIterator>::value, |
| 1903 | void |
| 1904 | >::type |
| 1905 | assign(_ForwardIterator __first, _ForwardIterator __last); |
| 1906 | |
| 1907 | void assign(size_type __n, const value_type& __x); |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame^] | 1908 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 1909 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1910 | void assign(initializer_list<value_type> __il) |
| 1911 | {assign(__il.begin(), __il.end());} |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame^] | 1912 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1913 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1914 | _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1915 | {return allocator_type(this->__alloc());} |
| 1916 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1917 | size_type max_size() const _NOEXCEPT; |
| 1918 | _LIBCPP_INLINE_VISIBILITY |
| 1919 | size_type capacity() const _NOEXCEPT |
| 1920 | {return __internal_cap_to_external(__cap());} |
| 1921 | _LIBCPP_INLINE_VISIBILITY |
| 1922 | size_type size() const _NOEXCEPT |
| 1923 | {return __size_;} |
| 1924 | _LIBCPP_INLINE_VISIBILITY |
| 1925 | bool empty() const _NOEXCEPT |
| 1926 | {return __size_ == 0;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1927 | void reserve(size_type __n); |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1928 | void shrink_to_fit() _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1929 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1930 | _LIBCPP_INLINE_VISIBILITY |
| 1931 | iterator begin() _NOEXCEPT |
| 1932 | {return __make_iter(0);} |
| 1933 | _LIBCPP_INLINE_VISIBILITY |
| 1934 | const_iterator begin() const _NOEXCEPT |
| 1935 | {return __make_iter(0);} |
| 1936 | _LIBCPP_INLINE_VISIBILITY |
| 1937 | iterator end() _NOEXCEPT |
| 1938 | {return __make_iter(__size_);} |
| 1939 | _LIBCPP_INLINE_VISIBILITY |
| 1940 | const_iterator end() const _NOEXCEPT |
| 1941 | {return __make_iter(__size_);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1942 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1943 | _LIBCPP_INLINE_VISIBILITY |
| 1944 | reverse_iterator rbegin() _NOEXCEPT |
| 1945 | {return reverse_iterator(end());} |
| 1946 | _LIBCPP_INLINE_VISIBILITY |
| 1947 | const_reverse_iterator rbegin() const _NOEXCEPT |
| 1948 | {return const_reverse_iterator(end());} |
| 1949 | _LIBCPP_INLINE_VISIBILITY |
| 1950 | reverse_iterator rend() _NOEXCEPT |
| 1951 | {return reverse_iterator(begin());} |
| 1952 | _LIBCPP_INLINE_VISIBILITY |
| 1953 | const_reverse_iterator rend() const _NOEXCEPT |
| 1954 | {return const_reverse_iterator(begin());} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1955 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 1956 | _LIBCPP_INLINE_VISIBILITY |
| 1957 | const_iterator cbegin() const _NOEXCEPT |
| 1958 | {return __make_iter(0);} |
| 1959 | _LIBCPP_INLINE_VISIBILITY |
| 1960 | const_iterator cend() const _NOEXCEPT |
| 1961 | {return __make_iter(__size_);} |
| 1962 | _LIBCPP_INLINE_VISIBILITY |
| 1963 | const_reverse_iterator crbegin() const _NOEXCEPT |
| 1964 | {return rbegin();} |
| 1965 | _LIBCPP_INLINE_VISIBILITY |
| 1966 | const_reverse_iterator crend() const _NOEXCEPT |
| 1967 | {return rend();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1968 | |
| 1969 | _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) {return __make_ref(__n);} |
| 1970 | _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __make_ref(__n);} |
| 1971 | reference at(size_type __n); |
| 1972 | const_reference at(size_type __n) const; |
| 1973 | |
| 1974 | _LIBCPP_INLINE_VISIBILITY reference front() {return __make_ref(0);} |
| 1975 | _LIBCPP_INLINE_VISIBILITY const_reference front() const {return __make_ref(0);} |
| 1976 | _LIBCPP_INLINE_VISIBILITY reference back() {return __make_ref(__size_ - 1);} |
| 1977 | _LIBCPP_INLINE_VISIBILITY const_reference back() const {return __make_ref(__size_ - 1);} |
| 1978 | |
| 1979 | void push_back(const value_type& __x); |
| 1980 | _LIBCPP_INLINE_VISIBILITY void pop_back() {--__size_;} |
| 1981 | |
| 1982 | iterator insert(const_iterator __position, const value_type& __x); |
| 1983 | iterator insert(const_iterator __position, size_type __n, const value_type& __x); |
| 1984 | iterator insert(const_iterator __position, size_type __n, const_reference __x); |
| 1985 | template <class _InputIterator> |
| 1986 | typename enable_if |
| 1987 | < |
| 1988 | __is_input_iterator <_InputIterator>::value && |
| 1989 | !__is_forward_iterator<_InputIterator>::value, |
| 1990 | iterator |
| 1991 | >::type |
| 1992 | insert(const_iterator __position, _InputIterator __first, _InputIterator __last); |
| 1993 | template <class _ForwardIterator> |
| 1994 | typename enable_if |
| 1995 | < |
| 1996 | __is_forward_iterator<_ForwardIterator>::value, |
| 1997 | iterator |
| 1998 | >::type |
| 1999 | insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame^] | 2000 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2001 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2002 | iterator insert(const_iterator __position, initializer_list<value_type> __il) |
| 2003 | {return insert(__position, __il.begin(), __il.end());} |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame^] | 2004 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2005 | |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 2006 | _LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2007 | iterator erase(const_iterator __first, const_iterator __last); |
| 2008 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2009 | _LIBCPP_INLINE_VISIBILITY |
| 2010 | void clear() _NOEXCEPT {__size_ = 0;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2011 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2012 | void swap(vector&) |
| 2013 | _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || |
| 2014 | __is_nothrow_swappable<allocator_type>::value); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2015 | |
| 2016 | void resize(size_type __sz, value_type __x = false); |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2017 | void flip() _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2018 | |
| 2019 | bool __invariants() const; |
| 2020 | |
| 2021 | private: |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 2022 | _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2023 | void allocate(size_type __n); |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2024 | void deallocate() _NOEXCEPT; |
| 2025 | _LIBCPP_INLINE_VISIBILITY |
| 2026 | static size_type __align(size_type __new_size) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2027 | {return __new_size + (__bits_per_word-1) & ~(__bits_per_word-1);}; |
Howard Hinnant | 2d72b1e | 2010-12-17 14:46:43 +0000 | [diff] [blame] | 2028 | _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const; |
| 2029 | _LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, bool __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2030 | template <class _ForwardIterator> |
| 2031 | typename enable_if |
| 2032 | < |
| 2033 | __is_forward_iterator<_ForwardIterator>::value, |
| 2034 | void |
| 2035 | >::type |
| 2036 | __construct_at_end(_ForwardIterator __first, _ForwardIterator __last); |
| 2037 | void __append(size_type __n, const_reference __x); |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2038 | _LIBCPP_INLINE_VISIBILITY |
| 2039 | reference __make_ref(size_type __pos) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2040 | {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] | 2041 | _LIBCPP_INLINE_VISIBILITY |
| 2042 | const_reference __make_ref(size_type __pos) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2043 | {return const_reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);} |
| 2044 | #ifdef _LIBCPP_DEBUG |
| 2045 | _LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_type __pos) |
| 2046 | {return iterator(this, pointer(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word)));} |
| 2047 | _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_type __pos) const |
| 2048 | {return const_iterator(this, const_pointer(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word)));} |
| 2049 | _LIBCPP_INLINE_VISIBILITY iterator __const_iterator_cast(const_iterator __p) |
| 2050 | {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] | 2051 | #else // _LIBCPP_DEBUG |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2052 | _LIBCPP_INLINE_VISIBILITY |
| 2053 | iterator __make_iter(size_type __pos) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2054 | {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] | 2055 | _LIBCPP_INLINE_VISIBILITY |
| 2056 | const_iterator __make_iter(size_type __pos) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2057 | {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] | 2058 | _LIBCPP_INLINE_VISIBILITY |
| 2059 | iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2060 | {return iterator(const_cast<__storage_pointer>(__p.__seg_), __p.__ctz_);} |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2061 | #endif // _LIBCPP_DEBUG |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2062 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2063 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2064 | void __copy_assign_alloc(const vector& __v) |
| 2065 | {__copy_assign_alloc(__v, integral_constant<bool, |
| 2066 | __storage_traits::propagate_on_container_copy_assignment::value>());} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2067 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2068 | void __copy_assign_alloc(const vector& __c, true_type) |
| 2069 | { |
| 2070 | if (__alloc() != __c.__alloc()) |
| 2071 | deallocate(); |
| 2072 | __alloc() = __c.__alloc(); |
| 2073 | } |
| 2074 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2075 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2076 | void __copy_assign_alloc(const vector& __c, false_type) |
| 2077 | {} |
| 2078 | |
| 2079 | void __move_assign(vector& __c, false_type); |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2080 | void __move_assign(vector& __c, true_type) |
| 2081 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2082 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2083 | void __move_assign_alloc(vector& __c) |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2084 | _NOEXCEPT_( |
| 2085 | !__storage_traits::propagate_on_container_move_assignment::value || |
| 2086 | is_nothrow_move_assignable<allocator_type>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2087 | {__move_assign_alloc(__c, integral_constant<bool, |
| 2088 | __storage_traits::propagate_on_container_move_assignment::value>());} |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2089 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2090 | void __move_assign_alloc(const vector& __c, true_type) |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2091 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2092 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2093 | __alloc() = _VSTD::move(__c.__alloc()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2094 | } |
| 2095 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2096 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2097 | void __move_assign_alloc(const vector& __c, false_type) |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2098 | _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2099 | {} |
| 2100 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2101 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2102 | static void __swap_alloc(__storage_allocator& __x, __storage_allocator& __y) |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2103 | _NOEXCEPT_( |
| 2104 | !__storage_traits::propagate_on_container_swap::value || |
| 2105 | __is_nothrow_swappable<allocator_type>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2106 | {__swap_alloc(__x, __y, integral_constant<bool, |
| 2107 | __storage_traits::propagate_on_container_swap::value>());} |
| 2108 | |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2109 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2110 | static void __swap_alloc(__storage_allocator& __x, __storage_allocator& __y, true_type) |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2111 | _NOEXCEPT_(__is_nothrow_swappable<allocator_type>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2112 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2113 | using _VSTD::swap; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2114 | swap(__x, __y); |
| 2115 | } |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2116 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2117 | static void __swap_alloc(__storage_allocator& __x, __storage_allocator& __y, false_type) |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2118 | _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2119 | {} |
| 2120 | |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2121 | size_t __hash_code() const _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2122 | |
| 2123 | friend class __bit_reference<vector>; |
| 2124 | friend class __bit_const_reference<vector>; |
| 2125 | friend class __bit_iterator<vector, false>; |
| 2126 | friend class __bit_iterator<vector, true>; |
| 2127 | friend class __bit_array<vector>; |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2128 | friend struct _LIBCPP_VISIBLE hash<vector>; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2129 | }; |
| 2130 | |
| 2131 | template <class _Allocator> |
| 2132 | #ifndef _LIBCPP_DEBUG |
| 2133 | _LIBCPP_INLINE_VISIBILITY inline |
| 2134 | #endif |
| 2135 | void |
| 2136 | vector<bool, _Allocator>::__invalidate_all_iterators() |
| 2137 | { |
| 2138 | #ifdef _LIBCPP_DEBUG |
| 2139 | iterator::__remove_all(this); |
| 2140 | const_iterator::__remove_all(this); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2141 | #endif // _LIBCPP_DEBUG |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2142 | } |
| 2143 | |
| 2144 | // Allocate space for __n objects |
| 2145 | // throws length_error if __n > max_size() |
| 2146 | // throws (probably bad_alloc) if memory run out |
| 2147 | // Precondition: __begin_ == __end_ == __cap() == 0 |
| 2148 | // Precondition: __n > 0 |
| 2149 | // Postcondition: capacity() == __n |
| 2150 | // Postcondition: size() == 0 |
| 2151 | template <class _Allocator> |
| 2152 | void |
| 2153 | vector<bool, _Allocator>::allocate(size_type __n) |
| 2154 | { |
| 2155 | if (__n > max_size()) |
| 2156 | this->__throw_length_error(); |
| 2157 | __n = __external_cap_to_internal(__n); |
| 2158 | this->__begin_ = __storage_traits::allocate(this->__alloc(), __n); |
| 2159 | this->__size_ = 0; |
| 2160 | this->__cap() = __n; |
| 2161 | } |
| 2162 | |
| 2163 | template <class _Allocator> |
| 2164 | void |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2165 | vector<bool, _Allocator>::deallocate() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2166 | { |
| 2167 | if (this->__begin_ != 0) |
| 2168 | { |
| 2169 | __storage_traits::deallocate(this->__alloc(), this->__begin_, __cap()); |
| 2170 | __invalidate_all_iterators(); |
| 2171 | this->__begin_ = 0; |
| 2172 | this->__size_ = this->__cap() = 0; |
| 2173 | } |
| 2174 | } |
| 2175 | |
| 2176 | template <class _Allocator> |
| 2177 | typename vector<bool, _Allocator>::size_type |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2178 | vector<bool, _Allocator>::max_size() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2179 | { |
| 2180 | size_type __amax = __storage_traits::max_size(__alloc()); |
| 2181 | size_type __nmax = numeric_limits<size_type>::max() / 2; // end() >= begin(), always |
| 2182 | if (__nmax / __bits_per_word <= __amax) |
| 2183 | return __nmax; |
| 2184 | return __internal_cap_to_external(__amax); |
| 2185 | } |
| 2186 | |
| 2187 | // Precondition: __new_size > capacity() |
| 2188 | template <class _Allocator> |
| 2189 | _LIBCPP_INLINE_VISIBILITY inline |
| 2190 | typename vector<bool, _Allocator>::size_type |
| 2191 | vector<bool, _Allocator>::__recommend(size_type __new_size) const |
| 2192 | { |
| 2193 | const size_type __ms = max_size(); |
| 2194 | if (__new_size > __ms) |
| 2195 | this->__throw_length_error(); |
| 2196 | const size_type __cap = capacity(); |
| 2197 | if (__cap >= __ms / 2) |
| 2198 | return __ms; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2199 | return _VSTD::max(2*__cap, __align(__new_size)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2200 | } |
| 2201 | |
| 2202 | // Default constructs __n objects starting at __end_ |
| 2203 | // Precondition: __n > 0 |
| 2204 | // Precondition: size() + __n <= capacity() |
| 2205 | // Postcondition: size() == size() + __n |
| 2206 | template <class _Allocator> |
| 2207 | _LIBCPP_INLINE_VISIBILITY inline |
| 2208 | void |
| 2209 | vector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x) |
| 2210 | { |
| 2211 | size_type __old_size = this->__size_; |
| 2212 | this->__size_ += __n; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2213 | _VSTD::fill_n(__make_iter(__old_size), __n, __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2214 | } |
| 2215 | |
| 2216 | template <class _Allocator> |
| 2217 | template <class _ForwardIterator> |
| 2218 | typename enable_if |
| 2219 | < |
| 2220 | __is_forward_iterator<_ForwardIterator>::value, |
| 2221 | void |
| 2222 | >::type |
| 2223 | vector<bool, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last) |
| 2224 | { |
| 2225 | size_type __old_size = this->__size_; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2226 | this->__size_ += _VSTD::distance(__first, __last); |
| 2227 | _VSTD::copy(__first, __last, __make_iter(__old_size)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2228 | } |
| 2229 | |
| 2230 | template <class _Allocator> |
| 2231 | _LIBCPP_INLINE_VISIBILITY inline |
| 2232 | vector<bool, _Allocator>::vector() |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2233 | _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2234 | : __begin_(0), |
| 2235 | __size_(0), |
| 2236 | __cap_alloc_(0) |
| 2237 | { |
| 2238 | } |
| 2239 | |
| 2240 | template <class _Allocator> |
| 2241 | _LIBCPP_INLINE_VISIBILITY inline |
| 2242 | vector<bool, _Allocator>::vector(const allocator_type& __a) |
| 2243 | : __begin_(0), |
| 2244 | __size_(0), |
| 2245 | __cap_alloc_(0, static_cast<__storage_allocator>(__a)) |
| 2246 | { |
| 2247 | } |
| 2248 | |
| 2249 | template <class _Allocator> |
| 2250 | vector<bool, _Allocator>::vector(size_type __n) |
| 2251 | : __begin_(0), |
| 2252 | __size_(0), |
| 2253 | __cap_alloc_(0) |
| 2254 | { |
| 2255 | if (__n > 0) |
| 2256 | { |
| 2257 | allocate(__n); |
| 2258 | __construct_at_end(__n, false); |
| 2259 | } |
| 2260 | } |
| 2261 | |
| 2262 | template <class _Allocator> |
| 2263 | vector<bool, _Allocator>::vector(size_type __n, const value_type& __x) |
| 2264 | : __begin_(0), |
| 2265 | __size_(0), |
| 2266 | __cap_alloc_(0) |
| 2267 | { |
| 2268 | if (__n > 0) |
| 2269 | { |
| 2270 | allocate(__n); |
| 2271 | __construct_at_end(__n, __x); |
| 2272 | } |
| 2273 | } |
| 2274 | |
| 2275 | template <class _Allocator> |
| 2276 | vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a) |
| 2277 | : __begin_(0), |
| 2278 | __size_(0), |
| 2279 | __cap_alloc_(0, static_cast<__storage_allocator>(__a)) |
| 2280 | { |
| 2281 | if (__n > 0) |
| 2282 | { |
| 2283 | allocate(__n); |
| 2284 | __construct_at_end(__n, __x); |
| 2285 | } |
| 2286 | } |
| 2287 | |
| 2288 | template <class _Allocator> |
| 2289 | template <class _InputIterator> |
| 2290 | vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, |
| 2291 | typename enable_if<__is_input_iterator <_InputIterator>::value && |
| 2292 | !__is_forward_iterator<_InputIterator>::value>::type*) |
| 2293 | : __begin_(0), |
| 2294 | __size_(0), |
| 2295 | __cap_alloc_(0) |
| 2296 | { |
| 2297 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2298 | try |
| 2299 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2300 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2301 | for (; __first != __last; ++__first) |
| 2302 | push_back(*__first); |
| 2303 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2304 | } |
| 2305 | catch (...) |
| 2306 | { |
| 2307 | if (__begin_ != 0) |
| 2308 | __storage_traits::deallocate(__alloc(), __begin_, __cap()); |
| 2309 | __invalidate_all_iterators(); |
| 2310 | throw; |
| 2311 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2312 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2313 | } |
| 2314 | |
| 2315 | template <class _Allocator> |
| 2316 | template <class _InputIterator> |
| 2317 | vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a, |
| 2318 | typename enable_if<__is_input_iterator <_InputIterator>::value && |
| 2319 | !__is_forward_iterator<_InputIterator>::value>::type*) |
| 2320 | : __begin_(0), |
| 2321 | __size_(0), |
| 2322 | __cap_alloc_(0, static_cast<__storage_allocator>(__a)) |
| 2323 | { |
| 2324 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2325 | try |
| 2326 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2327 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2328 | for (; __first != __last; ++__first) |
| 2329 | push_back(*__first); |
| 2330 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2331 | } |
| 2332 | catch (...) |
| 2333 | { |
| 2334 | if (__begin_ != 0) |
| 2335 | __storage_traits::deallocate(__alloc(), __begin_, __cap()); |
| 2336 | __invalidate_all_iterators(); |
| 2337 | throw; |
| 2338 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2339 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2340 | } |
| 2341 | |
| 2342 | template <class _Allocator> |
| 2343 | template <class _ForwardIterator> |
| 2344 | vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, |
| 2345 | typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*) |
| 2346 | : __begin_(0), |
| 2347 | __size_(0), |
| 2348 | __cap_alloc_(0) |
| 2349 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2350 | size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2351 | if (__n > 0) |
| 2352 | { |
| 2353 | allocate(__n); |
| 2354 | __construct_at_end(__first, __last); |
| 2355 | } |
| 2356 | } |
| 2357 | |
| 2358 | template <class _Allocator> |
| 2359 | template <class _ForwardIterator> |
| 2360 | vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a, |
| 2361 | typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*) |
| 2362 | : __begin_(0), |
| 2363 | __size_(0), |
| 2364 | __cap_alloc_(0, static_cast<__storage_allocator>(__a)) |
| 2365 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2366 | size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2367 | if (__n > 0) |
| 2368 | { |
| 2369 | allocate(__n); |
| 2370 | __construct_at_end(__first, __last); |
| 2371 | } |
| 2372 | } |
| 2373 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame^] | 2374 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 2375 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2376 | template <class _Allocator> |
| 2377 | vector<bool, _Allocator>::vector(initializer_list<value_type> __il) |
| 2378 | : __begin_(0), |
| 2379 | __size_(0), |
| 2380 | __cap_alloc_(0) |
| 2381 | { |
| 2382 | size_type __n = static_cast<size_type>(__il.size()); |
| 2383 | if (__n > 0) |
| 2384 | { |
| 2385 | allocate(__n); |
| 2386 | __construct_at_end(__il.begin(), __il.end()); |
| 2387 | } |
| 2388 | } |
| 2389 | |
| 2390 | template <class _Allocator> |
| 2391 | vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a) |
| 2392 | : __begin_(0), |
| 2393 | __size_(0), |
| 2394 | __cap_alloc_(0, static_cast<__storage_allocator>(__a)) |
| 2395 | { |
| 2396 | size_type __n = static_cast<size_type>(__il.size()); |
| 2397 | if (__n > 0) |
| 2398 | { |
| 2399 | allocate(__n); |
| 2400 | __construct_at_end(__il.begin(), __il.end()); |
| 2401 | } |
| 2402 | } |
| 2403 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame^] | 2404 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 2405 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2406 | template <class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2407 | vector<bool, _Allocator>::~vector() |
| 2408 | { |
| 2409 | if (__begin_ != 0) |
| 2410 | __storage_traits::deallocate(__alloc(), __begin_, __cap()); |
| 2411 | #ifdef _LIBCPP_DEBUG |
| 2412 | __invalidate_all_iterators(); |
| 2413 | #endif |
| 2414 | } |
| 2415 | |
| 2416 | template <class _Allocator> |
| 2417 | vector<bool, _Allocator>::vector(const vector& __v) |
| 2418 | : __begin_(0), |
| 2419 | __size_(0), |
| 2420 | __cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc())) |
| 2421 | { |
| 2422 | if (__v.size() > 0) |
| 2423 | { |
| 2424 | allocate(__v.size()); |
| 2425 | __construct_at_end(__v.begin(), __v.end()); |
| 2426 | } |
| 2427 | } |
| 2428 | |
| 2429 | template <class _Allocator> |
| 2430 | vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a) |
| 2431 | : __begin_(0), |
| 2432 | __size_(0), |
| 2433 | __cap_alloc_(0, __a) |
| 2434 | { |
| 2435 | if (__v.size() > 0) |
| 2436 | { |
| 2437 | allocate(__v.size()); |
| 2438 | __construct_at_end(__v.begin(), __v.end()); |
| 2439 | } |
| 2440 | } |
| 2441 | |
| 2442 | template <class _Allocator> |
| 2443 | vector<bool, _Allocator>& |
| 2444 | vector<bool, _Allocator>::operator=(const vector& __v) |
| 2445 | { |
| 2446 | if (this != &__v) |
| 2447 | { |
| 2448 | __copy_assign_alloc(__v); |
| 2449 | if (__v.__size_) |
| 2450 | { |
| 2451 | if (__v.__size_ > capacity()) |
| 2452 | { |
| 2453 | deallocate(); |
| 2454 | allocate(__v.__size_); |
| 2455 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2456 | _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] | 2457 | } |
| 2458 | __size_ = __v.__size_; |
| 2459 | } |
| 2460 | return *this; |
| 2461 | } |
| 2462 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2463 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 2464 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2465 | template <class _Allocator> |
| 2466 | _LIBCPP_INLINE_VISIBILITY inline |
| 2467 | vector<bool, _Allocator>::vector(vector&& __v) |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2468 | _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2469 | : __begin_(__v.__begin_), |
| 2470 | __size_(__v.__size_), |
| 2471 | __cap_alloc_(__v.__cap_alloc_) |
| 2472 | { |
| 2473 | __v.__begin_ = 0; |
| 2474 | __v.__size_ = 0; |
| 2475 | __v.__cap() = 0; |
| 2476 | } |
| 2477 | |
| 2478 | template <class _Allocator> |
| 2479 | vector<bool, _Allocator>::vector(vector&& __v, const allocator_type& __a) |
| 2480 | : __begin_(0), |
| 2481 | __size_(0), |
| 2482 | __cap_alloc_(0, __a) |
| 2483 | { |
| 2484 | if (__a == allocator_type(__v.__alloc())) |
| 2485 | { |
| 2486 | this->__begin_ = __v.__begin_; |
| 2487 | this->__size_ = __v.__size_; |
| 2488 | this->__cap() = __v.__cap(); |
| 2489 | __v.__begin_ = nullptr; |
| 2490 | __v.__cap() = __v.__size_ = 0; |
| 2491 | } |
| 2492 | else if (__v.size() > 0) |
| 2493 | { |
| 2494 | allocate(__v.size()); |
| 2495 | __construct_at_end(__v.begin(), __v.end()); |
| 2496 | } |
| 2497 | } |
| 2498 | |
| 2499 | template <class _Allocator> |
| 2500 | _LIBCPP_INLINE_VISIBILITY inline |
| 2501 | vector<bool, _Allocator>& |
| 2502 | vector<bool, _Allocator>::operator=(vector&& __v) |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2503 | _NOEXCEPT_( |
| 2504 | __alloc_traits::propagate_on_container_move_assignment::value && |
| 2505 | is_nothrow_move_assignable<allocator_type>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2506 | { |
| 2507 | __move_assign(__v, integral_constant<bool, |
| 2508 | __storage_traits::propagate_on_container_move_assignment::value>()); |
| 2509 | } |
| 2510 | |
| 2511 | template <class _Allocator> |
| 2512 | void |
| 2513 | vector<bool, _Allocator>::__move_assign(vector& __c, false_type) |
| 2514 | { |
| 2515 | if (__alloc() != __c.__alloc()) |
| 2516 | assign(__c.begin(), __c.end()); |
| 2517 | else |
| 2518 | __move_assign(__c, true_type()); |
| 2519 | } |
| 2520 | |
| 2521 | template <class _Allocator> |
| 2522 | void |
| 2523 | vector<bool, _Allocator>::__move_assign(vector& __c, true_type) |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2524 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2525 | { |
| 2526 | deallocate(); |
| 2527 | this->__begin_ = __c.__begin_; |
| 2528 | this->__size_ = __c.__size_; |
| 2529 | this->__cap() = __c.__cap(); |
| 2530 | __move_assign_alloc(__c); |
| 2531 | __c.__begin_ = nullptr; |
| 2532 | __c.__cap() = __c.__size_ = 0; |
| 2533 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 2534 | |
| 2535 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2536 | |
| 2537 | template <class _Allocator> |
| 2538 | void |
| 2539 | vector<bool, _Allocator>::assign(size_type __n, const value_type& __x) |
| 2540 | { |
| 2541 | __size_ = 0; |
| 2542 | if (__n > 0) |
| 2543 | { |
| 2544 | size_type __c = capacity(); |
| 2545 | if (__n <= __c) |
| 2546 | __size_ = __n; |
| 2547 | else |
| 2548 | { |
| 2549 | vector __v(__alloc()); |
| 2550 | __v.reserve(__recommend(__n)); |
| 2551 | __v.__size_ = __n; |
| 2552 | swap(__v); |
| 2553 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2554 | _VSTD::fill_n(begin(), __n, __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2555 | } |
| 2556 | } |
| 2557 | |
| 2558 | template <class _Allocator> |
| 2559 | template <class _InputIterator> |
| 2560 | typename enable_if |
| 2561 | < |
| 2562 | __is_input_iterator<_InputIterator>::value && |
| 2563 | !__is_forward_iterator<_InputIterator>::value, |
| 2564 | void |
| 2565 | >::type |
| 2566 | vector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last) |
| 2567 | { |
| 2568 | clear(); |
| 2569 | for (; __first != __last; ++__first) |
| 2570 | push_back(*__first); |
| 2571 | } |
| 2572 | |
| 2573 | template <class _Allocator> |
| 2574 | template <class _ForwardIterator> |
| 2575 | typename enable_if |
| 2576 | < |
| 2577 | __is_forward_iterator<_ForwardIterator>::value, |
| 2578 | void |
| 2579 | >::type |
| 2580 | vector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) |
| 2581 | { |
| 2582 | clear(); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2583 | difference_type __n = _VSTD::distance(__first, __last); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2584 | if (__n) |
| 2585 | { |
| 2586 | if (__n > capacity()) |
| 2587 | { |
| 2588 | deallocate(); |
| 2589 | allocate(__n); |
| 2590 | } |
| 2591 | __construct_at_end(__first, __last); |
| 2592 | } |
| 2593 | } |
| 2594 | |
| 2595 | template <class _Allocator> |
| 2596 | void |
| 2597 | vector<bool, _Allocator>::reserve(size_type __n) |
| 2598 | { |
| 2599 | if (__n > capacity()) |
| 2600 | { |
| 2601 | vector __v(this->__alloc()); |
| 2602 | __v.allocate(__n); |
| 2603 | __v.__construct_at_end(this->begin(), this->end()); |
| 2604 | swap(__v); |
| 2605 | __invalidate_all_iterators(); |
| 2606 | } |
| 2607 | } |
| 2608 | |
| 2609 | template <class _Allocator> |
| 2610 | void |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2611 | vector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2612 | { |
| 2613 | if (__external_cap_to_internal(size()) > __cap()) |
| 2614 | { |
| 2615 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2616 | try |
| 2617 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2618 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2619 | vector(*this, allocator_type(__alloc())).swap(*this); |
| 2620 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2621 | } |
| 2622 | catch (...) |
| 2623 | { |
| 2624 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2625 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2626 | } |
| 2627 | } |
| 2628 | |
| 2629 | template <class _Allocator> |
| 2630 | typename vector<bool, _Allocator>::reference |
| 2631 | vector<bool, _Allocator>::at(size_type __n) |
| 2632 | { |
| 2633 | if (__n >= size()) |
| 2634 | this->__throw_out_of_range(); |
| 2635 | return (*this)[__n]; |
| 2636 | } |
| 2637 | |
| 2638 | template <class _Allocator> |
| 2639 | typename vector<bool, _Allocator>::const_reference |
| 2640 | vector<bool, _Allocator>::at(size_type __n) const |
| 2641 | { |
| 2642 | if (__n >= size()) |
| 2643 | this->__throw_out_of_range(); |
| 2644 | return (*this)[__n]; |
| 2645 | } |
| 2646 | |
| 2647 | template <class _Allocator> |
| 2648 | void |
| 2649 | vector<bool, _Allocator>::push_back(const value_type& __x) |
| 2650 | { |
| 2651 | if (this->__size_ == this->capacity()) |
| 2652 | reserve(__recommend(this->__size_ + 1)); |
| 2653 | ++this->__size_; |
| 2654 | back() = __x; |
| 2655 | } |
| 2656 | |
| 2657 | template <class _Allocator> |
| 2658 | typename vector<bool, _Allocator>::iterator |
| 2659 | vector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x) |
| 2660 | { |
| 2661 | iterator __r; |
| 2662 | if (size() < capacity()) |
| 2663 | { |
| 2664 | const_iterator __old_end = end(); |
| 2665 | ++__size_; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2666 | _VSTD::copy_backward(__position, __old_end, end()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2667 | __r = __const_iterator_cast(__position); |
| 2668 | } |
| 2669 | else |
| 2670 | { |
| 2671 | vector __v(__alloc()); |
| 2672 | __v.reserve(__recommend(__size_ + 1)); |
| 2673 | __v.__size_ = __size_ + 1; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2674 | __r = _VSTD::copy(cbegin(), __position, __v.begin()); |
| 2675 | _VSTD::copy_backward(__position, cend(), __v.end()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2676 | swap(__v); |
| 2677 | } |
| 2678 | *__r = __x; |
| 2679 | return __r; |
| 2680 | } |
| 2681 | |
| 2682 | template <class _Allocator> |
| 2683 | typename vector<bool, _Allocator>::iterator |
| 2684 | vector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x) |
| 2685 | { |
| 2686 | iterator __r; |
| 2687 | size_type __c = capacity(); |
| 2688 | if (__n <= __c && size() <= __c - __n) |
| 2689 | { |
| 2690 | const_iterator __old_end = end(); |
| 2691 | __size_ += __n; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2692 | _VSTD::copy_backward(__position, __old_end, end()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2693 | __r = __const_iterator_cast(__position); |
| 2694 | } |
| 2695 | else |
| 2696 | { |
| 2697 | vector __v(__alloc()); |
| 2698 | __v.reserve(__recommend(__size_ + __n)); |
| 2699 | __v.__size_ = __size_ + __n; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2700 | __r = _VSTD::copy(cbegin(), __position, __v.begin()); |
| 2701 | _VSTD::copy_backward(__position, cend(), __v.end()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2702 | swap(__v); |
| 2703 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2704 | _VSTD::fill_n(__r, __n, __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2705 | return __r; |
| 2706 | } |
| 2707 | |
| 2708 | template <class _Allocator> |
| 2709 | template <class _InputIterator> |
| 2710 | typename enable_if |
| 2711 | < |
| 2712 | __is_input_iterator <_InputIterator>::value && |
| 2713 | !__is_forward_iterator<_InputIterator>::value, |
| 2714 | typename vector<bool, _Allocator>::iterator |
| 2715 | >::type |
| 2716 | vector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last) |
| 2717 | { |
| 2718 | difference_type __off = __position - begin(); |
| 2719 | iterator __p = __const_iterator_cast(__position); |
| 2720 | iterator __old_end = end(); |
| 2721 | for (; size() != capacity() && __first != __last; ++__first) |
| 2722 | { |
| 2723 | ++this->__size_; |
| 2724 | back() = *__first; |
| 2725 | } |
| 2726 | vector __v(__alloc()); |
| 2727 | if (__first != __last) |
| 2728 | { |
| 2729 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2730 | try |
| 2731 | { |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2732 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2733 | __v.assign(__first, __last); |
| 2734 | difference_type __old_size = static_cast<difference_type>(__old_end - begin()); |
| 2735 | difference_type __old_p = __p - begin(); |
| 2736 | reserve(__recommend(size() + __v.size())); |
| 2737 | __p = begin() + __old_p; |
| 2738 | __old_end = begin() + __old_size; |
| 2739 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2740 | } |
| 2741 | catch (...) |
| 2742 | { |
| 2743 | erase(__old_end, end()); |
| 2744 | throw; |
| 2745 | } |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2746 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2747 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2748 | __p = _VSTD::rotate(__p, __old_end, end()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2749 | insert(__p, __v.begin(), __v.end()); |
| 2750 | return begin() + __off; |
| 2751 | } |
| 2752 | |
| 2753 | template <class _Allocator> |
| 2754 | template <class _ForwardIterator> |
| 2755 | typename enable_if |
| 2756 | < |
| 2757 | __is_forward_iterator<_ForwardIterator>::value, |
| 2758 | typename vector<bool, _Allocator>::iterator |
| 2759 | >::type |
| 2760 | vector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last) |
| 2761 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2762 | difference_type __n = _VSTD::distance(__first, __last); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2763 | iterator __r; |
| 2764 | size_type __c = capacity(); |
| 2765 | if (__n <= __c && size() <= __c - __n) |
| 2766 | { |
| 2767 | const_iterator __old_end = end(); |
| 2768 | __size_ += __n; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2769 | _VSTD::copy_backward(__position, __old_end, end()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2770 | __r = __const_iterator_cast(__position); |
| 2771 | } |
| 2772 | else |
| 2773 | { |
| 2774 | vector __v(__alloc()); |
| 2775 | __v.reserve(__recommend(__size_ + __n)); |
| 2776 | __v.__size_ = __size_ + __n; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2777 | __r = _VSTD::copy(cbegin(), __position, __v.begin()); |
| 2778 | _VSTD::copy_backward(__position, cend(), __v.end()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2779 | swap(__v); |
| 2780 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2781 | _VSTD::copy(__first, __last, __r); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2782 | return __r; |
| 2783 | } |
| 2784 | |
| 2785 | template <class _Allocator> |
| 2786 | _LIBCPP_INLINE_VISIBILITY inline |
| 2787 | typename vector<bool, _Allocator>::iterator |
| 2788 | vector<bool, _Allocator>::erase(const_iterator __position) |
| 2789 | { |
| 2790 | iterator __r = __const_iterator_cast(__position); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2791 | _VSTD::copy(__position + 1, this->cend(), __r); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2792 | --__size_; |
| 2793 | return __r; |
| 2794 | } |
| 2795 | |
| 2796 | template <class _Allocator> |
| 2797 | typename vector<bool, _Allocator>::iterator |
| 2798 | vector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last) |
| 2799 | { |
| 2800 | iterator __r = __const_iterator_cast(__first); |
| 2801 | difference_type __d = __last - __first; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2802 | _VSTD::copy(__last, this->cend(), __r); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2803 | __size_ -= __d; |
| 2804 | return __r; |
| 2805 | } |
| 2806 | |
| 2807 | template <class _Allocator> |
| 2808 | void |
| 2809 | vector<bool, _Allocator>::swap(vector& __x) |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2810 | _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || |
| 2811 | __is_nothrow_swappable<allocator_type>::value) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2812 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2813 | _VSTD::swap(this->__begin_, __x.__begin_); |
| 2814 | _VSTD::swap(this->__size_, __x.__size_); |
| 2815 | _VSTD::swap(this->__cap(), __x.__cap()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2816 | __swap_alloc(this->__alloc(), __x.__alloc()); |
| 2817 | #ifdef _LIBCPP_DEBUG |
| 2818 | iterator::swap(this, &__x); |
| 2819 | const_iterator::swap(this, &__x); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2820 | #endif // _LIBCPP_DEBUG |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2821 | } |
| 2822 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2823 | template <class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2824 | void |
| 2825 | vector<bool, _Allocator>::resize(size_type __sz, value_type __x) |
| 2826 | { |
| 2827 | size_type __cs = size(); |
| 2828 | if (__cs < __sz) |
| 2829 | { |
| 2830 | iterator __r; |
| 2831 | size_type __c = capacity(); |
| 2832 | size_type __n = __sz - __cs; |
| 2833 | if (__n <= __c && __cs <= __c - __n) |
| 2834 | { |
| 2835 | __r = end(); |
| 2836 | __size_ += __n; |
| 2837 | } |
| 2838 | else |
| 2839 | { |
| 2840 | vector __v(__alloc()); |
| 2841 | __v.reserve(__recommend(__size_ + __n)); |
| 2842 | __v.__size_ = __size_ + __n; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2843 | __r = _VSTD::copy(cbegin(), cend(), __v.begin()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2844 | swap(__v); |
| 2845 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2846 | _VSTD::fill_n(__r, __n, __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2847 | } |
| 2848 | else |
| 2849 | __size_ = __sz; |
| 2850 | } |
| 2851 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2852 | template <class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2853 | void |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2854 | vector<bool, _Allocator>::flip() _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2855 | { |
| 2856 | // do middle whole words |
| 2857 | size_type __n = __size_; |
| 2858 | __storage_pointer __p = __begin_; |
| 2859 | for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) |
| 2860 | *__p = ~*__p; |
| 2861 | // do last partial word |
| 2862 | if (__n > 0) |
| 2863 | { |
| 2864 | __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); |
| 2865 | __storage_type __b = *__p & __m; |
| 2866 | *__p &= ~__m; |
| 2867 | *__p |= ~__b & __m; |
| 2868 | } |
| 2869 | } |
| 2870 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2871 | template <class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2872 | bool |
| 2873 | vector<bool, _Allocator>::__invariants() const |
| 2874 | { |
| 2875 | if (this->__begin_ == 0) |
| 2876 | { |
| 2877 | if (this->__size_ != 0 || this->__cap() != 0) |
| 2878 | return false; |
| 2879 | } |
| 2880 | else |
| 2881 | { |
| 2882 | if (this->__cap() == 0) |
| 2883 | return false; |
| 2884 | if (this->__size_ > this->capacity()) |
| 2885 | return false; |
| 2886 | } |
| 2887 | return true; |
| 2888 | } |
| 2889 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2890 | template <class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2891 | size_t |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2892 | vector<bool, _Allocator>::__hash_code() const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2893 | { |
| 2894 | size_t __h = 0; |
| 2895 | // do middle whole words |
| 2896 | size_type __n = __size_; |
| 2897 | __storage_pointer __p = __begin_; |
| 2898 | for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word) |
| 2899 | __h ^= *__p; |
| 2900 | // do last partial word |
| 2901 | if (__n > 0) |
| 2902 | { |
| 2903 | const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n); |
| 2904 | __h ^= *__p & __m; |
| 2905 | } |
| 2906 | return __h; |
| 2907 | } |
| 2908 | |
| 2909 | template <class _Allocator> |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2910 | struct _LIBCPP_VISIBLE hash<vector<bool, _Allocator> > |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2911 | : public unary_function<vector<bool, _Allocator>, size_t> |
| 2912 | { |
Howard Hinnant | ee6ccd0 | 2010-09-23 18:58:28 +0000 | [diff] [blame] | 2913 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2914 | size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2915 | {return __vec.__hash_code();} |
| 2916 | }; |
| 2917 | |
| 2918 | template <class _Tp, class _Allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2919 | _LIBCPP_INLINE_VISIBILITY inline |
| 2920 | bool |
| 2921 | operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) |
| 2922 | { |
| 2923 | const typename vector<_Tp, _Allocator>::size_type __sz = __x.size(); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2924 | return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2925 | } |
| 2926 | |
| 2927 | template <class _Tp, class _Allocator> |
| 2928 | _LIBCPP_INLINE_VISIBILITY inline |
| 2929 | bool |
| 2930 | operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) |
| 2931 | { |
| 2932 | return !(__x == __y); |
| 2933 | } |
| 2934 | |
| 2935 | template <class _Tp, class _Allocator> |
| 2936 | _LIBCPP_INLINE_VISIBILITY inline |
| 2937 | bool |
| 2938 | operator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) |
| 2939 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2940 | return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2941 | } |
| 2942 | |
| 2943 | template <class _Tp, class _Allocator> |
| 2944 | _LIBCPP_INLINE_VISIBILITY inline |
| 2945 | bool |
| 2946 | operator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) |
| 2947 | { |
| 2948 | return __y < __x; |
| 2949 | } |
| 2950 | |
| 2951 | template <class _Tp, class _Allocator> |
| 2952 | _LIBCPP_INLINE_VISIBILITY inline |
| 2953 | bool |
| 2954 | operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) |
| 2955 | { |
| 2956 | return !(__x < __y); |
| 2957 | } |
| 2958 | |
| 2959 | template <class _Tp, class _Allocator> |
| 2960 | _LIBCPP_INLINE_VISIBILITY inline |
| 2961 | bool |
| 2962 | operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) |
| 2963 | { |
| 2964 | return !(__y < __x); |
| 2965 | } |
| 2966 | |
| 2967 | template <class _Tp, class _Allocator> |
| 2968 | _LIBCPP_INLINE_VISIBILITY inline |
| 2969 | void |
| 2970 | swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y) |
Howard Hinnant | d1d27a4 | 2011-06-03 19:40:40 +0000 | [diff] [blame] | 2971 | _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2972 | { |
| 2973 | __x.swap(__y); |
| 2974 | } |
| 2975 | |
| 2976 | _LIBCPP_END_NAMESPACE_STD |
| 2977 | |
| 2978 | #endif // _LIBCPP_VECTOR |