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