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