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