Mercurial > hg > CbC > CbC_llvm
comparison libcxx/include/deque @ 236:c4bab56944e8 llvm-original
LLVM 16
author | kono |
---|---|
date | Wed, 09 Nov 2022 17:45:10 +0900 |
parents | 5f17cb93ff66 |
children | 1f2b6ac9f198 |
comparison
equal
deleted
inserted
replaced
232:70dce7da266c | 236:c4bab56944e8 |
---|---|
1 // -*- C++ -*- | 1 // -*- C++ -*- |
2 //===---------------------------- deque -----------------------------------===// | 2 //===----------------------------------------------------------------------===// |
3 // | 3 // |
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | 4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
5 // See https://llvm.org/LICENSE.txt for license information. | 5 // See https://llvm.org/LICENSE.txt for license information. |
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | 6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
7 // | 7 // |
127 void clear() noexcept; | 127 void clear() noexcept; |
128 }; | 128 }; |
129 | 129 |
130 template <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>> | 130 template <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>> |
131 deque(InputIterator, InputIterator, Allocator = Allocator()) | 131 deque(InputIterator, InputIterator, Allocator = Allocator()) |
132 -> deque<typename iterator_traits<InputIterator>::value_type, Allocator>; | 132 -> deque<typename iterator_traits<InputIterator>::value_type, Allocator>; // C++17 |
133 | 133 |
134 template <class T, class Allocator> | 134 template <class T, class Allocator> |
135 bool operator==(const deque<T,Allocator>& x, const deque<T,Allocator>& y); | 135 bool operator==(const deque<T,Allocator>& x, const deque<T,Allocator>& y); |
136 template <class T, class Allocator> | 136 template <class T, class Allocator> |
137 bool operator< (const deque<T,Allocator>& x, const deque<T,Allocator>& y); | 137 bool operator< (const deque<T,Allocator>& x, const deque<T,Allocator>& y); |
158 | 158 |
159 } // std | 159 } // std |
160 | 160 |
161 */ | 161 */ |
162 | 162 |
163 #include <__algorithm/copy.h> | |
164 #include <__algorithm/copy_backward.h> | |
165 #include <__algorithm/equal.h> | |
166 #include <__algorithm/fill_n.h> | |
167 #include <__algorithm/lexicographical_compare.h> | |
168 #include <__algorithm/min.h> | |
169 #include <__algorithm/remove.h> | |
170 #include <__algorithm/remove_if.h> | |
171 #include <__algorithm/unwrap_iter.h> | |
172 #include <__assert> // all public C++ headers provide the assertion handler | |
163 #include <__config> | 173 #include <__config> |
164 #include <__debug> | 174 #include <__format/enable_insertable.h> |
175 #include <__iterator/iterator_traits.h> | |
176 #include <__iterator/next.h> | |
177 #include <__iterator/prev.h> | |
178 #include <__iterator/reverse_iterator.h> | |
179 #include <__memory/pointer_traits.h> | |
180 #include <__memory/temp_value.h> | |
181 #include <__memory/unique_ptr.h> | |
182 #include <__memory_resource/polymorphic_allocator.h> | |
165 #include <__split_buffer> | 183 #include <__split_buffer> |
184 #include <__type_traits/is_allocator.h> | |
166 #include <__utility/forward.h> | 185 #include <__utility/forward.h> |
167 #include <algorithm> | 186 #include <__utility/move.h> |
168 #include <compare> | 187 #include <__utility/swap.h> |
169 #include <initializer_list> | |
170 #include <iterator> | |
171 #include <limits> | 188 #include <limits> |
172 #include <stdexcept> | 189 #include <stdexcept> |
173 #include <type_traits> | 190 #include <type_traits> |
174 #include <version> | 191 #include <version> |
175 | 192 |
193 // standard-mandated includes | |
194 | |
195 // [iterator.range] | |
196 #include <__iterator/access.h> | |
197 #include <__iterator/data.h> | |
198 #include <__iterator/empty.h> | |
199 #include <__iterator/reverse_access.h> | |
200 #include <__iterator/size.h> | |
201 | |
202 // [deque.syn] | |
203 #include <compare> | |
204 #include <initializer_list> | |
205 | |
176 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | 206 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
177 #pragma GCC system_header | 207 # pragma GCC system_header |
178 #endif | 208 #endif |
179 | 209 |
180 _LIBCPP_PUSH_MACROS | 210 _LIBCPP_PUSH_MACROS |
181 #include <__undef_macros> | 211 #include <__undef_macros> |
182 | 212 |
183 | 213 |
184 _LIBCPP_BEGIN_NAMESPACE_STD | 214 _LIBCPP_BEGIN_NAMESPACE_STD |
185 | 215 |
186 template <class _Tp, class _Allocator> class __deque_base; | |
187 template <class _Tp, class _Allocator = allocator<_Tp> > class _LIBCPP_TEMPLATE_VIS deque; | 216 template <class _Tp, class _Allocator = allocator<_Tp> > class _LIBCPP_TEMPLATE_VIS deque; |
188 | 217 |
189 template <class _ValueType, class _Pointer, class _Reference, class _MapPointer, | 218 template <class _ValueType, class _Pointer, class _Reference, class _MapPointer, |
190 class _DiffType, _DiffType _BlockSize> | 219 class _DiffType, _DiffType _BlockSize> |
191 class _LIBCPP_TEMPLATE_VIS __deque_iterator; | 220 class _LIBCPP_TEMPLATE_VIS __deque_iterator; |
192 | 221 |
193 template <class _RAIter, | 222 template <class _RAIter, |
194 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 223 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> |
195 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 224 _LIBCPP_HIDE_FROM_ABI __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> |
196 copy(_RAIter __f, | 225 copy(_RAIter __f, |
197 _RAIter __l, | 226 _RAIter __l, |
198 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, | 227 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, |
199 typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type* = 0); | 228 typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type* = 0); |
200 | 229 |
201 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 230 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, |
202 class _OutputIterator> | 231 class _OutputIterator> |
203 _OutputIterator | 232 _LIBCPP_HIDE_FROM_ABI _OutputIterator |
204 copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 233 copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, |
205 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 234 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, |
206 _OutputIterator __r); | 235 _OutputIterator __r); |
207 | 236 |
208 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 237 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, |
209 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 238 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> |
210 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 239 _LIBCPP_HIDE_FROM_ABI __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> |
211 copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 240 copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, |
212 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 241 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, |
213 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); | 242 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); |
214 | 243 |
215 template <class _RAIter, | 244 template <class _RAIter, |
216 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 245 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> |
217 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 246 _LIBCPP_HIDE_FROM_ABI __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> |
218 copy_backward(_RAIter __f, | 247 copy_backward(_RAIter __f, |
219 _RAIter __l, | 248 _RAIter __l, |
220 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, | 249 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, |
221 typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type* = 0); | 250 typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type* = 0); |
222 | 251 |
223 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 252 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, |
224 class _OutputIterator> | 253 class _OutputIterator> |
225 _OutputIterator | 254 _LIBCPP_HIDE_FROM_ABI _OutputIterator |
226 copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 255 copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, |
227 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 256 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, |
228 _OutputIterator __r); | 257 _OutputIterator __r); |
229 | 258 |
230 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 259 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, |
231 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 260 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> |
232 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 261 _LIBCPP_HIDE_FROM_ABI __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> |
233 copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 262 copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, |
234 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 263 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, |
235 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); | 264 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); |
236 | 265 |
237 template <class _RAIter, | 266 template <class _RAIter, |
238 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 267 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> |
239 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 268 _LIBCPP_HIDE_FROM_ABI __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> |
240 move(_RAIter __f, | 269 move(_RAIter __f, |
241 _RAIter __l, | 270 _RAIter __l, |
242 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, | 271 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, |
243 typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type* = 0); | 272 typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type* = 0); |
244 | 273 |
245 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 274 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, |
246 class _OutputIterator> | 275 class _OutputIterator> |
247 _OutputIterator | 276 _LIBCPP_HIDE_FROM_ABI _OutputIterator |
248 move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 277 move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, |
249 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 278 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, |
250 _OutputIterator __r); | 279 _OutputIterator __r); |
251 | 280 |
252 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 281 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, |
253 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 282 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> |
254 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 283 _LIBCPP_HIDE_FROM_ABI __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> |
255 move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 284 move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, |
256 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 285 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, |
257 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); | 286 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); |
258 | 287 |
259 template <class _RAIter, | 288 template <class _RAIter, |
260 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 289 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> |
261 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 290 _LIBCPP_HIDE_FROM_ABI __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> |
262 move_backward(_RAIter __f, | 291 move_backward(_RAIter __f, |
263 _RAIter __l, | 292 _RAIter __l, |
264 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, | 293 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, |
265 typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type* = 0); | 294 typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type* = 0); |
266 | 295 |
267 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 296 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, |
268 class _OutputIterator> | 297 class _OutputIterator> |
269 _OutputIterator | 298 _LIBCPP_HIDE_FROM_ABI _OutputIterator |
270 move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 299 move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, |
271 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 300 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, |
272 _OutputIterator __r); | 301 _OutputIterator __r); |
273 | 302 |
274 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 303 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, |
275 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 304 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> |
276 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 305 _LIBCPP_HIDE_FROM_ABI __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> |
277 move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 306 move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, |
278 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 307 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, |
279 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); | 308 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); |
280 | 309 |
281 template <class _ValueType, class _DiffType> | 310 template <class _ValueType, class _DiffType> |
307 public: | 336 public: |
308 typedef _ValueType value_type; | 337 typedef _ValueType value_type; |
309 typedef random_access_iterator_tag iterator_category; | 338 typedef random_access_iterator_tag iterator_category; |
310 typedef _Reference reference; | 339 typedef _Reference reference; |
311 | 340 |
312 _LIBCPP_INLINE_VISIBILITY __deque_iterator() _NOEXCEPT | 341 _LIBCPP_HIDE_FROM_ABI __deque_iterator() _NOEXCEPT |
313 #if _LIBCPP_STD_VER > 11 | 342 #if _LIBCPP_STD_VER > 11 |
314 : __m_iter_(nullptr), __ptr_(nullptr) | 343 : __m_iter_(nullptr), __ptr_(nullptr) |
315 #endif | 344 #endif |
316 {} | 345 {} |
317 | 346 |
318 template <class _Pp, class _Rp, class _MP> | 347 template <class _Pp, class _Rp, class _MP> |
319 _LIBCPP_INLINE_VISIBILITY | 348 _LIBCPP_HIDE_FROM_ABI |
320 __deque_iterator(const __deque_iterator<value_type, _Pp, _Rp, _MP, difference_type, _BS>& __it, | 349 __deque_iterator(const __deque_iterator<value_type, _Pp, _Rp, _MP, difference_type, _BS>& __it, |
321 typename enable_if<is_convertible<_Pp, pointer>::value>::type* = 0) _NOEXCEPT | 350 typename enable_if<is_convertible<_Pp, pointer>::value>::type* = 0) _NOEXCEPT |
322 : __m_iter_(__it.__m_iter_), __ptr_(__it.__ptr_) {} | 351 : __m_iter_(__it.__m_iter_), __ptr_(__it.__ptr_) {} |
323 | 352 |
324 _LIBCPP_INLINE_VISIBILITY reference operator*() const {return *__ptr_;} | 353 _LIBCPP_HIDE_FROM_ABI reference operator*() const {return *__ptr_;} |
325 _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return __ptr_;} | 354 _LIBCPP_HIDE_FROM_ABI pointer operator->() const {return __ptr_;} |
326 | 355 |
327 _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator++() | 356 _LIBCPP_HIDE_FROM_ABI __deque_iterator& operator++() |
328 { | 357 { |
329 if (++__ptr_ - *__m_iter_ == __block_size) | 358 if (++__ptr_ - *__m_iter_ == __block_size) |
330 { | 359 { |
331 ++__m_iter_; | 360 ++__m_iter_; |
332 __ptr_ = *__m_iter_; | 361 __ptr_ = *__m_iter_; |
333 } | 362 } |
334 return *this; | 363 return *this; |
335 } | 364 } |
336 | 365 |
337 _LIBCPP_INLINE_VISIBILITY __deque_iterator operator++(int) | 366 _LIBCPP_HIDE_FROM_ABI __deque_iterator operator++(int) |
338 { | 367 { |
339 __deque_iterator __tmp = *this; | 368 __deque_iterator __tmp = *this; |
340 ++(*this); | 369 ++(*this); |
341 return __tmp; | 370 return __tmp; |
342 } | 371 } |
343 | 372 |
344 _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator--() | 373 _LIBCPP_HIDE_FROM_ABI __deque_iterator& operator--() |
345 { | 374 { |
346 if (__ptr_ == *__m_iter_) | 375 if (__ptr_ == *__m_iter_) |
347 { | 376 { |
348 --__m_iter_; | 377 --__m_iter_; |
349 __ptr_ = *__m_iter_ + __block_size; | 378 __ptr_ = *__m_iter_ + __block_size; |
350 } | 379 } |
351 --__ptr_; | 380 --__ptr_; |
352 return *this; | 381 return *this; |
353 } | 382 } |
354 | 383 |
355 _LIBCPP_INLINE_VISIBILITY __deque_iterator operator--(int) | 384 _LIBCPP_HIDE_FROM_ABI __deque_iterator operator--(int) |
356 { | 385 { |
357 __deque_iterator __tmp = *this; | 386 __deque_iterator __tmp = *this; |
358 --(*this); | 387 --(*this); |
359 return __tmp; | 388 return __tmp; |
360 } | 389 } |
361 | 390 |
362 _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator+=(difference_type __n) | 391 _LIBCPP_HIDE_FROM_ABI __deque_iterator& operator+=(difference_type __n) |
363 { | 392 { |
364 if (__n != 0) | 393 if (__n != 0) |
365 { | 394 { |
366 __n += __ptr_ - *__m_iter_; | 395 __n += __ptr_ - *__m_iter_; |
367 if (__n > 0) | 396 if (__n > 0) |
377 } | 406 } |
378 } | 407 } |
379 return *this; | 408 return *this; |
380 } | 409 } |
381 | 410 |
382 _LIBCPP_INLINE_VISIBILITY __deque_iterator& operator-=(difference_type __n) | 411 _LIBCPP_HIDE_FROM_ABI __deque_iterator& operator-=(difference_type __n) |
383 { | 412 { |
384 return *this += -__n; | 413 return *this += -__n; |
385 } | 414 } |
386 | 415 |
387 _LIBCPP_INLINE_VISIBILITY __deque_iterator operator+(difference_type __n) const | 416 _LIBCPP_HIDE_FROM_ABI __deque_iterator operator+(difference_type __n) const |
388 { | 417 { |
389 __deque_iterator __t(*this); | 418 __deque_iterator __t(*this); |
390 __t += __n; | 419 __t += __n; |
391 return __t; | 420 return __t; |
392 } | 421 } |
393 | 422 |
394 _LIBCPP_INLINE_VISIBILITY __deque_iterator operator-(difference_type __n) const | 423 _LIBCPP_HIDE_FROM_ABI __deque_iterator operator-(difference_type __n) const |
395 { | 424 { |
396 __deque_iterator __t(*this); | 425 __deque_iterator __t(*this); |
397 __t -= __n; | 426 __t -= __n; |
398 return __t; | 427 return __t; |
399 } | 428 } |
400 | 429 |
401 _LIBCPP_INLINE_VISIBILITY | 430 _LIBCPP_HIDE_FROM_ABI |
402 friend __deque_iterator operator+(difference_type __n, const __deque_iterator& __it) | 431 friend __deque_iterator operator+(difference_type __n, const __deque_iterator& __it) |
403 {return __it + __n;} | 432 {return __it + __n;} |
404 | 433 |
405 _LIBCPP_INLINE_VISIBILITY | 434 _LIBCPP_HIDE_FROM_ABI |
406 friend difference_type operator-(const __deque_iterator& __x, const __deque_iterator& __y) | 435 friend difference_type operator-(const __deque_iterator& __x, const __deque_iterator& __y) |
407 { | 436 { |
408 if (__x != __y) | 437 if (__x != __y) |
409 return (__x.__m_iter_ - __y.__m_iter_) * __block_size | 438 return (__x.__m_iter_ - __y.__m_iter_) * __block_size |
410 + (__x.__ptr_ - *__x.__m_iter_) | 439 + (__x.__ptr_ - *__x.__m_iter_) |
411 - (__y.__ptr_ - *__y.__m_iter_); | 440 - (__y.__ptr_ - *__y.__m_iter_); |
412 return 0; | 441 return 0; |
413 } | 442 } |
414 | 443 |
415 _LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const | 444 _LIBCPP_HIDE_FROM_ABI reference operator[](difference_type __n) const |
416 {return *(*this + __n);} | 445 {return *(*this + __n);} |
417 | 446 |
418 _LIBCPP_INLINE_VISIBILITY friend | 447 _LIBCPP_HIDE_FROM_ABI friend |
419 bool operator==(const __deque_iterator& __x, const __deque_iterator& __y) | 448 bool operator==(const __deque_iterator& __x, const __deque_iterator& __y) |
420 {return __x.__ptr_ == __y.__ptr_;} | 449 {return __x.__ptr_ == __y.__ptr_;} |
421 | 450 |
422 _LIBCPP_INLINE_VISIBILITY friend | 451 _LIBCPP_HIDE_FROM_ABI friend |
423 bool operator!=(const __deque_iterator& __x, const __deque_iterator& __y) | 452 bool operator!=(const __deque_iterator& __x, const __deque_iterator& __y) |
424 {return !(__x == __y);} | 453 {return !(__x == __y);} |
425 | 454 |
426 _LIBCPP_INLINE_VISIBILITY friend | 455 _LIBCPP_HIDE_FROM_ABI friend |
427 bool operator<(const __deque_iterator& __x, const __deque_iterator& __y) | 456 bool operator<(const __deque_iterator& __x, const __deque_iterator& __y) |
428 {return __x.__m_iter_ < __y.__m_iter_ || | 457 {return __x.__m_iter_ < __y.__m_iter_ || |
429 (__x.__m_iter_ == __y.__m_iter_ && __x.__ptr_ < __y.__ptr_);} | 458 (__x.__m_iter_ == __y.__m_iter_ && __x.__ptr_ < __y.__ptr_);} |
430 | 459 |
431 _LIBCPP_INLINE_VISIBILITY friend | 460 _LIBCPP_HIDE_FROM_ABI friend |
432 bool operator>(const __deque_iterator& __x, const __deque_iterator& __y) | 461 bool operator>(const __deque_iterator& __x, const __deque_iterator& __y) |
433 {return __y < __x;} | 462 {return __y < __x;} |
434 | 463 |
435 _LIBCPP_INLINE_VISIBILITY friend | 464 _LIBCPP_HIDE_FROM_ABI friend |
436 bool operator<=(const __deque_iterator& __x, const __deque_iterator& __y) | 465 bool operator<=(const __deque_iterator& __x, const __deque_iterator& __y) |
437 {return !(__y < __x);} | 466 {return !(__y < __x);} |
438 | 467 |
439 _LIBCPP_INLINE_VISIBILITY friend | 468 _LIBCPP_HIDE_FROM_ABI friend |
440 bool operator>=(const __deque_iterator& __x, const __deque_iterator& __y) | 469 bool operator>=(const __deque_iterator& __x, const __deque_iterator& __y) |
441 {return !(__x < __y);} | 470 {return !(__x < __y);} |
442 | 471 |
443 private: | 472 private: |
444 _LIBCPP_INLINE_VISIBILITY __deque_iterator(__map_iterator __m, pointer __p) _NOEXCEPT | 473 _LIBCPP_HIDE_FROM_ABI explicit __deque_iterator(__map_iterator __m, pointer __p) _NOEXCEPT |
445 : __m_iter_(__m), __ptr_(__p) {} | 474 : __m_iter_(__m), __ptr_(__p) {} |
446 | 475 |
447 template <class _Tp, class _Ap> friend class __deque_base; | |
448 template <class _Tp, class _Ap> friend class _LIBCPP_TEMPLATE_VIS deque; | 476 template <class _Tp, class _Ap> friend class _LIBCPP_TEMPLATE_VIS deque; |
449 template <class _Vp, class _Pp, class _Rp, class _MP, class _Dp, _Dp> | 477 template <class _Vp, class _Pp, class _Rp, class _MP, class _Dp, _Dp> |
450 friend class _LIBCPP_TEMPLATE_VIS __deque_iterator; | 478 friend class _LIBCPP_TEMPLATE_VIS __deque_iterator; |
451 | 479 |
452 template <class _RAIter, | 480 template <class _RAIter, |
558 | 586 |
559 // copy | 587 // copy |
560 | 588 |
561 template <class _RAIter, | 589 template <class _RAIter, |
562 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 590 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> |
563 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 591 _LIBCPP_HIDE_FROM_ABI __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> |
564 copy(_RAIter __f, | 592 copy(_RAIter __f, |
565 _RAIter __l, | 593 _RAIter __l, |
566 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, | 594 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, |
567 typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type*) | 595 typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type*) |
568 { | 596 { |
588 return __r; | 616 return __r; |
589 } | 617 } |
590 | 618 |
591 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 619 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, |
592 class _OutputIterator> | 620 class _OutputIterator> |
593 _OutputIterator | 621 _LIBCPP_HIDE_FROM_ABI _OutputIterator |
594 copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 622 copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, |
595 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 623 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, |
596 _OutputIterator __r) | 624 _OutputIterator __r) |
597 { | 625 { |
598 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; | 626 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; |
616 return __r; | 644 return __r; |
617 } | 645 } |
618 | 646 |
619 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 647 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, |
620 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 648 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> |
621 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 649 _LIBCPP_HIDE_FROM_ABI __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> |
622 copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 650 copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, |
623 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 651 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, |
624 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) | 652 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) |
625 { | 653 { |
626 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; | 654 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; |
646 | 674 |
647 // copy_backward | 675 // copy_backward |
648 | 676 |
649 template <class _RAIter, | 677 template <class _RAIter, |
650 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 678 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> |
651 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 679 _LIBCPP_HIDE_FROM_ABI __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> |
652 copy_backward(_RAIter __f, | 680 copy_backward(_RAIter __f, |
653 _RAIter __l, | 681 _RAIter __l, |
654 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, | 682 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, |
655 typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type*) | 683 typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type*) |
656 { | 684 { |
676 return __r; | 704 return __r; |
677 } | 705 } |
678 | 706 |
679 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 707 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, |
680 class _OutputIterator> | 708 class _OutputIterator> |
681 _OutputIterator | 709 _LIBCPP_HIDE_FROM_ABI _OutputIterator |
682 copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 710 copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, |
683 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 711 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, |
684 _OutputIterator __r) | 712 _OutputIterator __r) |
685 { | 713 { |
686 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; | 714 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; |
704 return __r; | 732 return __r; |
705 } | 733 } |
706 | 734 |
707 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 735 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, |
708 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 736 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> |
709 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 737 _LIBCPP_HIDE_FROM_ABI __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> |
710 copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 738 copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, |
711 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 739 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, |
712 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) | 740 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) |
713 { | 741 { |
714 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; | 742 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; |
734 | 762 |
735 // move | 763 // move |
736 | 764 |
737 template <class _RAIter, | 765 template <class _RAIter, |
738 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 766 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> |
739 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 767 _LIBCPP_HIDE_FROM_ABI __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> |
740 move(_RAIter __f, | 768 move(_RAIter __f, |
741 _RAIter __l, | 769 _RAIter __l, |
742 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, | 770 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, |
743 typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type*) | 771 typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type*) |
744 { | 772 { |
764 return __r; | 792 return __r; |
765 } | 793 } |
766 | 794 |
767 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 795 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, |
768 class _OutputIterator> | 796 class _OutputIterator> |
769 _OutputIterator | 797 _LIBCPP_HIDE_FROM_ABI _OutputIterator |
770 move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 798 move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, |
771 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 799 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, |
772 _OutputIterator __r) | 800 _OutputIterator __r) |
773 { | 801 { |
774 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; | 802 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; |
792 return __r; | 820 return __r; |
793 } | 821 } |
794 | 822 |
795 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 823 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, |
796 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 824 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> |
797 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 825 _LIBCPP_HIDE_FROM_ABI __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> |
798 move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 826 move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, |
799 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 827 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, |
800 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) | 828 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) |
801 { | 829 { |
802 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; | 830 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; |
822 | 850 |
823 // move_backward | 851 // move_backward |
824 | 852 |
825 template <class _RAIter, | 853 template <class _RAIter, |
826 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 854 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> |
827 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 855 _LIBCPP_HIDE_FROM_ABI __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> |
828 move_backward(_RAIter __f, | 856 move_backward(_RAIter __f, |
829 _RAIter __l, | 857 _RAIter __l, |
830 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, | 858 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r, |
831 typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type*) | 859 typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type*) |
832 { | 860 { |
852 return __r; | 880 return __r; |
853 } | 881 } |
854 | 882 |
855 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 883 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, |
856 class _OutputIterator> | 884 class _OutputIterator> |
857 _OutputIterator | 885 _LIBCPP_HIDE_FROM_ABI _OutputIterator |
858 move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 886 move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, |
859 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 887 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, |
860 _OutputIterator __r) | 888 _OutputIterator __r) |
861 { | 889 { |
862 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; | 890 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; |
880 return __r; | 908 return __r; |
881 } | 909 } |
882 | 910 |
883 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, | 911 template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1, |
884 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> | 912 class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2> |
885 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> | 913 _LIBCPP_HIDE_FROM_ABI __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> |
886 move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, | 914 move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, |
887 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, | 915 __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, |
888 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) | 916 __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r) |
889 { | 917 { |
890 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; | 918 typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; |
906 __l -= __bs - 1; | 934 __l -= __bs - 1; |
907 } | 935 } |
908 return __r; | 936 return __r; |
909 } | 937 } |
910 | 938 |
911 template <bool> | |
912 class __deque_base_common | |
913 { | |
914 protected: | |
915 _LIBCPP_NORETURN void __throw_length_error() const; | |
916 _LIBCPP_NORETURN void __throw_out_of_range() const; | |
917 }; | |
918 | |
919 template <bool __b> | |
920 void | |
921 __deque_base_common<__b>::__throw_length_error() const | |
922 { | |
923 _VSTD::__throw_length_error("deque"); | |
924 } | |
925 | |
926 template <bool __b> | |
927 void | |
928 __deque_base_common<__b>::__throw_out_of_range() const | |
929 { | |
930 _VSTD::__throw_out_of_range("deque"); | |
931 } | |
932 | |
933 template <class _Tp, class _Allocator> | |
934 class __deque_base | |
935 : protected __deque_base_common<true> | |
936 { | |
937 __deque_base(const __deque_base& __c); | |
938 __deque_base& operator=(const __deque_base& __c); | |
939 public: | |
940 typedef _Allocator allocator_type; | |
941 typedef allocator_traits<allocator_type> __alloc_traits; | |
942 typedef typename __alloc_traits::size_type size_type; | |
943 | |
944 typedef _Tp value_type; | |
945 typedef value_type& reference; | |
946 typedef const value_type& const_reference; | |
947 typedef typename __alloc_traits::difference_type difference_type; | |
948 typedef typename __alloc_traits::pointer pointer; | |
949 typedef typename __alloc_traits::const_pointer const_pointer; | |
950 | |
951 static const difference_type __block_size; | |
952 | |
953 typedef typename __rebind_alloc_helper<__alloc_traits, pointer>::type __pointer_allocator; | |
954 typedef allocator_traits<__pointer_allocator> __map_traits; | |
955 typedef typename __map_traits::pointer __map_pointer; | |
956 typedef typename __rebind_alloc_helper<__alloc_traits, const_pointer>::type __const_pointer_allocator; | |
957 typedef typename allocator_traits<__const_pointer_allocator>::const_pointer __map_const_pointer; | |
958 typedef __split_buffer<pointer, __pointer_allocator> __map; | |
959 | |
960 typedef __deque_iterator<value_type, pointer, reference, __map_pointer, | |
961 difference_type> iterator; | |
962 typedef __deque_iterator<value_type, const_pointer, const_reference, __map_const_pointer, | |
963 difference_type> const_iterator; | |
964 | |
965 struct __deque_block_range { | |
966 explicit __deque_block_range(pointer __b, pointer __e) _NOEXCEPT : __begin_(__b), __end_(__e) {} | |
967 const pointer __begin_; | |
968 const pointer __end_; | |
969 }; | |
970 | |
971 struct __deque_range { | |
972 iterator __pos_; | |
973 const iterator __end_; | |
974 | |
975 __deque_range(iterator __pos, iterator __e) _NOEXCEPT | |
976 : __pos_(__pos), __end_(__e) {} | |
977 | |
978 explicit operator bool() const _NOEXCEPT { | |
979 return __pos_ != __end_; | |
980 } | |
981 | |
982 __deque_range begin() const { | |
983 return *this; | |
984 } | |
985 | |
986 __deque_range end() const { | |
987 return __deque_range(__end_, __end_); | |
988 } | |
989 __deque_block_range operator*() const _NOEXCEPT { | |
990 if (__pos_.__m_iter_ == __end_.__m_iter_) { | |
991 return __deque_block_range(__pos_.__ptr_, __end_.__ptr_); | |
992 } | |
993 return __deque_block_range(__pos_.__ptr_, *__pos_.__m_iter_ + __block_size); | |
994 } | |
995 | |
996 __deque_range& operator++() _NOEXCEPT { | |
997 if (__pos_.__m_iter_ == __end_.__m_iter_) { | |
998 __pos_ = __end_; | |
999 } else { | |
1000 ++__pos_.__m_iter_; | |
1001 __pos_.__ptr_ = *__pos_.__m_iter_; | |
1002 } | |
1003 return *this; | |
1004 } | |
1005 | |
1006 | |
1007 friend bool operator==(__deque_range const& __lhs, __deque_range const& __rhs) { | |
1008 return __lhs.__pos_ == __rhs.__pos_; | |
1009 } | |
1010 friend bool operator!=(__deque_range const& __lhs, __deque_range const& __rhs) { | |
1011 return !(__lhs == __rhs); | |
1012 } | |
1013 }; | |
1014 | |
1015 | |
1016 | |
1017 struct _ConstructTransaction { | |
1018 _ConstructTransaction(__deque_base* __db, __deque_block_range& __r) | |
1019 : __pos_(__r.__begin_), __end_(__r.__end_), __begin_(__r.__begin_), __base_(__db) {} | |
1020 | |
1021 | |
1022 ~_ConstructTransaction() { | |
1023 __base_->size() += (__pos_ - __begin_); | |
1024 } | |
1025 | |
1026 pointer __pos_; | |
1027 const pointer __end_; | |
1028 private: | |
1029 const pointer __begin_; | |
1030 __deque_base * const __base_; | |
1031 }; | |
1032 | |
1033 protected: | |
1034 __map __map_; | |
1035 size_type __start_; | |
1036 __compressed_pair<size_type, allocator_type> __size_; | |
1037 | |
1038 iterator begin() _NOEXCEPT; | |
1039 const_iterator begin() const _NOEXCEPT; | |
1040 iterator end() _NOEXCEPT; | |
1041 const_iterator end() const _NOEXCEPT; | |
1042 | |
1043 _LIBCPP_INLINE_VISIBILITY size_type& size() {return __size_.first();} | |
1044 _LIBCPP_INLINE_VISIBILITY | |
1045 const size_type& size() const _NOEXCEPT {return __size_.first();} | |
1046 _LIBCPP_INLINE_VISIBILITY allocator_type& __alloc() {return __size_.second();} | |
1047 _LIBCPP_INLINE_VISIBILITY | |
1048 const allocator_type& __alloc() const _NOEXCEPT {return __size_.second();} | |
1049 | |
1050 _LIBCPP_INLINE_VISIBILITY | |
1051 __deque_base() | |
1052 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value); | |
1053 _LIBCPP_INLINE_VISIBILITY | |
1054 explicit __deque_base(const allocator_type& __a); | |
1055 public: | |
1056 ~__deque_base(); | |
1057 | |
1058 #ifndef _LIBCPP_CXX03_LANG | |
1059 __deque_base(__deque_base&& __c) | |
1060 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); | |
1061 __deque_base(__deque_base&& __c, const allocator_type& __a); | |
1062 #endif // _LIBCPP_CXX03_LANG | |
1063 | |
1064 void swap(__deque_base& __c) | |
1065 #if _LIBCPP_STD_VER >= 14 | |
1066 _NOEXCEPT; | |
1067 #else | |
1068 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || | |
1069 __is_nothrow_swappable<allocator_type>::value); | |
1070 #endif | |
1071 protected: | |
1072 void clear() _NOEXCEPT; | |
1073 | |
1074 bool __invariants() const; | |
1075 | |
1076 _LIBCPP_INLINE_VISIBILITY | |
1077 void __move_assign(__deque_base& __c) | |
1078 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value && | |
1079 is_nothrow_move_assignable<allocator_type>::value) | |
1080 { | |
1081 __map_ = _VSTD::move(__c.__map_); | |
1082 __start_ = __c.__start_; | |
1083 size() = __c.size(); | |
1084 __move_assign_alloc(__c); | |
1085 __c.__start_ = __c.size() = 0; | |
1086 } | |
1087 | |
1088 _LIBCPP_INLINE_VISIBILITY | |
1089 void __move_assign_alloc(__deque_base& __c) | |
1090 _NOEXCEPT_(!__alloc_traits::propagate_on_container_move_assignment::value || | |
1091 is_nothrow_move_assignable<allocator_type>::value) | |
1092 {__move_assign_alloc(__c, integral_constant<bool, | |
1093 __alloc_traits::propagate_on_container_move_assignment::value>());} | |
1094 | |
1095 private: | |
1096 _LIBCPP_INLINE_VISIBILITY | |
1097 void __move_assign_alloc(__deque_base& __c, true_type) | |
1098 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) | |
1099 { | |
1100 __alloc() = _VSTD::move(__c.__alloc()); | |
1101 } | |
1102 | |
1103 _LIBCPP_INLINE_VISIBILITY | |
1104 void __move_assign_alloc(__deque_base&, false_type) _NOEXCEPT | |
1105 {} | |
1106 }; | |
1107 | |
1108 template <class _Tp, class _Allocator> | |
1109 const typename __deque_base<_Tp, _Allocator>::difference_type | |
1110 __deque_base<_Tp, _Allocator>::__block_size = | |
1111 __deque_block_size<value_type, difference_type>::value; | |
1112 | |
1113 template <class _Tp, class _Allocator> | |
1114 bool | |
1115 __deque_base<_Tp, _Allocator>::__invariants() const | |
1116 { | |
1117 if (!__map_.__invariants()) | |
1118 return false; | |
1119 if (__map_.size() >= size_type(-1) / __block_size) | |
1120 return false; | |
1121 for (typename __map::const_iterator __i = __map_.begin(), __e = __map_.end(); | |
1122 __i != __e; ++__i) | |
1123 if (*__i == nullptr) | |
1124 return false; | |
1125 if (__map_.size() != 0) | |
1126 { | |
1127 if (size() >= __map_.size() * __block_size) | |
1128 return false; | |
1129 if (__start_ >= __map_.size() * __block_size - size()) | |
1130 return false; | |
1131 } | |
1132 else | |
1133 { | |
1134 if (size() != 0) | |
1135 return false; | |
1136 if (__start_ != 0) | |
1137 return false; | |
1138 } | |
1139 return true; | |
1140 } | |
1141 | |
1142 template <class _Tp, class _Allocator> | |
1143 typename __deque_base<_Tp, _Allocator>::iterator | |
1144 __deque_base<_Tp, _Allocator>::begin() _NOEXCEPT | |
1145 { | |
1146 __map_pointer __mp = __map_.begin() + __start_ / __block_size; | |
1147 return iterator(__mp, __map_.empty() ? 0 : *__mp + __start_ % __block_size); | |
1148 } | |
1149 | |
1150 template <class _Tp, class _Allocator> | |
1151 typename __deque_base<_Tp, _Allocator>::const_iterator | |
1152 __deque_base<_Tp, _Allocator>::begin() const _NOEXCEPT | |
1153 { | |
1154 __map_const_pointer __mp = static_cast<__map_const_pointer>(__map_.begin() + __start_ / __block_size); | |
1155 return const_iterator(__mp, __map_.empty() ? 0 : *__mp + __start_ % __block_size); | |
1156 } | |
1157 | |
1158 template <class _Tp, class _Allocator> | |
1159 typename __deque_base<_Tp, _Allocator>::iterator | |
1160 __deque_base<_Tp, _Allocator>::end() _NOEXCEPT | |
1161 { | |
1162 size_type __p = size() + __start_; | |
1163 __map_pointer __mp = __map_.begin() + __p / __block_size; | |
1164 return iterator(__mp, __map_.empty() ? 0 : *__mp + __p % __block_size); | |
1165 } | |
1166 | |
1167 template <class _Tp, class _Allocator> | |
1168 typename __deque_base<_Tp, _Allocator>::const_iterator | |
1169 __deque_base<_Tp, _Allocator>::end() const _NOEXCEPT | |
1170 { | |
1171 size_type __p = size() + __start_; | |
1172 __map_const_pointer __mp = static_cast<__map_const_pointer>(__map_.begin() + __p / __block_size); | |
1173 return const_iterator(__mp, __map_.empty() ? 0 : *__mp + __p % __block_size); | |
1174 } | |
1175 | |
1176 template <class _Tp, class _Allocator> | |
1177 inline | |
1178 __deque_base<_Tp, _Allocator>::__deque_base() | |
1179 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) | |
1180 : __start_(0), __size_(0, __default_init_tag()) {} | |
1181 | |
1182 template <class _Tp, class _Allocator> | |
1183 inline | |
1184 __deque_base<_Tp, _Allocator>::__deque_base(const allocator_type& __a) | |
1185 : __map_(__pointer_allocator(__a)), __start_(0), __size_(0, __a) {} | |
1186 | |
1187 template <class _Tp, class _Allocator> | |
1188 __deque_base<_Tp, _Allocator>::~__deque_base() | |
1189 { | |
1190 clear(); | |
1191 typename __map::iterator __i = __map_.begin(); | |
1192 typename __map::iterator __e = __map_.end(); | |
1193 for (; __i != __e; ++__i) | |
1194 __alloc_traits::deallocate(__alloc(), *__i, __block_size); | |
1195 } | |
1196 | |
1197 #ifndef _LIBCPP_CXX03_LANG | |
1198 | |
1199 template <class _Tp, class _Allocator> | |
1200 __deque_base<_Tp, _Allocator>::__deque_base(__deque_base&& __c) | |
1201 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) | |
1202 : __map_(_VSTD::move(__c.__map_)), | |
1203 __start_(_VSTD::move(__c.__start_)), | |
1204 __size_(_VSTD::move(__c.__size_)) | |
1205 { | |
1206 __c.__start_ = 0; | |
1207 __c.size() = 0; | |
1208 } | |
1209 | |
1210 template <class _Tp, class _Allocator> | |
1211 __deque_base<_Tp, _Allocator>::__deque_base(__deque_base&& __c, const allocator_type& __a) | |
1212 : __map_(_VSTD::move(__c.__map_), __pointer_allocator(__a)), | |
1213 __start_(_VSTD::move(__c.__start_)), | |
1214 __size_(_VSTD::move(__c.size()), __a) | |
1215 { | |
1216 if (__a == __c.__alloc()) | |
1217 { | |
1218 __c.__start_ = 0; | |
1219 __c.size() = 0; | |
1220 } | |
1221 else | |
1222 { | |
1223 __map_.clear(); | |
1224 __start_ = 0; | |
1225 size() = 0; | |
1226 } | |
1227 } | |
1228 | |
1229 #endif // _LIBCPP_CXX03_LANG | |
1230 | |
1231 template <class _Tp, class _Allocator> | |
1232 void | |
1233 __deque_base<_Tp, _Allocator>::swap(__deque_base& __c) | |
1234 #if _LIBCPP_STD_VER >= 14 | |
1235 _NOEXCEPT | |
1236 #else | |
1237 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || | |
1238 __is_nothrow_swappable<allocator_type>::value) | |
1239 #endif | |
1240 { | |
1241 __map_.swap(__c.__map_); | |
1242 _VSTD::swap(__start_, __c.__start_); | |
1243 _VSTD::swap(size(), __c.size()); | |
1244 _VSTD::__swap_allocator(__alloc(), __c.__alloc()); | |
1245 } | |
1246 | |
1247 template <class _Tp, class _Allocator> | |
1248 void | |
1249 __deque_base<_Tp, _Allocator>::clear() _NOEXCEPT | |
1250 { | |
1251 allocator_type& __a = __alloc(); | |
1252 for (iterator __i = begin(), __e = end(); __i != __e; ++__i) | |
1253 __alloc_traits::destroy(__a, _VSTD::addressof(*__i)); | |
1254 size() = 0; | |
1255 while (__map_.size() > 2) | |
1256 { | |
1257 __alloc_traits::deallocate(__a, __map_.front(), __block_size); | |
1258 __map_.pop_front(); | |
1259 } | |
1260 switch (__map_.size()) | |
1261 { | |
1262 case 1: | |
1263 __start_ = __block_size / 2; | |
1264 break; | |
1265 case 2: | |
1266 __start_ = __block_size; | |
1267 break; | |
1268 } | |
1269 } | |
1270 | |
1271 template <class _Tp, class _Allocator /*= allocator<_Tp>*/> | 939 template <class _Tp, class _Allocator /*= allocator<_Tp>*/> |
1272 class _LIBCPP_TEMPLATE_VIS deque | 940 class _LIBCPP_TEMPLATE_VIS deque |
1273 : private __deque_base<_Tp, _Allocator> | |
1274 { | 941 { |
1275 public: | 942 public: |
1276 // types: | 943 // types: |
1277 | 944 |
1278 typedef _Tp value_type; | 945 using value_type = _Tp; |
1279 typedef _Allocator allocator_type; | 946 |
1280 | 947 static_assert((is_same<typename _Allocator::value_type, value_type>::value), |
1281 static_assert((is_same<typename allocator_type::value_type, value_type>::value), | 948 "Allocator::value_type must be same type as value_type"); |
1282 "Allocator::value_type must be same type as value_type"); | 949 |
1283 | 950 using allocator_type = _Allocator; |
1284 typedef __deque_base<value_type, allocator_type> __base; | 951 using __alloc_traits = allocator_traits<allocator_type>; |
1285 | 952 |
1286 typedef typename __base::__alloc_traits __alloc_traits; | 953 using size_type = typename __alloc_traits::size_type; |
1287 typedef typename __base::reference reference; | 954 using difference_type = typename __alloc_traits::difference_type; |
1288 typedef typename __base::const_reference const_reference; | 955 |
1289 typedef typename __base::iterator iterator; | 956 using pointer = typename __alloc_traits::pointer; |
1290 typedef typename __base::const_iterator const_iterator; | 957 using const_pointer = typename __alloc_traits::const_pointer; |
1291 typedef typename __base::size_type size_type; | 958 |
1292 typedef typename __base::difference_type difference_type; | 959 using __pointer_allocator = __rebind_alloc<__alloc_traits, pointer>; |
1293 | 960 using __const_pointer_allocator = __rebind_alloc<__alloc_traits, const_pointer>; |
1294 typedef typename __base::pointer pointer; | 961 using __map = __split_buffer<pointer, __pointer_allocator>; |
1295 typedef typename __base::const_pointer const_pointer; | 962 using __map_alloc_traits = allocator_traits<__pointer_allocator>; |
1296 typedef _VSTD::reverse_iterator<iterator> reverse_iterator; | 963 using __map_pointer = typename __map_alloc_traits::pointer; |
1297 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; | 964 using __map_const_pointer = typename allocator_traits<__const_pointer_allocator>::const_pointer; |
1298 | 965 |
1299 using typename __base::__deque_range; | 966 using reference = value_type&; |
1300 using typename __base::__deque_block_range; | 967 using const_reference = const value_type&; |
1301 using typename __base::_ConstructTransaction; | 968 |
969 using iterator = __deque_iterator<value_type, pointer, reference, __map_pointer, difference_type>; | |
970 using const_iterator = | |
971 __deque_iterator<value_type, const_pointer, const_reference, __map_const_pointer, difference_type>; | |
972 using reverse_iterator = std::reverse_iterator<iterator>; | |
973 using const_reverse_iterator = std::reverse_iterator<const_iterator>; | |
974 | |
975 static_assert(is_same<allocator_type, __rebind_alloc<__alloc_traits, value_type> >::value, | |
976 "[allocator.requirements] states that rebinding an allocator to the same type should result in the " | |
977 "original allocator"); | |
978 static_assert(is_nothrow_default_constructible<allocator_type>::value == | |
979 is_nothrow_default_constructible<__pointer_allocator>::value, | |
980 "rebinding an allocator should not change excpetion guarantees"); | |
981 static_assert(is_nothrow_move_constructible<allocator_type>::value == | |
982 is_nothrow_move_constructible<typename __map::allocator_type>::value, | |
983 "rebinding an allocator should not change excpetion guarantees"); | |
984 | |
985 private: | |
986 struct __deque_block_range { | |
987 explicit _LIBCPP_HIDE_FROM_ABI | |
988 __deque_block_range(pointer __b, pointer __e) _NOEXCEPT : __begin_(__b), __end_(__e) {} | |
989 const pointer __begin_; | |
990 const pointer __end_; | |
991 }; | |
992 | |
993 struct __deque_range { | |
994 iterator __pos_; | |
995 const iterator __end_; | |
996 | |
997 _LIBCPP_HIDE_FROM_ABI __deque_range(iterator __pos, iterator __e) _NOEXCEPT | |
998 : __pos_(__pos), __end_(__e) {} | |
999 | |
1000 explicit _LIBCPP_HIDE_FROM_ABI operator bool() const _NOEXCEPT { | |
1001 return __pos_ != __end_; | |
1002 } | |
1003 | |
1004 _LIBCPP_HIDE_FROM_ABI __deque_range begin() const { | |
1005 return *this; | |
1006 } | |
1007 | |
1008 _LIBCPP_HIDE_FROM_ABI __deque_range end() const { | |
1009 return __deque_range(__end_, __end_); | |
1010 } | |
1011 _LIBCPP_HIDE_FROM_ABI __deque_block_range operator*() const _NOEXCEPT { | |
1012 if (__pos_.__m_iter_ == __end_.__m_iter_) { | |
1013 return __deque_block_range(__pos_.__ptr_, __end_.__ptr_); | |
1014 } | |
1015 return __deque_block_range(__pos_.__ptr_, *__pos_.__m_iter_ + __block_size); | |
1016 } | |
1017 | |
1018 _LIBCPP_HIDE_FROM_ABI __deque_range& operator++() _NOEXCEPT { | |
1019 if (__pos_.__m_iter_ == __end_.__m_iter_) { | |
1020 __pos_ = __end_; | |
1021 } else { | |
1022 ++__pos_.__m_iter_; | |
1023 __pos_.__ptr_ = *__pos_.__m_iter_; | |
1024 } | |
1025 return *this; | |
1026 } | |
1027 | |
1028 | |
1029 _LIBCPP_HIDE_FROM_ABI friend bool operator==(__deque_range const& __lhs, __deque_range const& __rhs) { | |
1030 return __lhs.__pos_ == __rhs.__pos_; | |
1031 } | |
1032 _LIBCPP_HIDE_FROM_ABI friend bool operator!=(__deque_range const& __lhs, __deque_range const& __rhs) { | |
1033 return !(__lhs == __rhs); | |
1034 } | |
1035 }; | |
1036 | |
1037 struct _ConstructTransaction { | |
1038 _LIBCPP_HIDE_FROM_ABI _ConstructTransaction(deque* __db, __deque_block_range& __r) | |
1039 : __pos_(__r.__begin_), __end_(__r.__end_), __begin_(__r.__begin_), __base_(__db) {} | |
1040 | |
1041 | |
1042 _LIBCPP_HIDE_FROM_ABI ~_ConstructTransaction() { | |
1043 __base_->__size() += (__pos_ - __begin_); | |
1044 } | |
1045 | |
1046 pointer __pos_; | |
1047 const pointer __end_; | |
1048 private: | |
1049 const pointer __begin_; | |
1050 deque* const __base_; | |
1051 }; | |
1052 | |
1053 static const difference_type __block_size; | |
1054 | |
1055 __map __map_; | |
1056 size_type __start_; | |
1057 __compressed_pair<size_type, allocator_type> __size_; | |
1058 | |
1059 public: | |
1302 | 1060 |
1303 // construct/copy/destroy: | 1061 // construct/copy/destroy: |
1304 _LIBCPP_INLINE_VISIBILITY | 1062 _LIBCPP_HIDE_FROM_ABI |
1305 deque() | 1063 deque() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) |
1306 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) | 1064 : __start_(0), __size_(0, __default_init_tag()) {} |
1307 {} | 1065 |
1308 _LIBCPP_INLINE_VISIBILITY explicit deque(const allocator_type& __a) : __base(__a) {} | 1066 _LIBCPP_HIDE_FROM_ABI ~deque() { |
1309 explicit deque(size_type __n); | 1067 clear(); |
1068 typename __map::iterator __i = __map_.begin(); | |
1069 typename __map::iterator __e = __map_.end(); | |
1070 for (; __i != __e; ++__i) | |
1071 __alloc_traits::deallocate(__alloc(), *__i, __block_size); | |
1072 } | |
1073 | |
1074 _LIBCPP_HIDE_FROM_ABI explicit deque(const allocator_type& __a) | |
1075 : __map_(__pointer_allocator(__a)), __start_(0), __size_(0, __a) {} | |
1076 | |
1077 explicit _LIBCPP_HIDE_FROM_ABI deque(size_type __n); | |
1310 #if _LIBCPP_STD_VER > 11 | 1078 #if _LIBCPP_STD_VER > 11 |
1311 explicit deque(size_type __n, const _Allocator& __a); | 1079 explicit _LIBCPP_HIDE_FROM_ABI deque(size_type __n, const _Allocator& __a); |
1312 #endif | 1080 #endif |
1313 deque(size_type __n, const value_type& __v); | 1081 _LIBCPP_HIDE_FROM_ABI deque(size_type __n, const value_type& __v); |
1314 deque(size_type __n, const value_type& __v, const allocator_type& __a); | 1082 |
1083 template <class = __enable_if_t<__is_allocator<_Allocator>::value> > | |
1084 _LIBCPP_HIDE_FROM_ABI deque(size_type __n, const value_type& __v, const allocator_type& __a) | |
1085 : __map_(__pointer_allocator(__a)), __start_(0), __size_(0, __a) | |
1086 { | |
1087 if (__n > 0) | |
1088 __append(__n, __v); | |
1089 } | |
1090 | |
1315 template <class _InputIter> | 1091 template <class _InputIter> |
1316 deque(_InputIter __f, _InputIter __l, | 1092 _LIBCPP_HIDE_FROM_ABI deque(_InputIter __f, _InputIter __l, |
1317 typename enable_if<__is_cpp17_input_iterator<_InputIter>::value>::type* = 0); | 1093 typename enable_if<__is_cpp17_input_iterator<_InputIter>::value>::type* = 0); |
1318 template <class _InputIter> | 1094 template <class _InputIter> |
1319 deque(_InputIter __f, _InputIter __l, const allocator_type& __a, | 1095 _LIBCPP_HIDE_FROM_ABI deque(_InputIter __f, _InputIter __l, const allocator_type& __a, |
1320 typename enable_if<__is_cpp17_input_iterator<_InputIter>::value>::type* = 0); | 1096 typename enable_if<__is_cpp17_input_iterator<_InputIter>::value>::type* = 0); |
1321 deque(const deque& __c); | 1097 _LIBCPP_HIDE_FROM_ABI deque(const deque& __c); |
1322 deque(const deque& __c, const __identity_t<allocator_type>& __a); | 1098 _LIBCPP_HIDE_FROM_ABI deque(const deque& __c, const __type_identity_t<allocator_type>& __a); |
1323 | 1099 |
1324 deque& operator=(const deque& __c); | 1100 _LIBCPP_HIDE_FROM_ABI deque& operator=(const deque& __c); |
1325 | 1101 |
1326 #ifndef _LIBCPP_CXX03_LANG | 1102 #ifndef _LIBCPP_CXX03_LANG |
1327 deque(initializer_list<value_type> __il); | 1103 _LIBCPP_HIDE_FROM_ABI deque(initializer_list<value_type> __il); |
1328 deque(initializer_list<value_type> __il, const allocator_type& __a); | 1104 _LIBCPP_HIDE_FROM_ABI deque(initializer_list<value_type> __il, const allocator_type& __a); |
1329 | 1105 |
1330 _LIBCPP_INLINE_VISIBILITY | 1106 _LIBCPP_HIDE_FROM_ABI |
1331 deque& operator=(initializer_list<value_type> __il) {assign(__il); return *this;} | 1107 deque& operator=(initializer_list<value_type> __il) {assign(__il); return *this;} |
1332 | 1108 |
1333 _LIBCPP_INLINE_VISIBILITY | 1109 _LIBCPP_HIDE_FROM_ABI |
1334 deque(deque&& __c) _NOEXCEPT_(is_nothrow_move_constructible<__base>::value); | 1110 deque(deque&& __c) _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); |
1335 _LIBCPP_INLINE_VISIBILITY | 1111 _LIBCPP_HIDE_FROM_ABI |
1336 deque(deque&& __c, const __identity_t<allocator_type>& __a); | 1112 deque(deque&& __c, const __type_identity_t<allocator_type>& __a); |
1337 _LIBCPP_INLINE_VISIBILITY | 1113 _LIBCPP_HIDE_FROM_ABI |
1338 deque& operator=(deque&& __c) | 1114 deque& operator=(deque&& __c) |
1339 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value && | 1115 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value && |
1340 is_nothrow_move_assignable<allocator_type>::value); | 1116 is_nothrow_move_assignable<allocator_type>::value); |
1341 | 1117 |
1342 _LIBCPP_INLINE_VISIBILITY | 1118 _LIBCPP_HIDE_FROM_ABI |
1343 void assign(initializer_list<value_type> __il) {assign(__il.begin(), __il.end());} | 1119 void assign(initializer_list<value_type> __il) {assign(__il.begin(), __il.end());} |
1344 #endif // _LIBCPP_CXX03_LANG | 1120 #endif // _LIBCPP_CXX03_LANG |
1345 | 1121 |
1346 template <class _InputIter> | 1122 template <class _InputIter> |
1347 void assign(_InputIter __f, _InputIter __l, | 1123 _LIBCPP_HIDE_FROM_ABI void assign(_InputIter __f, _InputIter __l, |
1348 typename enable_if<__is_cpp17_input_iterator<_InputIter>::value && | 1124 typename enable_if<__is_cpp17_input_iterator<_InputIter>::value && |
1349 !__is_cpp17_random_access_iterator<_InputIter>::value>::type* = 0); | 1125 !__is_cpp17_random_access_iterator<_InputIter>::value>::type* = 0); |
1350 template <class _RAIter> | 1126 template <class _RAIter> |
1351 void assign(_RAIter __f, _RAIter __l, | 1127 _LIBCPP_HIDE_FROM_ABI void assign(_RAIter __f, _RAIter __l, |
1352 typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type* = 0); | 1128 typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type* = 0); |
1353 void assign(size_type __n, const value_type& __v); | 1129 _LIBCPP_HIDE_FROM_ABI void assign(size_type __n, const value_type& __v); |
1354 | 1130 |
1355 _LIBCPP_INLINE_VISIBILITY | 1131 _LIBCPP_HIDE_FROM_ABI |
1356 allocator_type get_allocator() const _NOEXCEPT; | 1132 allocator_type get_allocator() const _NOEXCEPT; |
1357 | 1133 _LIBCPP_HIDE_FROM_ABI allocator_type& __alloc() _NOEXCEPT { return __size_.second(); } |
1358 // iterators: | 1134 _LIBCPP_HIDE_FROM_ABI const allocator_type& __alloc() const _NOEXCEPT { return __size_.second(); } |
1359 | 1135 |
1360 _LIBCPP_INLINE_VISIBILITY | 1136 // iterators: |
1361 iterator begin() _NOEXCEPT {return __base::begin();} | 1137 |
1362 _LIBCPP_INLINE_VISIBILITY | 1138 _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { |
1363 const_iterator begin() const _NOEXCEPT {return __base::begin();} | 1139 __map_pointer __mp = __map_.begin() + __start_ / __block_size; |
1364 _LIBCPP_INLINE_VISIBILITY | 1140 return iterator(__mp, __map_.empty() ? 0 : *__mp + __start_ % __block_size); |
1365 iterator end() _NOEXCEPT {return __base::end();} | 1141 } |
1366 _LIBCPP_INLINE_VISIBILITY | 1142 |
1367 const_iterator end() const _NOEXCEPT {return __base::end();} | 1143 _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { |
1368 | 1144 __map_const_pointer __mp = |
1369 _LIBCPP_INLINE_VISIBILITY | 1145 static_cast<__map_const_pointer>(__map_.begin() + __start_ / __block_size); |
1146 return const_iterator(__mp, __map_.empty() ? 0 : *__mp + __start_ % __block_size); | |
1147 } | |
1148 | |
1149 _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT { | |
1150 size_type __p = size() + __start_; | |
1151 __map_pointer __mp = __map_.begin() + __p / __block_size; | |
1152 return iterator(__mp, __map_.empty() ? 0 : *__mp + __p % __block_size); | |
1153 } | |
1154 | |
1155 _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT { | |
1156 size_type __p = size() + __start_; | |
1157 __map_const_pointer __mp = static_cast<__map_const_pointer>(__map_.begin() + __p / __block_size); | |
1158 return const_iterator(__mp, __map_.empty() ? 0 : *__mp + __p % __block_size); | |
1159 } | |
1160 | |
1161 _LIBCPP_HIDE_FROM_ABI | |
1370 reverse_iterator rbegin() _NOEXCEPT | 1162 reverse_iterator rbegin() _NOEXCEPT |
1371 {return reverse_iterator(__base::end());} | 1163 {return reverse_iterator(end());} |
1372 _LIBCPP_INLINE_VISIBILITY | 1164 _LIBCPP_HIDE_FROM_ABI |
1373 const_reverse_iterator rbegin() const _NOEXCEPT | 1165 const_reverse_iterator rbegin() const _NOEXCEPT |
1374 {return const_reverse_iterator(__base::end());} | 1166 {return const_reverse_iterator(end());} |
1375 _LIBCPP_INLINE_VISIBILITY | 1167 _LIBCPP_HIDE_FROM_ABI |
1376 reverse_iterator rend() _NOEXCEPT | 1168 reverse_iterator rend() _NOEXCEPT |
1377 {return reverse_iterator(__base::begin());} | 1169 {return reverse_iterator(begin());} |
1378 _LIBCPP_INLINE_VISIBILITY | 1170 _LIBCPP_HIDE_FROM_ABI |
1379 const_reverse_iterator rend() const _NOEXCEPT | 1171 const_reverse_iterator rend() const _NOEXCEPT |
1380 {return const_reverse_iterator(__base::begin());} | 1172 {return const_reverse_iterator(begin());} |
1381 | 1173 |
1382 _LIBCPP_INLINE_VISIBILITY | 1174 _LIBCPP_HIDE_FROM_ABI |
1383 const_iterator cbegin() const _NOEXCEPT | 1175 const_iterator cbegin() const _NOEXCEPT |
1384 {return __base::begin();} | 1176 {return begin();} |
1385 _LIBCPP_INLINE_VISIBILITY | 1177 _LIBCPP_HIDE_FROM_ABI |
1386 const_iterator cend() const _NOEXCEPT | 1178 const_iterator cend() const _NOEXCEPT |
1387 {return __base::end();} | 1179 {return end();} |
1388 _LIBCPP_INLINE_VISIBILITY | 1180 _LIBCPP_HIDE_FROM_ABI |
1389 const_reverse_iterator crbegin() const _NOEXCEPT | 1181 const_reverse_iterator crbegin() const _NOEXCEPT |
1390 {return const_reverse_iterator(__base::end());} | 1182 {return const_reverse_iterator(end());} |
1391 _LIBCPP_INLINE_VISIBILITY | 1183 _LIBCPP_HIDE_FROM_ABI |
1392 const_reverse_iterator crend() const _NOEXCEPT | 1184 const_reverse_iterator crend() const _NOEXCEPT |
1393 {return const_reverse_iterator(__base::begin());} | 1185 {return const_reverse_iterator(begin());} |
1394 | 1186 |
1395 // capacity: | 1187 // capacity: |
1396 _LIBCPP_INLINE_VISIBILITY | 1188 _LIBCPP_HIDE_FROM_ABI |
1397 size_type size() const _NOEXCEPT {return __base::size();} | 1189 size_type size() const _NOEXCEPT {return __size();} |
1398 _LIBCPP_INLINE_VISIBILITY | 1190 |
1191 _LIBCPP_HIDE_FROM_ABI size_type& __size() _NOEXCEPT { return __size_.first(); } | |
1192 _LIBCPP_HIDE_FROM_ABI const size_type& __size() const _NOEXCEPT { return __size_.first(); } | |
1193 | |
1194 _LIBCPP_HIDE_FROM_ABI | |
1399 size_type max_size() const _NOEXCEPT | 1195 size_type max_size() const _NOEXCEPT |
1400 {return _VSTD::min<size_type>( | 1196 {return _VSTD::min<size_type>( |
1401 __alloc_traits::max_size(__base::__alloc()), | 1197 __alloc_traits::max_size(__alloc()), |
1402 numeric_limits<difference_type>::max());} | 1198 numeric_limits<difference_type>::max());} |
1403 void resize(size_type __n); | 1199 _LIBCPP_HIDE_FROM_ABI void resize(size_type __n); |
1404 void resize(size_type __n, const value_type& __v); | 1200 _LIBCPP_HIDE_FROM_ABI void resize(size_type __n, const value_type& __v); |
1405 void shrink_to_fit() _NOEXCEPT; | 1201 _LIBCPP_HIDE_FROM_ABI void shrink_to_fit() _NOEXCEPT; |
1406 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY | 1202 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI |
1407 bool empty() const _NOEXCEPT {return __base::size() == 0;} | 1203 bool empty() const _NOEXCEPT {return size() == 0;} |
1408 | 1204 |
1409 // element access: | 1205 // element access: |
1410 _LIBCPP_INLINE_VISIBILITY | 1206 _LIBCPP_HIDE_FROM_ABI |
1411 reference operator[](size_type __i) _NOEXCEPT; | 1207 reference operator[](size_type __i) _NOEXCEPT; |
1412 _LIBCPP_INLINE_VISIBILITY | 1208 _LIBCPP_HIDE_FROM_ABI |
1413 const_reference operator[](size_type __i) const _NOEXCEPT; | 1209 const_reference operator[](size_type __i) const _NOEXCEPT; |
1414 _LIBCPP_INLINE_VISIBILITY | 1210 _LIBCPP_HIDE_FROM_ABI |
1415 reference at(size_type __i); | 1211 reference at(size_type __i); |
1416 _LIBCPP_INLINE_VISIBILITY | 1212 _LIBCPP_HIDE_FROM_ABI |
1417 const_reference at(size_type __i) const; | 1213 const_reference at(size_type __i) const; |
1418 _LIBCPP_INLINE_VISIBILITY | 1214 _LIBCPP_HIDE_FROM_ABI |
1419 reference front() _NOEXCEPT; | 1215 reference front() _NOEXCEPT; |
1420 _LIBCPP_INLINE_VISIBILITY | 1216 _LIBCPP_HIDE_FROM_ABI |
1421 const_reference front() const _NOEXCEPT; | 1217 const_reference front() const _NOEXCEPT; |
1422 _LIBCPP_INLINE_VISIBILITY | 1218 _LIBCPP_HIDE_FROM_ABI |
1423 reference back() _NOEXCEPT; | 1219 reference back() _NOEXCEPT; |
1424 _LIBCPP_INLINE_VISIBILITY | 1220 _LIBCPP_HIDE_FROM_ABI |
1425 const_reference back() const _NOEXCEPT; | 1221 const_reference back() const _NOEXCEPT; |
1426 | 1222 |
1427 // 23.2.2.3 modifiers: | 1223 // 23.2.2.3 modifiers: |
1428 void push_front(const value_type& __v); | 1224 _LIBCPP_HIDE_FROM_ABI void push_front(const value_type& __v); |
1429 void push_back(const value_type& __v); | 1225 _LIBCPP_HIDE_FROM_ABI void push_back(const value_type& __v); |
1430 #ifndef _LIBCPP_CXX03_LANG | 1226 #ifndef _LIBCPP_CXX03_LANG |
1431 #if _LIBCPP_STD_VER > 14 | 1227 #if _LIBCPP_STD_VER > 14 |
1432 template <class... _Args> reference emplace_front(_Args&&... __args); | 1228 template <class... _Args> _LIBCPP_HIDE_FROM_ABI reference emplace_front(_Args&&... __args); |
1433 template <class... _Args> reference emplace_back (_Args&&... __args); | 1229 template <class... _Args> _LIBCPP_HIDE_FROM_ABI reference emplace_back (_Args&&... __args); |
1434 #else | 1230 #else |
1435 template <class... _Args> void emplace_front(_Args&&... __args); | 1231 template <class... _Args> _LIBCPP_HIDE_FROM_ABI void emplace_front(_Args&&... __args); |
1436 template <class... _Args> void emplace_back (_Args&&... __args); | 1232 template <class... _Args> _LIBCPP_HIDE_FROM_ABI void emplace_back (_Args&&... __args); |
1437 #endif | 1233 #endif |
1438 template <class... _Args> iterator emplace(const_iterator __p, _Args&&... __args); | 1234 template <class... _Args> _LIBCPP_HIDE_FROM_ABI iterator emplace(const_iterator __p, _Args&&... __args); |
1439 | 1235 |
1440 void push_front(value_type&& __v); | 1236 _LIBCPP_HIDE_FROM_ABI void push_front(value_type&& __v); |
1441 void push_back(value_type&& __v); | 1237 _LIBCPP_HIDE_FROM_ABI void push_back(value_type&& __v); |
1442 iterator insert(const_iterator __p, value_type&& __v); | 1238 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, value_type&& __v); |
1443 | 1239 |
1444 _LIBCPP_INLINE_VISIBILITY | 1240 _LIBCPP_HIDE_FROM_ABI |
1445 iterator insert(const_iterator __p, initializer_list<value_type> __il) | 1241 iterator insert(const_iterator __p, initializer_list<value_type> __il) |
1446 {return insert(__p, __il.begin(), __il.end());} | 1242 {return insert(__p, __il.begin(), __il.end());} |
1447 #endif // _LIBCPP_CXX03_LANG | 1243 #endif // _LIBCPP_CXX03_LANG |
1448 iterator insert(const_iterator __p, const value_type& __v); | 1244 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, const value_type& __v); |
1449 iterator insert(const_iterator __p, size_type __n, const value_type& __v); | 1245 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, size_type __n, const value_type& __v); |
1450 template <class _InputIter> | 1246 template <class _InputIter> |
1451 iterator insert(const_iterator __p, _InputIter __f, _InputIter __l, | 1247 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, _InputIter __f, _InputIter __l, |
1452 typename enable_if<__is_cpp17_input_iterator<_InputIter>::value | 1248 typename enable_if<__is_exactly_cpp17_input_iterator<_InputIter>::value>::type* = 0); |
1453 &&!__is_cpp17_forward_iterator<_InputIter>::value>::type* = 0); | |
1454 template <class _ForwardIterator> | 1249 template <class _ForwardIterator> |
1455 iterator insert(const_iterator __p, _ForwardIterator __f, _ForwardIterator __l, | 1250 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, _ForwardIterator __f, _ForwardIterator __l, |
1456 typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value | 1251 typename enable_if<__is_exactly_cpp17_forward_iterator<_ForwardIterator>::value>::type* = 0); |
1457 &&!__is_cpp17_bidirectional_iterator<_ForwardIterator>::value>::type* = 0); | |
1458 template <class _BiIter> | 1252 template <class _BiIter> |
1459 iterator insert(const_iterator __p, _BiIter __f, _BiIter __l, | 1253 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, _BiIter __f, _BiIter __l, |
1460 typename enable_if<__is_cpp17_bidirectional_iterator<_BiIter>::value>::type* = 0); | 1254 typename enable_if<__is_cpp17_bidirectional_iterator<_BiIter>::value>::type* = 0); |
1461 | 1255 |
1462 void pop_front(); | 1256 _LIBCPP_HIDE_FROM_ABI void pop_front(); |
1463 void pop_back(); | 1257 _LIBCPP_HIDE_FROM_ABI void pop_back(); |
1464 iterator erase(const_iterator __p); | 1258 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __p); |
1465 iterator erase(const_iterator __f, const_iterator __l); | 1259 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __f, const_iterator __l); |
1466 | 1260 |
1467 _LIBCPP_INLINE_VISIBILITY | 1261 _LIBCPP_HIDE_FROM_ABI |
1468 void swap(deque& __c) | 1262 void swap(deque& __c) |
1469 #if _LIBCPP_STD_VER >= 14 | 1263 #if _LIBCPP_STD_VER >= 14 |
1470 _NOEXCEPT; | 1264 _NOEXCEPT; |
1471 #else | 1265 #else |
1472 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || | 1266 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || |
1473 __is_nothrow_swappable<allocator_type>::value); | 1267 __is_nothrow_swappable<allocator_type>::value); |
1474 #endif | 1268 #endif |
1475 _LIBCPP_INLINE_VISIBILITY | 1269 _LIBCPP_HIDE_FROM_ABI |
1476 void clear() _NOEXCEPT; | 1270 void clear() _NOEXCEPT; |
1477 | 1271 |
1478 _LIBCPP_INLINE_VISIBILITY | 1272 _LIBCPP_HIDE_FROM_ABI |
1479 bool __invariants() const {return __base::__invariants();} | 1273 bool __invariants() const { |
1480 | 1274 if (!__map_.__invariants()) |
1481 typedef typename __base::__map_const_pointer __map_const_pointer; | 1275 return false; |
1482 | 1276 if (__map_.size() >= size_type(-1) / __block_size) |
1483 _LIBCPP_INLINE_VISIBILITY | 1277 return false; |
1278 for (typename __map::const_iterator __i = __map_.begin(), __e = __map_.end(); | |
1279 __i != __e; ++__i) | |
1280 if (*__i == nullptr) | |
1281 return false; | |
1282 if (__map_.size() != 0) | |
1283 { | |
1284 if (size() >= __map_.size() * __block_size) | |
1285 return false; | |
1286 if (__start_ >= __map_.size() * __block_size - size()) | |
1287 return false; | |
1288 } | |
1289 else | |
1290 { | |
1291 if (size() != 0) | |
1292 return false; | |
1293 if (__start_ != 0) | |
1294 return false; | |
1295 } | |
1296 return true; | |
1297 } | |
1298 | |
1299 _LIBCPP_HIDE_FROM_ABI | |
1300 void __move_assign_alloc(deque& __c) | |
1301 _NOEXCEPT_(!__alloc_traits::propagate_on_container_move_assignment::value || | |
1302 is_nothrow_move_assignable<allocator_type>::value) | |
1303 {__move_assign_alloc(__c, integral_constant<bool, | |
1304 __alloc_traits::propagate_on_container_move_assignment::value>());} | |
1305 | |
1306 _LIBCPP_HIDE_FROM_ABI | |
1307 void __move_assign_alloc(deque& __c, true_type) | |
1308 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) | |
1309 { | |
1310 __alloc() = _VSTD::move(__c.__alloc()); | |
1311 } | |
1312 | |
1313 _LIBCPP_HIDE_FROM_ABI | |
1314 void __move_assign_alloc(deque&, false_type) _NOEXCEPT | |
1315 {} | |
1316 | |
1317 _LIBCPP_HIDE_FROM_ABI | |
1318 void __move_assign(deque& __c) | |
1319 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value && | |
1320 is_nothrow_move_assignable<allocator_type>::value) | |
1321 { | |
1322 __map_ = _VSTD::move(__c.__map_); | |
1323 __start_ = __c.__start_; | |
1324 __size() = __c.size(); | |
1325 __move_assign_alloc(__c); | |
1326 __c.__start_ = __c.__size() = 0; | |
1327 } | |
1328 | |
1329 _LIBCPP_HIDE_FROM_ABI | |
1484 static size_type __recommend_blocks(size_type __n) | 1330 static size_type __recommend_blocks(size_type __n) |
1485 { | 1331 { |
1486 return __n / __base::__block_size + (__n % __base::__block_size != 0); | 1332 return __n / __block_size + (__n % __block_size != 0); |
1487 } | 1333 } |
1488 _LIBCPP_INLINE_VISIBILITY | 1334 _LIBCPP_HIDE_FROM_ABI |
1489 size_type __capacity() const | 1335 size_type __capacity() const |
1490 { | 1336 { |
1491 return __base::__map_.size() == 0 ? 0 : __base::__map_.size() * __base::__block_size - 1; | 1337 return __map_.size() == 0 ? 0 : __map_.size() * __block_size - 1; |
1492 } | 1338 } |
1493 _LIBCPP_INLINE_VISIBILITY | 1339 _LIBCPP_HIDE_FROM_ABI |
1494 size_type __block_count() const | 1340 size_type __block_count() const |
1495 { | 1341 { |
1496 return __base::__map_.size(); | 1342 return __map_.size(); |
1497 } | 1343 } |
1498 | 1344 |
1499 _LIBCPP_INLINE_VISIBILITY | 1345 _LIBCPP_HIDE_FROM_ABI |
1500 size_type __front_spare() const | 1346 size_type __front_spare() const |
1501 { | 1347 { |
1502 return __base::__start_; | 1348 return __start_; |
1503 } | 1349 } |
1504 _LIBCPP_INLINE_VISIBILITY | 1350 _LIBCPP_HIDE_FROM_ABI |
1505 size_type __front_spare_blocks() const { | 1351 size_type __front_spare_blocks() const { |
1506 return __front_spare() / __base::__block_size; | 1352 return __front_spare() / __block_size; |
1507 } | 1353 } |
1508 _LIBCPP_INLINE_VISIBILITY | 1354 _LIBCPP_HIDE_FROM_ABI |
1509 size_type __back_spare() const | 1355 size_type __back_spare() const |
1510 { | 1356 { |
1511 return __capacity() - (__base::__start_ + __base::size()); | 1357 return __capacity() - (__start_ + size()); |
1512 } | 1358 } |
1513 _LIBCPP_INLINE_VISIBILITY | 1359 _LIBCPP_HIDE_FROM_ABI |
1514 size_type __back_spare_blocks() const { | 1360 size_type __back_spare_blocks() const { |
1515 return __back_spare() / __base::__block_size; | 1361 return __back_spare() / __block_size; |
1516 } | 1362 } |
1517 | 1363 |
1518 private: | 1364 private: |
1519 _LIBCPP_INLINE_VISIBILITY | 1365 _LIBCPP_HIDE_FROM_ABI |
1520 bool __maybe_remove_front_spare(bool __keep_one = true) { | 1366 bool __maybe_remove_front_spare(bool __keep_one = true) { |
1521 if (__front_spare_blocks() >= 2 || (!__keep_one && __front_spare_blocks())) { | 1367 if (__front_spare_blocks() >= 2 || (!__keep_one && __front_spare_blocks())) { |
1522 __alloc_traits::deallocate(__base::__alloc(), __base::__map_.front(), | 1368 __alloc_traits::deallocate(__alloc(), __map_.front(), |
1523 __base::__block_size); | 1369 __block_size); |
1524 __base::__map_.pop_front(); | 1370 __map_.pop_front(); |
1525 __base::__start_ -= __base::__block_size; | 1371 __start_ -= __block_size; |
1526 return true; | 1372 return true; |
1527 } | 1373 } |
1528 return false; | 1374 return false; |
1529 } | 1375 } |
1530 | 1376 |
1531 _LIBCPP_INLINE_VISIBILITY | 1377 _LIBCPP_HIDE_FROM_ABI |
1532 bool __maybe_remove_back_spare(bool __keep_one = true) { | 1378 bool __maybe_remove_back_spare(bool __keep_one = true) { |
1533 if (__back_spare_blocks() >= 2 || (!__keep_one && __back_spare_blocks())) { | 1379 if (__back_spare_blocks() >= 2 || (!__keep_one && __back_spare_blocks())) { |
1534 __alloc_traits::deallocate(__base::__alloc(), __base::__map_.back(), | 1380 __alloc_traits::deallocate(__alloc(), __map_.back(), |
1535 __base::__block_size); | 1381 __block_size); |
1536 __base::__map_.pop_back(); | 1382 __map_.pop_back(); |
1537 return true; | 1383 return true; |
1538 } | 1384 } |
1539 return false; | 1385 return false; |
1540 } | 1386 } |
1541 | 1387 |
1542 template <class _InpIter> | 1388 template <class _InpIter> |
1543 void __append(_InpIter __f, _InpIter __l, | 1389 _LIBCPP_HIDE_FROM_ABI void __append(_InpIter __f, _InpIter __l, |
1544 typename enable_if<__is_cpp17_input_iterator<_InpIter>::value && | 1390 typename enable_if<__is_exactly_cpp17_input_iterator<_InpIter>::value>::type* = 0); |
1545 !__is_cpp17_forward_iterator<_InpIter>::value>::type* = 0); | |
1546 template <class _ForIter> | 1391 template <class _ForIter> |
1547 void __append(_ForIter __f, _ForIter __l, | 1392 _LIBCPP_HIDE_FROM_ABI void __append(_ForIter __f, _ForIter __l, |
1548 typename enable_if<__is_cpp17_forward_iterator<_ForIter>::value>::type* = 0); | 1393 typename enable_if<__is_cpp17_forward_iterator<_ForIter>::value>::type* = 0); |
1549 void __append(size_type __n); | 1394 _LIBCPP_HIDE_FROM_ABI void __append(size_type __n); |
1550 void __append(size_type __n, const value_type& __v); | 1395 _LIBCPP_HIDE_FROM_ABI void __append(size_type __n, const value_type& __v); |
1551 void __erase_to_end(const_iterator __f); | 1396 _LIBCPP_HIDE_FROM_ABI void __erase_to_end(const_iterator __f); |
1552 void __add_front_capacity(); | 1397 _LIBCPP_HIDE_FROM_ABI void __add_front_capacity(); |
1553 void __add_front_capacity(size_type __n); | 1398 _LIBCPP_HIDE_FROM_ABI void __add_front_capacity(size_type __n); |
1554 void __add_back_capacity(); | 1399 _LIBCPP_HIDE_FROM_ABI void __add_back_capacity(); |
1555 void __add_back_capacity(size_type __n); | 1400 _LIBCPP_HIDE_FROM_ABI void __add_back_capacity(size_type __n); |
1556 iterator __move_and_check(iterator __f, iterator __l, iterator __r, | 1401 _LIBCPP_HIDE_FROM_ABI iterator __move_and_check(iterator __f, iterator __l, iterator __r, |
1557 const_pointer& __vt); | 1402 const_pointer& __vt); |
1558 iterator __move_backward_and_check(iterator __f, iterator __l, iterator __r, | 1403 _LIBCPP_HIDE_FROM_ABI iterator __move_backward_and_check(iterator __f, iterator __l, iterator __r, |
1559 const_pointer& __vt); | 1404 const_pointer& __vt); |
1560 void __move_construct_and_check(iterator __f, iterator __l, | 1405 _LIBCPP_HIDE_FROM_ABI void __move_construct_and_check(iterator __f, iterator __l, |
1561 iterator __r, const_pointer& __vt); | 1406 iterator __r, const_pointer& __vt); |
1562 void __move_construct_backward_and_check(iterator __f, iterator __l, | 1407 _LIBCPP_HIDE_FROM_ABI void __move_construct_backward_and_check(iterator __f, iterator __l, |
1563 iterator __r, const_pointer& __vt); | 1408 iterator __r, const_pointer& __vt); |
1564 | 1409 |
1565 _LIBCPP_INLINE_VISIBILITY | 1410 _LIBCPP_HIDE_FROM_ABI |
1566 void __copy_assign_alloc(const deque& __c) | 1411 void __copy_assign_alloc(const deque& __c) |
1567 {__copy_assign_alloc(__c, integral_constant<bool, | 1412 {__copy_assign_alloc(__c, integral_constant<bool, |
1568 __alloc_traits::propagate_on_container_copy_assignment::value>());} | 1413 __alloc_traits::propagate_on_container_copy_assignment::value>());} |
1569 | 1414 |
1570 _LIBCPP_INLINE_VISIBILITY | 1415 _LIBCPP_HIDE_FROM_ABI |
1571 void __copy_assign_alloc(const deque& __c, true_type) | 1416 void __copy_assign_alloc(const deque& __c, true_type) |
1572 { | 1417 { |
1573 if (__base::__alloc() != __c.__alloc()) | 1418 if (__alloc() != __c.__alloc()) |
1574 { | 1419 { |
1575 clear(); | 1420 clear(); |
1576 shrink_to_fit(); | 1421 shrink_to_fit(); |
1577 } | 1422 } |
1578 __base::__alloc() = __c.__alloc(); | 1423 __alloc() = __c.__alloc(); |
1579 __base::__map_.__alloc() = __c.__map_.__alloc(); | 1424 __map_.__alloc() = __c.__map_.__alloc(); |
1580 } | 1425 } |
1581 | 1426 |
1582 _LIBCPP_INLINE_VISIBILITY | 1427 _LIBCPP_HIDE_FROM_ABI |
1583 void __copy_assign_alloc(const deque&, false_type) | 1428 void __copy_assign_alloc(const deque&, false_type) |
1584 {} | 1429 {} |
1585 | 1430 |
1586 void __move_assign(deque& __c, true_type) | 1431 _LIBCPP_HIDE_FROM_ABI void __move_assign(deque& __c, true_type) |
1587 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); | 1432 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); |
1588 void __move_assign(deque& __c, false_type); | 1433 _LIBCPP_HIDE_FROM_ABI void __move_assign(deque& __c, false_type); |
1589 }; | 1434 }; |
1590 | 1435 |
1591 #ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES | 1436 template <class _Tp, class _Alloc> |
1437 _LIBCPP_CONSTEXPR const typename allocator_traits<_Alloc>::difference_type deque<_Tp, _Alloc>::__block_size = | |
1438 __deque_block_size<value_type, difference_type>::value; | |
1439 | |
1440 #if _LIBCPP_STD_VER >= 17 | |
1592 template<class _InputIterator, | 1441 template<class _InputIterator, |
1593 class _Alloc = allocator<__iter_value_type<_InputIterator>>, | 1442 class _Alloc = allocator<__iter_value_type<_InputIterator>>, |
1594 class = _EnableIf<__is_allocator<_Alloc>::value> | 1443 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>, |
1444 class = enable_if_t<__is_allocator<_Alloc>::value> | |
1595 > | 1445 > |
1596 deque(_InputIterator, _InputIterator) | 1446 deque(_InputIterator, _InputIterator) |
1597 -> deque<__iter_value_type<_InputIterator>, _Alloc>; | 1447 -> deque<__iter_value_type<_InputIterator>, _Alloc>; |
1598 | 1448 |
1599 template<class _InputIterator, | 1449 template<class _InputIterator, |
1600 class _Alloc, | 1450 class _Alloc, |
1601 class = _EnableIf<__is_allocator<_Alloc>::value> | 1451 class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>, |
1452 class = enable_if_t<__is_allocator<_Alloc>::value> | |
1602 > | 1453 > |
1603 deque(_InputIterator, _InputIterator, _Alloc) | 1454 deque(_InputIterator, _InputIterator, _Alloc) |
1604 -> deque<__iter_value_type<_InputIterator>, _Alloc>; | 1455 -> deque<__iter_value_type<_InputIterator>, _Alloc>; |
1605 #endif | 1456 #endif |
1606 | 1457 |
1607 | |
1608 template <class _Tp, class _Allocator> | 1458 template <class _Tp, class _Allocator> |
1609 deque<_Tp, _Allocator>::deque(size_type __n) | 1459 deque<_Tp, _Allocator>::deque(size_type __n) |
1460 : __start_(0), __size_(0, __default_init_tag()) | |
1610 { | 1461 { |
1611 if (__n > 0) | 1462 if (__n > 0) |
1612 __append(__n); | 1463 __append(__n); |
1613 } | 1464 } |
1614 | 1465 |
1615 #if _LIBCPP_STD_VER > 11 | 1466 #if _LIBCPP_STD_VER > 11 |
1616 template <class _Tp, class _Allocator> | 1467 template <class _Tp, class _Allocator> |
1617 deque<_Tp, _Allocator>::deque(size_type __n, const _Allocator& __a) | 1468 deque<_Tp, _Allocator>::deque(size_type __n, const _Allocator& __a) |
1618 : __base(__a) | 1469 : __map_(__pointer_allocator(__a)), __start_(0), __size_(0, __a) |
1619 { | 1470 { |
1620 if (__n > 0) | 1471 if (__n > 0) |
1621 __append(__n); | 1472 __append(__n); |
1622 } | 1473 } |
1623 #endif | 1474 #endif |
1624 | 1475 |
1625 template <class _Tp, class _Allocator> | 1476 template <class _Tp, class _Allocator> |
1626 deque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v) | 1477 deque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v) |
1627 { | 1478 : __start_(0), __size_(0, __default_init_tag()) |
1628 if (__n > 0) | |
1629 __append(__n, __v); | |
1630 } | |
1631 | |
1632 template <class _Tp, class _Allocator> | |
1633 deque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v, const allocator_type& __a) | |
1634 : __base(__a) | |
1635 { | 1479 { |
1636 if (__n > 0) | 1480 if (__n > 0) |
1637 __append(__n, __v); | 1481 __append(__n, __v); |
1638 } | 1482 } |
1639 | 1483 |
1640 template <class _Tp, class _Allocator> | 1484 template <class _Tp, class _Allocator> |
1641 template <class _InputIter> | 1485 template <class _InputIter> |
1642 deque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l, | 1486 deque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l, |
1643 typename enable_if<__is_cpp17_input_iterator<_InputIter>::value>::type*) | 1487 typename enable_if<__is_cpp17_input_iterator<_InputIter>::value>::type*) |
1488 : __start_(0), __size_(0, __default_init_tag()) | |
1644 { | 1489 { |
1645 __append(__f, __l); | 1490 __append(__f, __l); |
1646 } | 1491 } |
1647 | 1492 |
1648 template <class _Tp, class _Allocator> | 1493 template <class _Tp, class _Allocator> |
1649 template <class _InputIter> | 1494 template <class _InputIter> |
1650 deque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l, const allocator_type& __a, | 1495 deque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l, const allocator_type& __a, |
1651 typename enable_if<__is_cpp17_input_iterator<_InputIter>::value>::type*) | 1496 typename enable_if<__is_cpp17_input_iterator<_InputIter>::value>::type*) |
1652 : __base(__a) | 1497 : __map_(__pointer_allocator(__a)), __start_(0), __size_(0, __a) |
1653 { | 1498 { |
1654 __append(__f, __l); | 1499 __append(__f, __l); |
1655 } | 1500 } |
1656 | 1501 |
1657 template <class _Tp, class _Allocator> | 1502 template <class _Tp, class _Allocator> |
1658 deque<_Tp, _Allocator>::deque(const deque& __c) | 1503 deque<_Tp, _Allocator>::deque(const deque& __c) |
1659 : __base(__alloc_traits::select_on_container_copy_construction(__c.__alloc())) | 1504 : __map_(__pointer_allocator(__alloc_traits::select_on_container_copy_construction(__c.__alloc()))), |
1505 __start_(0), | |
1506 __size_(0, __map_.__alloc()) | |
1660 { | 1507 { |
1661 __append(__c.begin(), __c.end()); | 1508 __append(__c.begin(), __c.end()); |
1662 } | 1509 } |
1663 | 1510 |
1664 template <class _Tp, class _Allocator> | 1511 template <class _Tp, class _Allocator> |
1665 deque<_Tp, _Allocator>::deque(const deque& __c, const __identity_t<allocator_type>& __a) | 1512 deque<_Tp, _Allocator>::deque(const deque& __c, const __type_identity_t<allocator_type>& __a) |
1666 : __base(__a) | 1513 : __map_(__pointer_allocator(__a)), __start_(0), __size_(0, __a) |
1667 { | 1514 { |
1668 __append(__c.begin(), __c.end()); | 1515 __append(__c.begin(), __c.end()); |
1669 } | 1516 } |
1670 | 1517 |
1671 template <class _Tp, class _Allocator> | 1518 template <class _Tp, class _Allocator> |
1672 deque<_Tp, _Allocator>& | 1519 deque<_Tp, _Allocator>& |
1673 deque<_Tp, _Allocator>::operator=(const deque& __c) | 1520 deque<_Tp, _Allocator>::operator=(const deque& __c) |
1674 { | 1521 { |
1675 if (this != &__c) | 1522 if (this != _VSTD::addressof(__c)) |
1676 { | 1523 { |
1677 __copy_assign_alloc(__c); | 1524 __copy_assign_alloc(__c); |
1678 assign(__c.begin(), __c.end()); | 1525 assign(__c.begin(), __c.end()); |
1679 } | 1526 } |
1680 return *this; | 1527 return *this; |
1682 | 1529 |
1683 #ifndef _LIBCPP_CXX03_LANG | 1530 #ifndef _LIBCPP_CXX03_LANG |
1684 | 1531 |
1685 template <class _Tp, class _Allocator> | 1532 template <class _Tp, class _Allocator> |
1686 deque<_Tp, _Allocator>::deque(initializer_list<value_type> __il) | 1533 deque<_Tp, _Allocator>::deque(initializer_list<value_type> __il) |
1534 : __start_(0), __size_(0, __default_init_tag()) | |
1687 { | 1535 { |
1688 __append(__il.begin(), __il.end()); | 1536 __append(__il.begin(), __il.end()); |
1689 } | 1537 } |
1690 | 1538 |
1691 template <class _Tp, class _Allocator> | 1539 template <class _Tp, class _Allocator> |
1692 deque<_Tp, _Allocator>::deque(initializer_list<value_type> __il, const allocator_type& __a) | 1540 deque<_Tp, _Allocator>::deque(initializer_list<value_type> __il, const allocator_type& __a) |
1693 : __base(__a) | 1541 : __map_(__pointer_allocator(__a)), __start_(0), __size_(0, __a) |
1694 { | 1542 { |
1695 __append(__il.begin(), __il.end()); | 1543 __append(__il.begin(), __il.end()); |
1696 } | 1544 } |
1697 | 1545 |
1698 template <class _Tp, class _Allocator> | 1546 template <class _Tp, class _Allocator> |
1699 inline | 1547 inline |
1700 deque<_Tp, _Allocator>::deque(deque&& __c) | 1548 deque<_Tp, _Allocator>::deque(deque&& __c) |
1701 _NOEXCEPT_(is_nothrow_move_constructible<__base>::value) | 1549 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) |
1702 : __base(_VSTD::move(__c)) | 1550 : __map_(std::move(__c.__map_)), __start_(std::move(__c.__start_)), __size_(std::move(__c.__size_)) |
1703 { | 1551 { |
1552 __c.__start_ = 0; | |
1553 __c.__size() = 0; | |
1704 } | 1554 } |
1705 | 1555 |
1706 template <class _Tp, class _Allocator> | 1556 template <class _Tp, class _Allocator> |
1707 inline | 1557 inline |
1708 deque<_Tp, _Allocator>::deque(deque&& __c, const __identity_t<allocator_type>& __a) | 1558 deque<_Tp, _Allocator>::deque(deque&& __c, const __type_identity_t<allocator_type>& __a) |
1709 : __base(_VSTD::move(__c), __a) | 1559 : __map_(std::move(__c.__map_), __pointer_allocator(__a)), |
1710 { | 1560 __start_(std::move(__c.__start_)), |
1711 if (__a != __c.__alloc()) | 1561 __size_(std::move(__c.__size()), __a) |
1712 { | 1562 { |
1563 if (__a == __c.__alloc()) | |
1564 { | |
1565 __c.__start_ = 0; | |
1566 __c.__size() = 0; | |
1567 } | |
1568 else | |
1569 { | |
1570 __map_.clear(); | |
1571 __start_ = 0; | |
1572 __size() = 0; | |
1713 typedef move_iterator<iterator> _Ip; | 1573 typedef move_iterator<iterator> _Ip; |
1714 assign(_Ip(__c.begin()), _Ip(__c.end())); | 1574 assign(_Ip(__c.begin()), _Ip(__c.end())); |
1715 } | 1575 } |
1716 } | 1576 } |
1717 | 1577 |
1729 | 1589 |
1730 template <class _Tp, class _Allocator> | 1590 template <class _Tp, class _Allocator> |
1731 void | 1591 void |
1732 deque<_Tp, _Allocator>::__move_assign(deque& __c, false_type) | 1592 deque<_Tp, _Allocator>::__move_assign(deque& __c, false_type) |
1733 { | 1593 { |
1734 if (__base::__alloc() != __c.__alloc()) | 1594 if (__alloc() != __c.__alloc()) |
1735 { | 1595 { |
1736 typedef move_iterator<iterator> _Ip; | 1596 typedef move_iterator<iterator> _Ip; |
1737 assign(_Ip(__c.begin()), _Ip(__c.end())); | 1597 assign(_Ip(__c.begin()), _Ip(__c.end())); |
1738 } | 1598 } |
1739 else | 1599 else |
1745 deque<_Tp, _Allocator>::__move_assign(deque& __c, true_type) | 1605 deque<_Tp, _Allocator>::__move_assign(deque& __c, true_type) |
1746 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) | 1606 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) |
1747 { | 1607 { |
1748 clear(); | 1608 clear(); |
1749 shrink_to_fit(); | 1609 shrink_to_fit(); |
1750 __base::__move_assign(__c); | 1610 __move_assign(__c); |
1751 } | 1611 } |
1752 | 1612 |
1753 #endif // _LIBCPP_CXX03_LANG | 1613 #endif // _LIBCPP_CXX03_LANG |
1754 | 1614 |
1755 template <class _Tp, class _Allocator> | 1615 template <class _Tp, class _Allocator> |
1757 void | 1617 void |
1758 deque<_Tp, _Allocator>::assign(_InputIter __f, _InputIter __l, | 1618 deque<_Tp, _Allocator>::assign(_InputIter __f, _InputIter __l, |
1759 typename enable_if<__is_cpp17_input_iterator<_InputIter>::value && | 1619 typename enable_if<__is_cpp17_input_iterator<_InputIter>::value && |
1760 !__is_cpp17_random_access_iterator<_InputIter>::value>::type*) | 1620 !__is_cpp17_random_access_iterator<_InputIter>::value>::type*) |
1761 { | 1621 { |
1762 iterator __i = __base::begin(); | 1622 iterator __i = begin(); |
1763 iterator __e = __base::end(); | 1623 iterator __e = end(); |
1764 for (; __f != __l && __i != __e; ++__f, (void) ++__i) | 1624 for (; __f != __l && __i != __e; ++__f, (void) ++__i) |
1765 *__i = *__f; | 1625 *__i = *__f; |
1766 if (__f != __l) | 1626 if (__f != __l) |
1767 __append(__f, __l); | 1627 __append(__f, __l); |
1768 else | 1628 else |
1773 template <class _RAIter> | 1633 template <class _RAIter> |
1774 void | 1634 void |
1775 deque<_Tp, _Allocator>::assign(_RAIter __f, _RAIter __l, | 1635 deque<_Tp, _Allocator>::assign(_RAIter __f, _RAIter __l, |
1776 typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type*) | 1636 typename enable_if<__is_cpp17_random_access_iterator<_RAIter>::value>::type*) |
1777 { | 1637 { |
1778 if (static_cast<size_type>(__l - __f) > __base::size()) | 1638 if (static_cast<size_type>(__l - __f) > size()) |
1779 { | 1639 { |
1780 _RAIter __m = __f + __base::size(); | 1640 _RAIter __m = __f + size(); |
1781 _VSTD::copy(__f, __m, __base::begin()); | 1641 _VSTD::copy(__f, __m, begin()); |
1782 __append(__m, __l); | 1642 __append(__m, __l); |
1783 } | 1643 } |
1784 else | 1644 else |
1785 __erase_to_end(_VSTD::copy(__f, __l, __base::begin())); | 1645 __erase_to_end(_VSTD::copy(__f, __l, begin())); |
1786 } | 1646 } |
1787 | 1647 |
1788 template <class _Tp, class _Allocator> | 1648 template <class _Tp, class _Allocator> |
1789 void | 1649 void |
1790 deque<_Tp, _Allocator>::assign(size_type __n, const value_type& __v) | 1650 deque<_Tp, _Allocator>::assign(size_type __n, const value_type& __v) |
1791 { | 1651 { |
1792 if (__n > __base::size()) | 1652 if (__n > size()) |
1793 { | 1653 { |
1794 _VSTD::fill_n(__base::begin(), __base::size(), __v); | 1654 _VSTD::fill_n(begin(), size(), __v); |
1795 __n -= __base::size(); | 1655 __n -= size(); |
1796 __append(__n, __v); | 1656 __append(__n, __v); |
1797 } | 1657 } |
1798 else | 1658 else |
1799 __erase_to_end(_VSTD::fill_n(__base::begin(), __n, __v)); | 1659 __erase_to_end(_VSTD::fill_n(begin(), __n, __v)); |
1800 } | 1660 } |
1801 | 1661 |
1802 template <class _Tp, class _Allocator> | 1662 template <class _Tp, class _Allocator> |
1803 inline | 1663 inline |
1804 _Allocator | 1664 _Allocator |
1805 deque<_Tp, _Allocator>::get_allocator() const _NOEXCEPT | 1665 deque<_Tp, _Allocator>::get_allocator() const _NOEXCEPT |
1806 { | 1666 { |
1807 return __base::__alloc(); | 1667 return __alloc(); |
1808 } | 1668 } |
1809 | 1669 |
1810 template <class _Tp, class _Allocator> | 1670 template <class _Tp, class _Allocator> |
1811 void | 1671 void |
1812 deque<_Tp, _Allocator>::resize(size_type __n) | 1672 deque<_Tp, _Allocator>::resize(size_type __n) |
1813 { | 1673 { |
1814 if (__n > __base::size()) | 1674 if (__n > size()) |
1815 __append(__n - __base::size()); | 1675 __append(__n - size()); |
1816 else if (__n < __base::size()) | 1676 else if (__n < size()) |
1817 __erase_to_end(__base::begin() + __n); | 1677 __erase_to_end(begin() + __n); |
1818 } | 1678 } |
1819 | 1679 |
1820 template <class _Tp, class _Allocator> | 1680 template <class _Tp, class _Allocator> |
1821 void | 1681 void |
1822 deque<_Tp, _Allocator>::resize(size_type __n, const value_type& __v) | 1682 deque<_Tp, _Allocator>::resize(size_type __n, const value_type& __v) |
1823 { | 1683 { |
1824 if (__n > __base::size()) | 1684 if (__n > size()) |
1825 __append(__n - __base::size(), __v); | 1685 __append(__n - size(), __v); |
1826 else if (__n < __base::size()) | 1686 else if (__n < size()) |
1827 __erase_to_end(__base::begin() + __n); | 1687 __erase_to_end(begin() + __n); |
1828 } | 1688 } |
1829 | 1689 |
1830 template <class _Tp, class _Allocator> | 1690 template <class _Tp, class _Allocator> |
1831 void | 1691 void |
1832 deque<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT | 1692 deque<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT |
1833 { | 1693 { |
1834 allocator_type& __a = __base::__alloc(); | 1694 allocator_type& __a = __alloc(); |
1835 if (empty()) | 1695 if (empty()) |
1836 { | 1696 { |
1837 while (__base::__map_.size() > 0) | 1697 while (__map_.size() > 0) |
1838 { | 1698 { |
1839 __alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size); | 1699 __alloc_traits::deallocate(__a, __map_.back(), __block_size); |
1840 __base::__map_.pop_back(); | 1700 __map_.pop_back(); |
1841 } | 1701 } |
1842 __base::__start_ = 0; | 1702 __start_ = 0; |
1843 } | 1703 } |
1844 else | 1704 else |
1845 { | 1705 { |
1846 __maybe_remove_front_spare(/*__keep_one=*/false); | 1706 __maybe_remove_front_spare(/*__keep_one=*/false); |
1847 __maybe_remove_back_spare(/*__keep_one=*/false); | 1707 __maybe_remove_back_spare(/*__keep_one=*/false); |
1848 } | 1708 } |
1849 __base::__map_.shrink_to_fit(); | 1709 __map_.shrink_to_fit(); |
1850 } | 1710 } |
1851 | 1711 |
1852 template <class _Tp, class _Allocator> | 1712 template <class _Tp, class _Allocator> |
1853 inline | 1713 inline |
1854 typename deque<_Tp, _Allocator>::reference | 1714 typename deque<_Tp, _Allocator>::reference |
1855 deque<_Tp, _Allocator>::operator[](size_type __i) _NOEXCEPT | 1715 deque<_Tp, _Allocator>::operator[](size_type __i) _NOEXCEPT |
1856 { | 1716 { |
1857 size_type __p = __base::__start_ + __i; | 1717 size_type __p = __start_ + __i; |
1858 return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); | 1718 return *(*(__map_.begin() + __p / __block_size) + __p % __block_size); |
1859 } | 1719 } |
1860 | 1720 |
1861 template <class _Tp, class _Allocator> | 1721 template <class _Tp, class _Allocator> |
1862 inline | 1722 inline |
1863 typename deque<_Tp, _Allocator>::const_reference | 1723 typename deque<_Tp, _Allocator>::const_reference |
1864 deque<_Tp, _Allocator>::operator[](size_type __i) const _NOEXCEPT | 1724 deque<_Tp, _Allocator>::operator[](size_type __i) const _NOEXCEPT |
1865 { | 1725 { |
1866 size_type __p = __base::__start_ + __i; | 1726 size_type __p = __start_ + __i; |
1867 return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); | 1727 return *(*(__map_.begin() + __p / __block_size) + __p % __block_size); |
1868 } | 1728 } |
1869 | 1729 |
1870 template <class _Tp, class _Allocator> | 1730 template <class _Tp, class _Allocator> |
1871 inline | 1731 inline |
1872 typename deque<_Tp, _Allocator>::reference | 1732 typename deque<_Tp, _Allocator>::reference |
1873 deque<_Tp, _Allocator>::at(size_type __i) | 1733 deque<_Tp, _Allocator>::at(size_type __i) |
1874 { | 1734 { |
1875 if (__i >= __base::size()) | 1735 if (__i >= size()) |
1876 __base::__throw_out_of_range(); | 1736 _VSTD::__throw_out_of_range("deque"); |
1877 size_type __p = __base::__start_ + __i; | 1737 size_type __p = __start_ + __i; |
1878 return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); | 1738 return *(*(__map_.begin() + __p / __block_size) + __p % __block_size); |
1879 } | 1739 } |
1880 | 1740 |
1881 template <class _Tp, class _Allocator> | 1741 template <class _Tp, class _Allocator> |
1882 inline | 1742 inline |
1883 typename deque<_Tp, _Allocator>::const_reference | 1743 typename deque<_Tp, _Allocator>::const_reference |
1884 deque<_Tp, _Allocator>::at(size_type __i) const | 1744 deque<_Tp, _Allocator>::at(size_type __i) const |
1885 { | 1745 { |
1886 if (__i >= __base::size()) | 1746 if (__i >= size()) |
1887 __base::__throw_out_of_range(); | 1747 _VSTD::__throw_out_of_range("deque"); |
1888 size_type __p = __base::__start_ + __i; | 1748 size_type __p = __start_ + __i; |
1889 return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); | 1749 return *(*(__map_.begin() + __p / __block_size) + __p % __block_size); |
1890 } | 1750 } |
1891 | 1751 |
1892 template <class _Tp, class _Allocator> | 1752 template <class _Tp, class _Allocator> |
1893 inline | 1753 inline |
1894 typename deque<_Tp, _Allocator>::reference | 1754 typename deque<_Tp, _Allocator>::reference |
1895 deque<_Tp, _Allocator>::front() _NOEXCEPT | 1755 deque<_Tp, _Allocator>::front() _NOEXCEPT |
1896 { | 1756 { |
1897 return *(*(__base::__map_.begin() + __base::__start_ / __base::__block_size) | 1757 return *(*(__map_.begin() + __start_ / __block_size) |
1898 + __base::__start_ % __base::__block_size); | 1758 + __start_ % __block_size); |
1899 } | 1759 } |
1900 | 1760 |
1901 template <class _Tp, class _Allocator> | 1761 template <class _Tp, class _Allocator> |
1902 inline | 1762 inline |
1903 typename deque<_Tp, _Allocator>::const_reference | 1763 typename deque<_Tp, _Allocator>::const_reference |
1904 deque<_Tp, _Allocator>::front() const _NOEXCEPT | 1764 deque<_Tp, _Allocator>::front() const _NOEXCEPT |
1905 { | 1765 { |
1906 return *(*(__base::__map_.begin() + __base::__start_ / __base::__block_size) | 1766 return *(*(__map_.begin() + __start_ / __block_size) |
1907 + __base::__start_ % __base::__block_size); | 1767 + __start_ % __block_size); |
1908 } | 1768 } |
1909 | 1769 |
1910 template <class _Tp, class _Allocator> | 1770 template <class _Tp, class _Allocator> |
1911 inline | 1771 inline |
1912 typename deque<_Tp, _Allocator>::reference | 1772 typename deque<_Tp, _Allocator>::reference |
1913 deque<_Tp, _Allocator>::back() _NOEXCEPT | 1773 deque<_Tp, _Allocator>::back() _NOEXCEPT |
1914 { | 1774 { |
1915 size_type __p = __base::size() + __base::__start_ - 1; | 1775 size_type __p = size() + __start_ - 1; |
1916 return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); | 1776 return *(*(__map_.begin() + __p / __block_size) + __p % __block_size); |
1917 } | 1777 } |
1918 | 1778 |
1919 template <class _Tp, class _Allocator> | 1779 template <class _Tp, class _Allocator> |
1920 inline | 1780 inline |
1921 typename deque<_Tp, _Allocator>::const_reference | 1781 typename deque<_Tp, _Allocator>::const_reference |
1922 deque<_Tp, _Allocator>::back() const _NOEXCEPT | 1782 deque<_Tp, _Allocator>::back() const _NOEXCEPT |
1923 { | 1783 { |
1924 size_type __p = __base::size() + __base::__start_ - 1; | 1784 size_type __p = size() + __start_ - 1; |
1925 return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size); | 1785 return *(*(__map_.begin() + __p / __block_size) + __p % __block_size); |
1926 } | 1786 } |
1927 | 1787 |
1928 template <class _Tp, class _Allocator> | 1788 template <class _Tp, class _Allocator> |
1929 void | 1789 void |
1930 deque<_Tp, _Allocator>::push_back(const value_type& __v) | 1790 deque<_Tp, _Allocator>::push_back(const value_type& __v) |
1931 { | 1791 { |
1932 allocator_type& __a = __base::__alloc(); | 1792 allocator_type& __a = __alloc(); |
1933 if (__back_spare() == 0) | 1793 if (__back_spare() == 0) |
1934 __add_back_capacity(); | 1794 __add_back_capacity(); |
1935 // __back_spare() >= 1 | 1795 // __back_spare() >= 1 |
1936 __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), __v); | 1796 __alloc_traits::construct(__a, _VSTD::addressof(*end()), __v); |
1937 ++__base::size(); | 1797 ++__size(); |
1938 } | 1798 } |
1939 | 1799 |
1940 template <class _Tp, class _Allocator> | 1800 template <class _Tp, class _Allocator> |
1941 void | 1801 void |
1942 deque<_Tp, _Allocator>::push_front(const value_type& __v) | 1802 deque<_Tp, _Allocator>::push_front(const value_type& __v) |
1943 { | 1803 { |
1944 allocator_type& __a = __base::__alloc(); | 1804 allocator_type& __a = __alloc(); |
1945 if (__front_spare() == 0) | 1805 if (__front_spare() == 0) |
1946 __add_front_capacity(); | 1806 __add_front_capacity(); |
1947 // __front_spare() >= 1 | 1807 // __front_spare() >= 1 |
1948 __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), __v); | 1808 __alloc_traits::construct(__a, _VSTD::addressof(*--begin()), __v); |
1949 --__base::__start_; | 1809 --__start_; |
1950 ++__base::size(); | 1810 ++__size(); |
1951 } | 1811 } |
1952 | 1812 |
1953 #ifndef _LIBCPP_CXX03_LANG | 1813 #ifndef _LIBCPP_CXX03_LANG |
1954 template <class _Tp, class _Allocator> | 1814 template <class _Tp, class _Allocator> |
1955 void | 1815 void |
1956 deque<_Tp, _Allocator>::push_back(value_type&& __v) | 1816 deque<_Tp, _Allocator>::push_back(value_type&& __v) |
1957 { | 1817 { |
1958 allocator_type& __a = __base::__alloc(); | 1818 allocator_type& __a = __alloc(); |
1959 if (__back_spare() == 0) | 1819 if (__back_spare() == 0) |
1960 __add_back_capacity(); | 1820 __add_back_capacity(); |
1961 // __back_spare() >= 1 | 1821 // __back_spare() >= 1 |
1962 __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::move(__v)); | 1822 __alloc_traits::construct(__a, _VSTD::addressof(*end()), _VSTD::move(__v)); |
1963 ++__base::size(); | 1823 ++__size(); |
1964 } | 1824 } |
1965 | 1825 |
1966 template <class _Tp, class _Allocator> | 1826 template <class _Tp, class _Allocator> |
1967 template <class... _Args> | 1827 template <class... _Args> |
1968 #if _LIBCPP_STD_VER > 14 | 1828 #if _LIBCPP_STD_VER > 14 |
1970 #else | 1830 #else |
1971 void | 1831 void |
1972 #endif | 1832 #endif |
1973 deque<_Tp, _Allocator>::emplace_back(_Args&&... __args) | 1833 deque<_Tp, _Allocator>::emplace_back(_Args&&... __args) |
1974 { | 1834 { |
1975 allocator_type& __a = __base::__alloc(); | 1835 allocator_type& __a = __alloc(); |
1976 if (__back_spare() == 0) | 1836 if (__back_spare() == 0) |
1977 __add_back_capacity(); | 1837 __add_back_capacity(); |
1978 // __back_spare() >= 1 | 1838 // __back_spare() >= 1 |
1979 __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), | 1839 __alloc_traits::construct(__a, _VSTD::addressof(*end()), |
1980 _VSTD::forward<_Args>(__args)...); | 1840 _VSTD::forward<_Args>(__args)...); |
1981 ++__base::size(); | 1841 ++__size(); |
1982 #if _LIBCPP_STD_VER > 14 | 1842 #if _LIBCPP_STD_VER > 14 |
1983 return *--__base::end(); | 1843 return *--end(); |
1984 #endif | 1844 #endif |
1985 } | 1845 } |
1986 | 1846 |
1987 template <class _Tp, class _Allocator> | 1847 template <class _Tp, class _Allocator> |
1988 void | 1848 void |
1989 deque<_Tp, _Allocator>::push_front(value_type&& __v) | 1849 deque<_Tp, _Allocator>::push_front(value_type&& __v) |
1990 { | 1850 { |
1991 allocator_type& __a = __base::__alloc(); | 1851 allocator_type& __a = __alloc(); |
1992 if (__front_spare() == 0) | 1852 if (__front_spare() == 0) |
1993 __add_front_capacity(); | 1853 __add_front_capacity(); |
1994 // __front_spare() >= 1 | 1854 // __front_spare() >= 1 |
1995 __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::move(__v)); | 1855 __alloc_traits::construct(__a, _VSTD::addressof(*--begin()), _VSTD::move(__v)); |
1996 --__base::__start_; | 1856 --__start_; |
1997 ++__base::size(); | 1857 ++__size(); |
1998 } | 1858 } |
1999 | 1859 |
2000 | 1860 |
2001 template <class _Tp, class _Allocator> | 1861 template <class _Tp, class _Allocator> |
2002 template <class... _Args> | 1862 template <class... _Args> |
2005 #else | 1865 #else |
2006 void | 1866 void |
2007 #endif | 1867 #endif |
2008 deque<_Tp, _Allocator>::emplace_front(_Args&&... __args) | 1868 deque<_Tp, _Allocator>::emplace_front(_Args&&... __args) |
2009 { | 1869 { |
2010 allocator_type& __a = __base::__alloc(); | 1870 allocator_type& __a = __alloc(); |
2011 if (__front_spare() == 0) | 1871 if (__front_spare() == 0) |
2012 __add_front_capacity(); | 1872 __add_front_capacity(); |
2013 // __front_spare() >= 1 | 1873 // __front_spare() >= 1 |
2014 __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::forward<_Args>(__args)...); | 1874 __alloc_traits::construct(__a, _VSTD::addressof(*--begin()), _VSTD::forward<_Args>(__args)...); |
2015 --__base::__start_; | 1875 --__start_; |
2016 ++__base::size(); | 1876 ++__size(); |
2017 #if _LIBCPP_STD_VER > 14 | 1877 #if _LIBCPP_STD_VER > 14 |
2018 return *__base::begin(); | 1878 return *begin(); |
2019 #endif | 1879 #endif |
2020 } | 1880 } |
2021 | 1881 |
2022 template <class _Tp, class _Allocator> | 1882 template <class _Tp, class _Allocator> |
2023 typename deque<_Tp, _Allocator>::iterator | 1883 typename deque<_Tp, _Allocator>::iterator |
2024 deque<_Tp, _Allocator>::insert(const_iterator __p, value_type&& __v) | 1884 deque<_Tp, _Allocator>::insert(const_iterator __p, value_type&& __v) |
2025 { | 1885 { |
2026 size_type __pos = __p - __base::begin(); | 1886 size_type __pos = __p - begin(); |
2027 size_type __to_end = __base::size() - __pos; | 1887 size_type __to_end = size() - __pos; |
2028 allocator_type& __a = __base::__alloc(); | 1888 allocator_type& __a = __alloc(); |
2029 if (__pos < __to_end) | 1889 if (__pos < __to_end) |
2030 { // insert by shifting things backward | 1890 { // insert by shifting things backward |
2031 if (__front_spare() == 0) | 1891 if (__front_spare() == 0) |
2032 __add_front_capacity(); | 1892 __add_front_capacity(); |
2033 // __front_spare() >= 1 | 1893 // __front_spare() >= 1 |
2034 if (__pos == 0) | 1894 if (__pos == 0) |
2035 { | 1895 { |
2036 __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::move(__v)); | 1896 __alloc_traits::construct(__a, _VSTD::addressof(*--begin()), _VSTD::move(__v)); |
2037 --__base::__start_; | 1897 --__start_; |
2038 ++__base::size(); | 1898 ++__size(); |
2039 } | 1899 } |
2040 else | 1900 else |
2041 { | 1901 { |
2042 iterator __b = __base::begin(); | 1902 iterator __b = begin(); |
2043 iterator __bm1 = _VSTD::prev(__b); | 1903 iterator __bm1 = _VSTD::prev(__b); |
2044 __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b)); | 1904 __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b)); |
2045 --__base::__start_; | 1905 --__start_; |
2046 ++__base::size(); | 1906 ++__size(); |
2047 if (__pos > 1) | 1907 if (__pos > 1) |
2048 __b = _VSTD::move(_VSTD::next(__b), __b + __pos, __b); | 1908 __b = _VSTD::move(_VSTD::next(__b), __b + __pos, __b); |
2049 *__b = _VSTD::move(__v); | 1909 *__b = _VSTD::move(__v); |
2050 } | 1910 } |
2051 } | 1911 } |
2052 else | 1912 else |
2053 { // insert by shifting things forward | 1913 { // insert by shifting things forward |
2054 if (__back_spare() == 0) | 1914 if (__back_spare() == 0) |
2055 __add_back_capacity(); | 1915 __add_back_capacity(); |
2056 // __back_capacity >= 1 | 1916 // __back_capacity >= 1 |
2057 size_type __de = __base::size() - __pos; | 1917 size_type __de = size() - __pos; |
2058 if (__de == 0) | 1918 if (__de == 0) |
2059 { | 1919 { |
2060 __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::move(__v)); | 1920 __alloc_traits::construct(__a, _VSTD::addressof(*end()), _VSTD::move(__v)); |
2061 ++__base::size(); | 1921 ++__size(); |
2062 } | 1922 } |
2063 else | 1923 else |
2064 { | 1924 { |
2065 iterator __e = __base::end(); | 1925 iterator __e = end(); |
2066 iterator __em1 = _VSTD::prev(__e); | 1926 iterator __em1 = _VSTD::prev(__e); |
2067 __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1)); | 1927 __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1)); |
2068 ++__base::size(); | 1928 ++__size(); |
2069 if (__de > 1) | 1929 if (__de > 1) |
2070 __e = _VSTD::move_backward(__e - __de, __em1, __e); | 1930 __e = _VSTD::move_backward(__e - __de, __em1, __e); |
2071 *--__e = _VSTD::move(__v); | 1931 *--__e = _VSTD::move(__v); |
2072 } | 1932 } |
2073 } | 1933 } |
2074 return __base::begin() + __pos; | 1934 return begin() + __pos; |
2075 } | 1935 } |
2076 | 1936 |
2077 template <class _Tp, class _Allocator> | 1937 template <class _Tp, class _Allocator> |
2078 template <class... _Args> | 1938 template <class... _Args> |
2079 typename deque<_Tp, _Allocator>::iterator | 1939 typename deque<_Tp, _Allocator>::iterator |
2080 deque<_Tp, _Allocator>::emplace(const_iterator __p, _Args&&... __args) | 1940 deque<_Tp, _Allocator>::emplace(const_iterator __p, _Args&&... __args) |
2081 { | 1941 { |
2082 size_type __pos = __p - __base::begin(); | 1942 size_type __pos = __p - begin(); |
2083 size_type __to_end = __base::size() - __pos; | 1943 size_type __to_end = size() - __pos; |
2084 allocator_type& __a = __base::__alloc(); | 1944 allocator_type& __a = __alloc(); |
2085 if (__pos < __to_end) | 1945 if (__pos < __to_end) |
2086 { // insert by shifting things backward | 1946 { // insert by shifting things backward |
2087 if (__front_spare() == 0) | 1947 if (__front_spare() == 0) |
2088 __add_front_capacity(); | 1948 __add_front_capacity(); |
2089 // __front_spare() >= 1 | 1949 // __front_spare() >= 1 |
2090 if (__pos == 0) | 1950 if (__pos == 0) |
2091 { | 1951 { |
2092 __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::forward<_Args>(__args)...); | 1952 __alloc_traits::construct(__a, _VSTD::addressof(*--begin()), _VSTD::forward<_Args>(__args)...); |
2093 --__base::__start_; | 1953 --__start_; |
2094 ++__base::size(); | 1954 ++__size(); |
2095 } | 1955 } |
2096 else | 1956 else |
2097 { | 1957 { |
2098 __temp_value<value_type, _Allocator> __tmp(this->__alloc(), _VSTD::forward<_Args>(__args)...); | 1958 __temp_value<value_type, _Allocator> __tmp(__alloc(), _VSTD::forward<_Args>(__args)...); |
2099 iterator __b = __base::begin(); | 1959 iterator __b = begin(); |
2100 iterator __bm1 = _VSTD::prev(__b); | 1960 iterator __bm1 = _VSTD::prev(__b); |
2101 __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b)); | 1961 __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b)); |
2102 --__base::__start_; | 1962 --__start_; |
2103 ++__base::size(); | 1963 ++__size(); |
2104 if (__pos > 1) | 1964 if (__pos > 1) |
2105 __b = _VSTD::move(_VSTD::next(__b), __b + __pos, __b); | 1965 __b = _VSTD::move(_VSTD::next(__b), __b + __pos, __b); |
2106 *__b = _VSTD::move(__tmp.get()); | 1966 *__b = _VSTD::move(__tmp.get()); |
2107 } | 1967 } |
2108 } | 1968 } |
2109 else | 1969 else |
2110 { // insert by shifting things forward | 1970 { // insert by shifting things forward |
2111 if (__back_spare() == 0) | 1971 if (__back_spare() == 0) |
2112 __add_back_capacity(); | 1972 __add_back_capacity(); |
2113 // __back_capacity >= 1 | 1973 // __back_capacity >= 1 |
2114 size_type __de = __base::size() - __pos; | 1974 size_type __de = size() - __pos; |
2115 if (__de == 0) | 1975 if (__de == 0) |
2116 { | 1976 { |
2117 __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::forward<_Args>(__args)...); | 1977 __alloc_traits::construct(__a, _VSTD::addressof(*end()), _VSTD::forward<_Args>(__args)...); |
2118 ++__base::size(); | 1978 ++__size(); |
2119 } | 1979 } |
2120 else | 1980 else |
2121 { | 1981 { |
2122 __temp_value<value_type, _Allocator> __tmp(this->__alloc(), _VSTD::forward<_Args>(__args)...); | 1982 __temp_value<value_type, _Allocator> __tmp(__alloc(), _VSTD::forward<_Args>(__args)...); |
2123 iterator __e = __base::end(); | 1983 iterator __e = end(); |
2124 iterator __em1 = _VSTD::prev(__e); | 1984 iterator __em1 = _VSTD::prev(__e); |
2125 __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1)); | 1985 __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1)); |
2126 ++__base::size(); | 1986 ++__size(); |
2127 if (__de > 1) | 1987 if (__de > 1) |
2128 __e = _VSTD::move_backward(__e - __de, __em1, __e); | 1988 __e = _VSTD::move_backward(__e - __de, __em1, __e); |
2129 *--__e = _VSTD::move(__tmp.get()); | 1989 *--__e = _VSTD::move(__tmp.get()); |
2130 } | 1990 } |
2131 } | 1991 } |
2132 return __base::begin() + __pos; | 1992 return begin() + __pos; |
2133 } | 1993 } |
2134 | 1994 |
2135 #endif // _LIBCPP_CXX03_LANG | 1995 #endif // _LIBCPP_CXX03_LANG |
2136 | 1996 |
2137 | 1997 |
2138 template <class _Tp, class _Allocator> | 1998 template <class _Tp, class _Allocator> |
2139 typename deque<_Tp, _Allocator>::iterator | 1999 typename deque<_Tp, _Allocator>::iterator |
2140 deque<_Tp, _Allocator>::insert(const_iterator __p, const value_type& __v) | 2000 deque<_Tp, _Allocator>::insert(const_iterator __p, const value_type& __v) |
2141 { | 2001 { |
2142 size_type __pos = __p - __base::begin(); | 2002 size_type __pos = __p - begin(); |
2143 size_type __to_end = __base::size() - __pos; | 2003 size_type __to_end = size() - __pos; |
2144 allocator_type& __a = __base::__alloc(); | 2004 allocator_type& __a = __alloc(); |
2145 if (__pos < __to_end) | 2005 if (__pos < __to_end) |
2146 { // insert by shifting things backward | 2006 { // insert by shifting things backward |
2147 if (__front_spare() == 0) | 2007 if (__front_spare() == 0) |
2148 __add_front_capacity(); | 2008 __add_front_capacity(); |
2149 // __front_spare() >= 1 | 2009 // __front_spare() >= 1 |
2150 if (__pos == 0) | 2010 if (__pos == 0) |
2151 { | 2011 { |
2152 __alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), __v); | 2012 __alloc_traits::construct(__a, _VSTD::addressof(*--begin()), __v); |
2153 --__base::__start_; | 2013 --__start_; |
2154 ++__base::size(); | 2014 ++__size(); |
2155 } | 2015 } |
2156 else | 2016 else |
2157 { | 2017 { |
2158 const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v); | 2018 const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v); |
2159 iterator __b = __base::begin(); | 2019 iterator __b = begin(); |
2160 iterator __bm1 = _VSTD::prev(__b); | 2020 iterator __bm1 = _VSTD::prev(__b); |
2161 if (__vt == pointer_traits<const_pointer>::pointer_to(*__b)) | 2021 if (__vt == pointer_traits<const_pointer>::pointer_to(*__b)) |
2162 __vt = pointer_traits<const_pointer>::pointer_to(*__bm1); | 2022 __vt = pointer_traits<const_pointer>::pointer_to(*__bm1); |
2163 __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b)); | 2023 __alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b)); |
2164 --__base::__start_; | 2024 --__start_; |
2165 ++__base::size(); | 2025 ++__size(); |
2166 if (__pos > 1) | 2026 if (__pos > 1) |
2167 __b = __move_and_check(_VSTD::next(__b), __b + __pos, __b, __vt); | 2027 __b = __move_and_check(_VSTD::next(__b), __b + __pos, __b, __vt); |
2168 *__b = *__vt; | 2028 *__b = *__vt; |
2169 } | 2029 } |
2170 } | 2030 } |
2171 else | 2031 else |
2172 { // insert by shifting things forward | 2032 { // insert by shifting things forward |
2173 if (__back_spare() == 0) | 2033 if (__back_spare() == 0) |
2174 __add_back_capacity(); | 2034 __add_back_capacity(); |
2175 // __back_capacity >= 1 | 2035 // __back_capacity >= 1 |
2176 size_type __de = __base::size() - __pos; | 2036 size_type __de = size() - __pos; |
2177 if (__de == 0) | 2037 if (__de == 0) |
2178 { | 2038 { |
2179 __alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), __v); | 2039 __alloc_traits::construct(__a, _VSTD::addressof(*end()), __v); |
2180 ++__base::size(); | 2040 ++__size(); |
2181 } | 2041 } |
2182 else | 2042 else |
2183 { | 2043 { |
2184 const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v); | 2044 const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v); |
2185 iterator __e = __base::end(); | 2045 iterator __e = end(); |
2186 iterator __em1 = _VSTD::prev(__e); | 2046 iterator __em1 = _VSTD::prev(__e); |
2187 if (__vt == pointer_traits<const_pointer>::pointer_to(*__em1)) | 2047 if (__vt == pointer_traits<const_pointer>::pointer_to(*__em1)) |
2188 __vt = pointer_traits<const_pointer>::pointer_to(*__e); | 2048 __vt = pointer_traits<const_pointer>::pointer_to(*__e); |
2189 __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1)); | 2049 __alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1)); |
2190 ++__base::size(); | 2050 ++__size(); |
2191 if (__de > 1) | 2051 if (__de > 1) |
2192 __e = __move_backward_and_check(__e - __de, __em1, __e, __vt); | 2052 __e = __move_backward_and_check(__e - __de, __em1, __e, __vt); |
2193 *--__e = *__vt; | 2053 *--__e = *__vt; |
2194 } | 2054 } |
2195 } | 2055 } |
2196 return __base::begin() + __pos; | 2056 return begin() + __pos; |
2197 } | 2057 } |
2198 | 2058 |
2199 template <class _Tp, class _Allocator> | 2059 template <class _Tp, class _Allocator> |
2200 typename deque<_Tp, _Allocator>::iterator | 2060 typename deque<_Tp, _Allocator>::iterator |
2201 deque<_Tp, _Allocator>::insert(const_iterator __p, size_type __n, const value_type& __v) | 2061 deque<_Tp, _Allocator>::insert(const_iterator __p, size_type __n, const value_type& __v) |
2202 { | 2062 { |
2203 size_type __pos = __p - __base::begin(); | 2063 size_type __pos = __p - begin(); |
2204 size_type __to_end = __base::size() - __pos; | 2064 size_type __to_end = __size() - __pos; |
2205 allocator_type& __a = __base::__alloc(); | 2065 allocator_type& __a = __alloc(); |
2206 if (__pos < __to_end) | 2066 if (__pos < __to_end) |
2207 { // insert by shifting things backward | 2067 { // insert by shifting things backward |
2208 if (__n > __front_spare()) | 2068 if (__n > __front_spare()) |
2209 __add_front_capacity(__n - __front_spare()); | 2069 __add_front_capacity(__n - __front_spare()); |
2210 // __n <= __front_spare() | 2070 // __n <= __front_spare() |
2211 iterator __old_begin = __base::begin(); | 2071 iterator __old_begin = begin(); |
2212 iterator __i = __old_begin; | 2072 iterator __i = __old_begin; |
2213 if (__n > __pos) | 2073 if (__n > __pos) |
2214 { | 2074 { |
2215 for (size_type __m = __n - __pos; __m; --__m, --__base::__start_, ++__base::size()) | 2075 for (size_type __m = __n - __pos; __m; --__m, --__start_, ++__size()) |
2216 __alloc_traits::construct(__a, _VSTD::addressof(*--__i), __v); | 2076 __alloc_traits::construct(__a, _VSTD::addressof(*--__i), __v); |
2217 __n = __pos; | 2077 __n = __pos; |
2218 } | 2078 } |
2219 if (__n > 0) | 2079 if (__n > 0) |
2220 { | 2080 { |
2230 { // insert by shifting things forward | 2090 { // insert by shifting things forward |
2231 size_type __back_capacity = __back_spare(); | 2091 size_type __back_capacity = __back_spare(); |
2232 if (__n > __back_capacity) | 2092 if (__n > __back_capacity) |
2233 __add_back_capacity(__n - __back_capacity); | 2093 __add_back_capacity(__n - __back_capacity); |
2234 // __n <= __back_capacity | 2094 // __n <= __back_capacity |
2235 iterator __old_end = __base::end(); | 2095 iterator __old_end = end(); |
2236 iterator __i = __old_end; | 2096 iterator __i = __old_end; |
2237 size_type __de = __base::size() - __pos; | 2097 size_type __de = size() - __pos; |
2238 if (__n > __de) | 2098 if (__n > __de) |
2239 { | 2099 { |
2240 for (size_type __m = __n - __de; __m; --__m, ++__i, ++__base::size()) | 2100 for (size_type __m = __n - __de; __m; --__m, (void) ++__i, ++__size()) |
2241 __alloc_traits::construct(__a, _VSTD::addressof(*__i), __v); | 2101 __alloc_traits::construct(__a, _VSTD::addressof(*__i), __v); |
2242 __n = __de; | 2102 __n = __de; |
2243 } | 2103 } |
2244 if (__n > 0) | 2104 if (__n > 0) |
2245 { | 2105 { |
2249 if (__n < __de) | 2109 if (__n < __de) |
2250 __old_end = __move_backward_and_check(__old_end - __de, __oen, __old_end, __vt); | 2110 __old_end = __move_backward_and_check(__old_end - __de, __oen, __old_end, __vt); |
2251 _VSTD::fill_n(__old_end - __n, __n, *__vt); | 2111 _VSTD::fill_n(__old_end - __n, __n, *__vt); |
2252 } | 2112 } |
2253 } | 2113 } |
2254 return __base::begin() + __pos; | 2114 return begin() + __pos; |
2255 } | 2115 } |
2256 | 2116 |
2257 template <class _Tp, class _Allocator> | 2117 template <class _Tp, class _Allocator> |
2258 template <class _InputIter> | 2118 template <class _InputIter> |
2259 typename deque<_Tp, _Allocator>::iterator | 2119 typename deque<_Tp, _Allocator>::iterator |
2260 deque<_Tp, _Allocator>::insert(const_iterator __p, _InputIter __f, _InputIter __l, | 2120 deque<_Tp, _Allocator>::insert(const_iterator __p, _InputIter __f, _InputIter __l, |
2261 typename enable_if<__is_cpp17_input_iterator<_InputIter>::value | 2121 typename enable_if<__is_exactly_cpp17_input_iterator<_InputIter>::value>::type*) |
2262 &&!__is_cpp17_forward_iterator<_InputIter>::value>::type*) | 2122 { |
2263 { | 2123 __split_buffer<value_type, allocator_type&> __buf(__alloc()); |
2264 __split_buffer<value_type, allocator_type&> __buf(__base::__alloc()); | |
2265 __buf.__construct_at_end(__f, __l); | 2124 __buf.__construct_at_end(__f, __l); |
2266 typedef typename __split_buffer<value_type, allocator_type&>::iterator __bi; | 2125 typedef typename __split_buffer<value_type, allocator_type&>::iterator __bi; |
2267 return insert(__p, move_iterator<__bi>(__buf.begin()), move_iterator<__bi>(__buf.end())); | 2126 return insert(__p, move_iterator<__bi>(__buf.begin()), move_iterator<__bi>(__buf.end())); |
2268 } | 2127 } |
2269 | 2128 |
2270 template <class _Tp, class _Allocator> | 2129 template <class _Tp, class _Allocator> |
2271 template <class _ForwardIterator> | 2130 template <class _ForwardIterator> |
2272 typename deque<_Tp, _Allocator>::iterator | 2131 typename deque<_Tp, _Allocator>::iterator |
2273 deque<_Tp, _Allocator>::insert(const_iterator __p, _ForwardIterator __f, _ForwardIterator __l, | 2132 deque<_Tp, _Allocator>::insert(const_iterator __p, _ForwardIterator __f, _ForwardIterator __l, |
2274 typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value | 2133 typename enable_if<__is_exactly_cpp17_forward_iterator<_ForwardIterator>::value>::type*) |
2275 &&!__is_cpp17_bidirectional_iterator<_ForwardIterator>::value>::type*) | |
2276 { | 2134 { |
2277 size_type __n = _VSTD::distance(__f, __l); | 2135 size_type __n = _VSTD::distance(__f, __l); |
2278 __split_buffer<value_type, allocator_type&> __buf(__n, 0, __base::__alloc()); | 2136 __split_buffer<value_type, allocator_type&> __buf(__n, 0, __alloc()); |
2279 __buf.__construct_at_end(__f, __l); | 2137 __buf.__construct_at_end(__f, __l); |
2280 typedef typename __split_buffer<value_type, allocator_type&>::iterator __fwd; | 2138 typedef typename __split_buffer<value_type, allocator_type&>::iterator __fwd; |
2281 return insert(__p, move_iterator<__fwd>(__buf.begin()), move_iterator<__fwd>(__buf.end())); | 2139 return insert(__p, move_iterator<__fwd>(__buf.begin()), move_iterator<__fwd>(__buf.end())); |
2282 } | 2140 } |
2283 | 2141 |
2286 typename deque<_Tp, _Allocator>::iterator | 2144 typename deque<_Tp, _Allocator>::iterator |
2287 deque<_Tp, _Allocator>::insert(const_iterator __p, _BiIter __f, _BiIter __l, | 2145 deque<_Tp, _Allocator>::insert(const_iterator __p, _BiIter __f, _BiIter __l, |
2288 typename enable_if<__is_cpp17_bidirectional_iterator<_BiIter>::value>::type*) | 2146 typename enable_if<__is_cpp17_bidirectional_iterator<_BiIter>::value>::type*) |
2289 { | 2147 { |
2290 size_type __n = _VSTD::distance(__f, __l); | 2148 size_type __n = _VSTD::distance(__f, __l); |
2291 size_type __pos = __p - __base::begin(); | 2149 size_type __pos = __p - begin(); |
2292 size_type __to_end = __base::size() - __pos; | 2150 size_type __to_end = size() - __pos; |
2293 allocator_type& __a = __base::__alloc(); | 2151 allocator_type& __a = __alloc(); |
2294 if (__pos < __to_end) | 2152 if (__pos < __to_end) |
2295 { // insert by shifting things backward | 2153 { // insert by shifting things backward |
2296 if (__n > __front_spare()) | 2154 if (__n > __front_spare()) |
2297 __add_front_capacity(__n - __front_spare()); | 2155 __add_front_capacity(__n - __front_spare()); |
2298 // __n <= __front_spare() | 2156 // __n <= __front_spare() |
2299 iterator __old_begin = __base::begin(); | 2157 iterator __old_begin = begin(); |
2300 iterator __i = __old_begin; | 2158 iterator __i = __old_begin; |
2301 _BiIter __m = __f; | 2159 _BiIter __m = __f; |
2302 if (__n > __pos) | 2160 if (__n > __pos) |
2303 { | 2161 { |
2304 __m = __pos < __n / 2 ? _VSTD::prev(__l, __pos) : _VSTD::next(__f, __n - __pos); | 2162 __m = __pos < __n / 2 ? _VSTD::prev(__l, __pos) : _VSTD::next(__f, __n - __pos); |
2305 for (_BiIter __j = __m; __j != __f; --__base::__start_, ++__base::size()) | 2163 for (_BiIter __j = __m; __j != __f; --__start_, ++__size()) |
2306 __alloc_traits::construct(__a, _VSTD::addressof(*--__i), *--__j); | 2164 __alloc_traits::construct(__a, _VSTD::addressof(*--__i), *--__j); |
2307 __n = __pos; | 2165 __n = __pos; |
2308 } | 2166 } |
2309 if (__n > 0) | 2167 if (__n > 0) |
2310 { | 2168 { |
2311 iterator __obn = __old_begin + __n; | 2169 iterator __obn = __old_begin + __n; |
2312 for (iterator __j = __obn; __j != __old_begin;) | 2170 for (iterator __j = __obn; __j != __old_begin;) |
2313 { | 2171 { |
2314 __alloc_traits::construct(__a, _VSTD::addressof(*--__i), _VSTD::move(*--__j)); | 2172 __alloc_traits::construct(__a, _VSTD::addressof(*--__i), _VSTD::move(*--__j)); |
2315 --__base::__start_; | 2173 --__start_; |
2316 ++__base::size(); | 2174 ++__size(); |
2317 } | 2175 } |
2318 if (__n < __pos) | 2176 if (__n < __pos) |
2319 __old_begin = _VSTD::move(__obn, __old_begin + __pos, __old_begin); | 2177 __old_begin = _VSTD::move(__obn, __old_begin + __pos, __old_begin); |
2320 _VSTD::copy(__m, __l, __old_begin); | 2178 _VSTD::copy(__m, __l, __old_begin); |
2321 } | 2179 } |
2324 { // insert by shifting things forward | 2182 { // insert by shifting things forward |
2325 size_type __back_capacity = __back_spare(); | 2183 size_type __back_capacity = __back_spare(); |
2326 if (__n > __back_capacity) | 2184 if (__n > __back_capacity) |
2327 __add_back_capacity(__n - __back_capacity); | 2185 __add_back_capacity(__n - __back_capacity); |
2328 // __n <= __back_capacity | 2186 // __n <= __back_capacity |
2329 iterator __old_end = __base::end(); | 2187 iterator __old_end = end(); |
2330 iterator __i = __old_end; | 2188 iterator __i = __old_end; |
2331 _BiIter __m = __l; | 2189 _BiIter __m = __l; |
2332 size_type __de = __base::size() - __pos; | 2190 size_type __de = size() - __pos; |
2333 if (__n > __de) | 2191 if (__n > __de) |
2334 { | 2192 { |
2335 __m = __de < __n / 2 ? _VSTD::next(__f, __de) : _VSTD::prev(__l, __n - __de); | 2193 __m = __de < __n / 2 ? _VSTD::next(__f, __de) : _VSTD::prev(__l, __n - __de); |
2336 for (_BiIter __j = __m; __j != __l; ++__i, (void) ++__j, ++__base::size()) | 2194 for (_BiIter __j = __m; __j != __l; ++__i, (void) ++__j, ++__size()) |
2337 __alloc_traits::construct(__a, _VSTD::addressof(*__i), *__j); | 2195 __alloc_traits::construct(__a, _VSTD::addressof(*__i), *__j); |
2338 __n = __de; | 2196 __n = __de; |
2339 } | 2197 } |
2340 if (__n > 0) | 2198 if (__n > 0) |
2341 { | 2199 { |
2342 iterator __oen = __old_end - __n; | 2200 iterator __oen = __old_end - __n; |
2343 for (iterator __j = __oen; __j != __old_end; ++__i, ++__j, ++__base::size()) | 2201 for (iterator __j = __oen; __j != __old_end; ++__i, (void) ++__j, ++__size()) |
2344 __alloc_traits::construct(__a, _VSTD::addressof(*__i), _VSTD::move(*__j)); | 2202 __alloc_traits::construct(__a, _VSTD::addressof(*__i), _VSTD::move(*__j)); |
2345 if (__n < __de) | 2203 if (__n < __de) |
2346 __old_end = _VSTD::move_backward(__old_end - __de, __oen, __old_end); | 2204 __old_end = _VSTD::move_backward(__old_end - __de, __oen, __old_end); |
2347 _VSTD::copy_backward(__f, __m, __old_end); | 2205 _VSTD::copy_backward(__f, __m, __old_end); |
2348 } | 2206 } |
2349 } | 2207 } |
2350 return __base::begin() + __pos; | 2208 return begin() + __pos; |
2351 } | 2209 } |
2352 | 2210 |
2353 template <class _Tp, class _Allocator> | 2211 template <class _Tp, class _Allocator> |
2354 template <class _InpIter> | 2212 template <class _InpIter> |
2355 void | 2213 void |
2356 deque<_Tp, _Allocator>::__append(_InpIter __f, _InpIter __l, | 2214 deque<_Tp, _Allocator>::__append(_InpIter __f, _InpIter __l, |
2357 typename enable_if<__is_cpp17_input_iterator<_InpIter>::value && | 2215 typename enable_if<__is_exactly_cpp17_input_iterator<_InpIter>::value>::type*) |
2358 !__is_cpp17_forward_iterator<_InpIter>::value>::type*) | |
2359 { | 2216 { |
2360 for (; __f != __l; ++__f) | 2217 for (; __f != __l; ++__f) |
2361 #ifdef _LIBCPP_CXX03_LANG | 2218 #ifdef _LIBCPP_CXX03_LANG |
2362 push_back(*__f); | 2219 push_back(*__f); |
2363 #else | 2220 #else |
2370 void | 2227 void |
2371 deque<_Tp, _Allocator>::__append(_ForIter __f, _ForIter __l, | 2228 deque<_Tp, _Allocator>::__append(_ForIter __f, _ForIter __l, |
2372 typename enable_if<__is_cpp17_forward_iterator<_ForIter>::value>::type*) | 2229 typename enable_if<__is_cpp17_forward_iterator<_ForIter>::value>::type*) |
2373 { | 2230 { |
2374 size_type __n = _VSTD::distance(__f, __l); | 2231 size_type __n = _VSTD::distance(__f, __l); |
2375 allocator_type& __a = __base::__alloc(); | 2232 allocator_type& __a = __alloc(); |
2376 size_type __back_capacity = __back_spare(); | 2233 size_type __back_capacity = __back_spare(); |
2377 if (__n > __back_capacity) | 2234 if (__n > __back_capacity) |
2378 __add_back_capacity(__n - __back_capacity); | 2235 __add_back_capacity(__n - __back_capacity); |
2379 // __n <= __back_capacity | 2236 // __n <= __back_capacity |
2380 for (__deque_block_range __br : __deque_range(__base::end(), __base::end() + __n)) { | 2237 for (__deque_block_range __br : __deque_range(end(), end() + __n)) { |
2381 _ConstructTransaction __tx(this, __br); | 2238 _ConstructTransaction __tx(this, __br); |
2382 for (; __tx.__pos_ != __tx.__end_; ++__tx.__pos_, (void)++__f) { | 2239 for (; __tx.__pos_ != __tx.__end_; ++__tx.__pos_, (void)++__f) { |
2383 __alloc_traits::construct(__a, _VSTD::__to_address(__tx.__pos_), *__f); | 2240 __alloc_traits::construct(__a, _VSTD::__to_address(__tx.__pos_), *__f); |
2384 } | 2241 } |
2385 } | 2242 } |
2387 | 2244 |
2388 template <class _Tp, class _Allocator> | 2245 template <class _Tp, class _Allocator> |
2389 void | 2246 void |
2390 deque<_Tp, _Allocator>::__append(size_type __n) | 2247 deque<_Tp, _Allocator>::__append(size_type __n) |
2391 { | 2248 { |
2392 allocator_type& __a = __base::__alloc(); | 2249 allocator_type& __a = __alloc(); |
2393 size_type __back_capacity = __back_spare(); | 2250 size_type __back_capacity = __back_spare(); |
2394 if (__n > __back_capacity) | 2251 if (__n > __back_capacity) |
2395 __add_back_capacity(__n - __back_capacity); | 2252 __add_back_capacity(__n - __back_capacity); |
2396 // __n <= __back_capacity | 2253 // __n <= __back_capacity |
2397 for (__deque_block_range __br : __deque_range(__base::end(), __base::end() + __n)) { | 2254 for (__deque_block_range __br : __deque_range(end(), end() + __n)) { |
2398 _ConstructTransaction __tx(this, __br); | 2255 _ConstructTransaction __tx(this, __br); |
2399 for (; __tx.__pos_ != __tx.__end_; ++__tx.__pos_) { | 2256 for (; __tx.__pos_ != __tx.__end_; ++__tx.__pos_) { |
2400 __alloc_traits::construct(__a, _VSTD::__to_address(__tx.__pos_)); | 2257 __alloc_traits::construct(__a, _VSTD::__to_address(__tx.__pos_)); |
2401 } | 2258 } |
2402 } | 2259 } |
2404 | 2261 |
2405 template <class _Tp, class _Allocator> | 2262 template <class _Tp, class _Allocator> |
2406 void | 2263 void |
2407 deque<_Tp, _Allocator>::__append(size_type __n, const value_type& __v) | 2264 deque<_Tp, _Allocator>::__append(size_type __n, const value_type& __v) |
2408 { | 2265 { |
2409 allocator_type& __a = __base::__alloc(); | 2266 allocator_type& __a = __alloc(); |
2410 size_type __back_capacity = __back_spare(); | 2267 size_type __back_capacity = __back_spare(); |
2411 if (__n > __back_capacity) | 2268 if (__n > __back_capacity) |
2412 __add_back_capacity(__n - __back_capacity); | 2269 __add_back_capacity(__n - __back_capacity); |
2413 // __n <= __back_capacity | 2270 // __n <= __back_capacity |
2414 for (__deque_block_range __br : __deque_range(__base::end(), __base::end() + __n)) { | 2271 for (__deque_block_range __br : __deque_range(end(), end() + __n)) { |
2415 _ConstructTransaction __tx(this, __br); | 2272 _ConstructTransaction __tx(this, __br); |
2416 for (; __tx.__pos_ != __tx.__end_; ++__tx.__pos_) { | 2273 for (; __tx.__pos_ != __tx.__end_; ++__tx.__pos_) { |
2417 __alloc_traits::construct(__a, _VSTD::__to_address(__tx.__pos_), __v); | 2274 __alloc_traits::construct(__a, _VSTD::__to_address(__tx.__pos_), __v); |
2418 } | 2275 } |
2419 } | 2276 } |
2424 // Strong guarantee. Either do it or don't touch anything. | 2281 // Strong guarantee. Either do it or don't touch anything. |
2425 template <class _Tp, class _Allocator> | 2282 template <class _Tp, class _Allocator> |
2426 void | 2283 void |
2427 deque<_Tp, _Allocator>::__add_front_capacity() | 2284 deque<_Tp, _Allocator>::__add_front_capacity() |
2428 { | 2285 { |
2429 allocator_type& __a = __base::__alloc(); | 2286 allocator_type& __a = __alloc(); |
2430 if (__back_spare() >= __base::__block_size) | 2287 if (__back_spare() >= __block_size) |
2431 { | 2288 { |
2432 __base::__start_ += __base::__block_size; | 2289 __start_ += __block_size; |
2433 pointer __pt = __base::__map_.back(); | 2290 pointer __pt = __map_.back(); |
2434 __base::__map_.pop_back(); | 2291 __map_.pop_back(); |
2435 __base::__map_.push_front(__pt); | 2292 __map_.push_front(__pt); |
2436 } | 2293 } |
2437 // Else if __base::__map_.size() < __base::__map_.capacity() then we need to allocate 1 buffer | 2294 // Else if __map_.size() < __map_.capacity() then we need to allocate 1 buffer |
2438 else if (__base::__map_.size() < __base::__map_.capacity()) | 2295 else if (__map_.size() < __map_.capacity()) |
2439 { // we can put the new buffer into the map, but don't shift things around | 2296 { // we can put the new buffer into the map, but don't shift things around |
2440 // until all buffers are allocated. If we throw, we don't need to fix | 2297 // until all buffers are allocated. If we throw, we don't need to fix |
2441 // anything up (any added buffers are undetectible) | 2298 // anything up (any added buffers are undetectible) |
2442 if (__base::__map_.__front_spare() > 0) | 2299 if (__map_.__front_spare() > 0) |
2443 __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size)); | 2300 __map_.push_front(__alloc_traits::allocate(__a, __block_size)); |
2444 else | 2301 else |
2445 { | 2302 { |
2446 __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size)); | 2303 __map_.push_back(__alloc_traits::allocate(__a, __block_size)); |
2447 // Done allocating, reorder capacity | 2304 // Done allocating, reorder capacity |
2448 pointer __pt = __base::__map_.back(); | 2305 pointer __pt = __map_.back(); |
2449 __base::__map_.pop_back(); | 2306 __map_.pop_back(); |
2450 __base::__map_.push_front(__pt); | 2307 __map_.push_front(__pt); |
2451 } | 2308 } |
2452 __base::__start_ = __base::__map_.size() == 1 ? | 2309 __start_ = __map_.size() == 1 ? |
2453 __base::__block_size / 2 : | 2310 __block_size / 2 : |
2454 __base::__start_ + __base::__block_size; | 2311 __start_ + __block_size; |
2455 } | 2312 } |
2456 // Else need to allocate 1 buffer, *and* we need to reallocate __map_. | 2313 // Else need to allocate 1 buffer, *and* we need to reallocate __map_. |
2457 else | 2314 else |
2458 { | 2315 { |
2459 __split_buffer<pointer, typename __base::__pointer_allocator&> | 2316 __split_buffer<pointer, __pointer_allocator&> |
2460 __buf(max<size_type>(2 * __base::__map_.capacity(), 1), | 2317 __buf(max<size_type>(2 * __map_.capacity(), 1), |
2461 0, __base::__map_.__alloc()); | 2318 0, __map_.__alloc()); |
2462 | 2319 |
2463 typedef __allocator_destructor<_Allocator> _Dp; | 2320 typedef __allocator_destructor<_Allocator> _Dp; |
2464 unique_ptr<pointer, _Dp> __hold( | 2321 unique_ptr<pointer, _Dp> __hold( |
2465 __alloc_traits::allocate(__a, __base::__block_size), | 2322 __alloc_traits::allocate(__a, __block_size), |
2466 _Dp(__a, __base::__block_size)); | 2323 _Dp(__a, __block_size)); |
2467 __buf.push_back(__hold.get()); | 2324 __buf.push_back(__hold.get()); |
2468 __hold.release(); | 2325 __hold.release(); |
2469 | 2326 |
2470 for (typename __base::__map_pointer __i = __base::__map_.begin(); | 2327 for (__map_pointer __i = __map_.begin(); |
2471 __i != __base::__map_.end(); ++__i) | 2328 __i != __map_.end(); ++__i) |
2472 __buf.push_back(*__i); | 2329 __buf.push_back(*__i); |
2473 _VSTD::swap(__base::__map_.__first_, __buf.__first_); | 2330 _VSTD::swap(__map_.__first_, __buf.__first_); |
2474 _VSTD::swap(__base::__map_.__begin_, __buf.__begin_); | 2331 _VSTD::swap(__map_.__begin_, __buf.__begin_); |
2475 _VSTD::swap(__base::__map_.__end_, __buf.__end_); | 2332 _VSTD::swap(__map_.__end_, __buf.__end_); |
2476 _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap()); | 2333 _VSTD::swap(__map_.__end_cap(), __buf.__end_cap()); |
2477 __base::__start_ = __base::__map_.size() == 1 ? | 2334 __start_ = __map_.size() == 1 ? |
2478 __base::__block_size / 2 : | 2335 __block_size / 2 : |
2479 __base::__start_ + __base::__block_size; | 2336 __start_ + __block_size; |
2480 } | 2337 } |
2481 } | 2338 } |
2482 | 2339 |
2483 // Create front capacity for __n elements. | 2340 // Create front capacity for __n elements. |
2484 // Strong guarantee. Either do it or don't touch anything. | 2341 // Strong guarantee. Either do it or don't touch anything. |
2485 template <class _Tp, class _Allocator> | 2342 template <class _Tp, class _Allocator> |
2486 void | 2343 void |
2487 deque<_Tp, _Allocator>::__add_front_capacity(size_type __n) | 2344 deque<_Tp, _Allocator>::__add_front_capacity(size_type __n) |
2488 { | 2345 { |
2489 allocator_type& __a = __base::__alloc(); | 2346 allocator_type& __a = __alloc(); |
2490 size_type __nb = __recommend_blocks(__n + __base::__map_.empty()); | 2347 size_type __nb = __recommend_blocks(__n + __map_.empty()); |
2491 // Number of unused blocks at back: | 2348 // Number of unused blocks at back: |
2492 size_type __back_capacity = __back_spare() / __base::__block_size; | 2349 size_type __back_capacity = __back_spare() / __block_size; |
2493 __back_capacity = _VSTD::min(__back_capacity, __nb); // don't take more than you need | 2350 __back_capacity = _VSTD::min(__back_capacity, __nb); // don't take more than you need |
2494 __nb -= __back_capacity; // number of blocks need to allocate | 2351 __nb -= __back_capacity; // number of blocks need to allocate |
2495 // If __nb == 0, then we have sufficient capacity. | 2352 // If __nb == 0, then we have sufficient capacity. |
2496 if (__nb == 0) | 2353 if (__nb == 0) |
2497 { | 2354 { |
2498 __base::__start_ += __base::__block_size * __back_capacity; | 2355 __start_ += __block_size * __back_capacity; |
2499 for (; __back_capacity > 0; --__back_capacity) | 2356 for (; __back_capacity > 0; --__back_capacity) |
2500 { | 2357 { |
2501 pointer __pt = __base::__map_.back(); | 2358 pointer __pt = __map_.back(); |
2502 __base::__map_.pop_back(); | 2359 __map_.pop_back(); |
2503 __base::__map_.push_front(__pt); | 2360 __map_.push_front(__pt); |
2504 } | 2361 } |
2505 } | 2362 } |
2506 // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers | 2363 // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers |
2507 else if (__nb <= __base::__map_.capacity() - __base::__map_.size()) | 2364 else if (__nb <= __map_.capacity() - __map_.size()) |
2508 { // we can put the new buffers into the map, but don't shift things around | 2365 { // we can put the new buffers into the map, but don't shift things around |
2509 // until all buffers are allocated. If we throw, we don't need to fix | 2366 // until all buffers are allocated. If we throw, we don't need to fix |
2510 // anything up (any added buffers are undetectible) | 2367 // anything up (any added buffers are undetectible) |
2511 for (; __nb > 0; --__nb, __base::__start_ += __base::__block_size - (__base::__map_.size() == 1)) | 2368 for (; __nb > 0; --__nb, __start_ += __block_size - (__map_.size() == 1)) |
2512 { | 2369 { |
2513 if (__base::__map_.__front_spare() == 0) | 2370 if (__map_.__front_spare() == 0) |
2514 break; | 2371 break; |
2515 __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size)); | 2372 __map_.push_front(__alloc_traits::allocate(__a, __block_size)); |
2516 } | 2373 } |
2517 for (; __nb > 0; --__nb, ++__back_capacity) | 2374 for (; __nb > 0; --__nb, ++__back_capacity) |
2518 __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size)); | 2375 __map_.push_back(__alloc_traits::allocate(__a, __block_size)); |
2519 // Done allocating, reorder capacity | 2376 // Done allocating, reorder capacity |
2520 __base::__start_ += __back_capacity * __base::__block_size; | 2377 __start_ += __back_capacity * __block_size; |
2521 for (; __back_capacity > 0; --__back_capacity) | 2378 for (; __back_capacity > 0; --__back_capacity) |
2522 { | 2379 { |
2523 pointer __pt = __base::__map_.back(); | 2380 pointer __pt = __map_.back(); |
2524 __base::__map_.pop_back(); | 2381 __map_.pop_back(); |
2525 __base::__map_.push_front(__pt); | 2382 __map_.push_front(__pt); |
2526 } | 2383 } |
2527 } | 2384 } |
2528 // Else need to allocate __nb buffers, *and* we need to reallocate __map_. | 2385 // Else need to allocate __nb buffers, *and* we need to reallocate __map_. |
2529 else | 2386 else |
2530 { | 2387 { |
2531 size_type __ds = (__nb + __back_capacity) * __base::__block_size - __base::__map_.empty(); | 2388 size_type __ds = (__nb + __back_capacity) * __block_size - __map_.empty(); |
2532 __split_buffer<pointer, typename __base::__pointer_allocator&> | 2389 __split_buffer<pointer, __pointer_allocator&> |
2533 __buf(max<size_type>(2* __base::__map_.capacity(), | 2390 __buf(max<size_type>(2* __map_.capacity(), |
2534 __nb + __base::__map_.size()), | 2391 __nb + __map_.size()), |
2535 0, __base::__map_.__alloc()); | 2392 0, __map_.__alloc()); |
2536 #ifndef _LIBCPP_NO_EXCEPTIONS | 2393 #ifndef _LIBCPP_NO_EXCEPTIONS |
2537 try | 2394 try |
2538 { | 2395 { |
2539 #endif // _LIBCPP_NO_EXCEPTIONS | 2396 #endif // _LIBCPP_NO_EXCEPTIONS |
2540 for (; __nb > 0; --__nb) | 2397 for (; __nb > 0; --__nb) |
2541 __buf.push_back(__alloc_traits::allocate(__a, __base::__block_size)); | 2398 __buf.push_back(__alloc_traits::allocate(__a, __block_size)); |
2542 #ifndef _LIBCPP_NO_EXCEPTIONS | 2399 #ifndef _LIBCPP_NO_EXCEPTIONS |
2543 } | 2400 } |
2544 catch (...) | 2401 catch (...) |
2545 { | 2402 { |
2546 for (typename __base::__map_pointer __i = __buf.begin(); | 2403 for (__map_pointer __i = __buf.begin(); |
2547 __i != __buf.end(); ++__i) | 2404 __i != __buf.end(); ++__i) |
2548 __alloc_traits::deallocate(__a, *__i, __base::__block_size); | 2405 __alloc_traits::deallocate(__a, *__i, __block_size); |
2549 throw; | 2406 throw; |
2550 } | 2407 } |
2551 #endif // _LIBCPP_NO_EXCEPTIONS | 2408 #endif // _LIBCPP_NO_EXCEPTIONS |
2552 for (; __back_capacity > 0; --__back_capacity) | 2409 for (; __back_capacity > 0; --__back_capacity) |
2553 { | 2410 { |
2554 __buf.push_back(__base::__map_.back()); | 2411 __buf.push_back(__map_.back()); |
2555 __base::__map_.pop_back(); | 2412 __map_.pop_back(); |
2556 } | 2413 } |
2557 for (typename __base::__map_pointer __i = __base::__map_.begin(); | 2414 for (__map_pointer __i = __map_.begin(); |
2558 __i != __base::__map_.end(); ++__i) | 2415 __i != __map_.end(); ++__i) |
2559 __buf.push_back(*__i); | 2416 __buf.push_back(*__i); |
2560 _VSTD::swap(__base::__map_.__first_, __buf.__first_); | 2417 _VSTD::swap(__map_.__first_, __buf.__first_); |
2561 _VSTD::swap(__base::__map_.__begin_, __buf.__begin_); | 2418 _VSTD::swap(__map_.__begin_, __buf.__begin_); |
2562 _VSTD::swap(__base::__map_.__end_, __buf.__end_); | 2419 _VSTD::swap(__map_.__end_, __buf.__end_); |
2563 _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap()); | 2420 _VSTD::swap(__map_.__end_cap(), __buf.__end_cap()); |
2564 __base::__start_ += __ds; | 2421 __start_ += __ds; |
2565 } | 2422 } |
2566 } | 2423 } |
2567 | 2424 |
2568 // Create back capacity for one block of elements. | 2425 // Create back capacity for one block of elements. |
2569 // Strong guarantee. Either do it or don't touch anything. | 2426 // Strong guarantee. Either do it or don't touch anything. |
2570 template <class _Tp, class _Allocator> | 2427 template <class _Tp, class _Allocator> |
2571 void | 2428 void |
2572 deque<_Tp, _Allocator>::__add_back_capacity() | 2429 deque<_Tp, _Allocator>::__add_back_capacity() |
2573 { | 2430 { |
2574 allocator_type& __a = __base::__alloc(); | 2431 allocator_type& __a = __alloc(); |
2575 if (__front_spare() >= __base::__block_size) | 2432 if (__front_spare() >= __block_size) |
2576 { | 2433 { |
2577 __base::__start_ -= __base::__block_size; | 2434 __start_ -= __block_size; |
2578 pointer __pt = __base::__map_.front(); | 2435 pointer __pt = __map_.front(); |
2579 __base::__map_.pop_front(); | 2436 __map_.pop_front(); |
2580 __base::__map_.push_back(__pt); | 2437 __map_.push_back(__pt); |
2581 } | 2438 } |
2582 // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers | 2439 // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers |
2583 else if (__base::__map_.size() < __base::__map_.capacity()) | 2440 else if (__map_.size() < __map_.capacity()) |
2584 { // we can put the new buffer into the map, but don't shift things around | 2441 { // we can put the new buffer into the map, but don't shift things around |
2585 // until it is allocated. If we throw, we don't need to fix | 2442 // until it is allocated. If we throw, we don't need to fix |
2586 // anything up (any added buffers are undetectible) | 2443 // anything up (any added buffers are undetectible) |
2587 if (__base::__map_.__back_spare() != 0) | 2444 if (__map_.__back_spare() != 0) |
2588 __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size)); | 2445 __map_.push_back(__alloc_traits::allocate(__a, __block_size)); |
2589 else | 2446 else |
2590 { | 2447 { |
2591 __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size)); | 2448 __map_.push_front(__alloc_traits::allocate(__a, __block_size)); |
2592 // Done allocating, reorder capacity | 2449 // Done allocating, reorder capacity |
2593 pointer __pt = __base::__map_.front(); | 2450 pointer __pt = __map_.front(); |
2594 __base::__map_.pop_front(); | 2451 __map_.pop_front(); |
2595 __base::__map_.push_back(__pt); | 2452 __map_.push_back(__pt); |
2596 } | 2453 } |
2597 } | 2454 } |
2598 // Else need to allocate 1 buffer, *and* we need to reallocate __map_. | 2455 // Else need to allocate 1 buffer, *and* we need to reallocate __map_. |
2599 else | 2456 else |
2600 { | 2457 { |
2601 __split_buffer<pointer, typename __base::__pointer_allocator&> | 2458 __split_buffer<pointer, __pointer_allocator&> |
2602 __buf(max<size_type>(2* __base::__map_.capacity(), 1), | 2459 __buf(max<size_type>(2* __map_.capacity(), 1), |
2603 __base::__map_.size(), | 2460 __map_.size(), |
2604 __base::__map_.__alloc()); | 2461 __map_.__alloc()); |
2605 | 2462 |
2606 typedef __allocator_destructor<_Allocator> _Dp; | 2463 typedef __allocator_destructor<_Allocator> _Dp; |
2607 unique_ptr<pointer, _Dp> __hold( | 2464 unique_ptr<pointer, _Dp> __hold( |
2608 __alloc_traits::allocate(__a, __base::__block_size), | 2465 __alloc_traits::allocate(__a, __block_size), |
2609 _Dp(__a, __base::__block_size)); | 2466 _Dp(__a, __block_size)); |
2610 __buf.push_back(__hold.get()); | 2467 __buf.push_back(__hold.get()); |
2611 __hold.release(); | 2468 __hold.release(); |
2612 | 2469 |
2613 for (typename __base::__map_pointer __i = __base::__map_.end(); | 2470 for (__map_pointer __i = __map_.end(); |
2614 __i != __base::__map_.begin();) | 2471 __i != __map_.begin();) |
2615 __buf.push_front(*--__i); | 2472 __buf.push_front(*--__i); |
2616 _VSTD::swap(__base::__map_.__first_, __buf.__first_); | 2473 _VSTD::swap(__map_.__first_, __buf.__first_); |
2617 _VSTD::swap(__base::__map_.__begin_, __buf.__begin_); | 2474 _VSTD::swap(__map_.__begin_, __buf.__begin_); |
2618 _VSTD::swap(__base::__map_.__end_, __buf.__end_); | 2475 _VSTD::swap(__map_.__end_, __buf.__end_); |
2619 _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap()); | 2476 _VSTD::swap(__map_.__end_cap(), __buf.__end_cap()); |
2620 } | 2477 } |
2621 } | 2478 } |
2622 | 2479 |
2623 // Create back capacity for __n elements. | 2480 // Create back capacity for __n elements. |
2624 // Strong guarantee. Either do it or don't touch anything. | 2481 // Strong guarantee. Either do it or don't touch anything. |
2625 template <class _Tp, class _Allocator> | 2482 template <class _Tp, class _Allocator> |
2626 void | 2483 void |
2627 deque<_Tp, _Allocator>::__add_back_capacity(size_type __n) | 2484 deque<_Tp, _Allocator>::__add_back_capacity(size_type __n) |
2628 { | 2485 { |
2629 allocator_type& __a = __base::__alloc(); | 2486 allocator_type& __a = __alloc(); |
2630 size_type __nb = __recommend_blocks(__n + __base::__map_.empty()); | 2487 size_type __nb = __recommend_blocks(__n + __map_.empty()); |
2631 // Number of unused blocks at front: | 2488 // Number of unused blocks at front: |
2632 size_type __front_capacity = __front_spare() / __base::__block_size; | 2489 size_type __front_capacity = __front_spare() / __block_size; |
2633 __front_capacity = _VSTD::min(__front_capacity, __nb); // don't take more than you need | 2490 __front_capacity = _VSTD::min(__front_capacity, __nb); // don't take more than you need |
2634 __nb -= __front_capacity; // number of blocks need to allocate | 2491 __nb -= __front_capacity; // number of blocks need to allocate |
2635 // If __nb == 0, then we have sufficient capacity. | 2492 // If __nb == 0, then we have sufficient capacity. |
2636 if (__nb == 0) | 2493 if (__nb == 0) |
2637 { | 2494 { |
2638 __base::__start_ -= __base::__block_size * __front_capacity; | 2495 __start_ -= __block_size * __front_capacity; |
2639 for (; __front_capacity > 0; --__front_capacity) | 2496 for (; __front_capacity > 0; --__front_capacity) |
2640 { | 2497 { |
2641 pointer __pt = __base::__map_.front(); | 2498 pointer __pt = __map_.front(); |
2642 __base::__map_.pop_front(); | 2499 __map_.pop_front(); |
2643 __base::__map_.push_back(__pt); | 2500 __map_.push_back(__pt); |
2644 } | 2501 } |
2645 } | 2502 } |
2646 // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers | 2503 // Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers |
2647 else if (__nb <= __base::__map_.capacity() - __base::__map_.size()) | 2504 else if (__nb <= __map_.capacity() - __map_.size()) |
2648 { // we can put the new buffers into the map, but don't shift things around | 2505 { // we can put the new buffers into the map, but don't shift things around |
2649 // until all buffers are allocated. If we throw, we don't need to fix | 2506 // until all buffers are allocated. If we throw, we don't need to fix |
2650 // anything up (any added buffers are undetectible) | 2507 // anything up (any added buffers are undetectible) |
2651 for (; __nb > 0; --__nb) | 2508 for (; __nb > 0; --__nb) |
2652 { | 2509 { |
2653 if (__base::__map_.__back_spare() == 0) | 2510 if (__map_.__back_spare() == 0) |
2654 break; | 2511 break; |
2655 __base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size)); | 2512 __map_.push_back(__alloc_traits::allocate(__a, __block_size)); |
2656 } | 2513 } |
2657 for (; __nb > 0; --__nb, ++__front_capacity, __base::__start_ += | 2514 for (; __nb > 0; --__nb, ++__front_capacity, __start_ += |
2658 __base::__block_size - (__base::__map_.size() == 1)) | 2515 __block_size - (__map_.size() == 1)) |
2659 __base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size)); | 2516 __map_.push_front(__alloc_traits::allocate(__a, __block_size)); |
2660 // Done allocating, reorder capacity | 2517 // Done allocating, reorder capacity |
2661 __base::__start_ -= __base::__block_size * __front_capacity; | 2518 __start_ -= __block_size * __front_capacity; |
2662 for (; __front_capacity > 0; --__front_capacity) | 2519 for (; __front_capacity > 0; --__front_capacity) |
2663 { | 2520 { |
2664 pointer __pt = __base::__map_.front(); | 2521 pointer __pt = __map_.front(); |
2665 __base::__map_.pop_front(); | 2522 __map_.pop_front(); |
2666 __base::__map_.push_back(__pt); | 2523 __map_.push_back(__pt); |
2667 } | 2524 } |
2668 } | 2525 } |
2669 // Else need to allocate __nb buffers, *and* we need to reallocate __map_. | 2526 // Else need to allocate __nb buffers, *and* we need to reallocate __map_. |
2670 else | 2527 else |
2671 { | 2528 { |
2672 size_type __ds = __front_capacity * __base::__block_size; | 2529 size_type __ds = __front_capacity * __block_size; |
2673 __split_buffer<pointer, typename __base::__pointer_allocator&> | 2530 __split_buffer<pointer, __pointer_allocator&> |
2674 __buf(max<size_type>(2* __base::__map_.capacity(), | 2531 __buf(max<size_type>(2* __map_.capacity(), |
2675 __nb + __base::__map_.size()), | 2532 __nb + __map_.size()), |
2676 __base::__map_.size() - __front_capacity, | 2533 __map_.size() - __front_capacity, |
2677 __base::__map_.__alloc()); | 2534 __map_.__alloc()); |
2678 #ifndef _LIBCPP_NO_EXCEPTIONS | 2535 #ifndef _LIBCPP_NO_EXCEPTIONS |
2679 try | 2536 try |
2680 { | 2537 { |
2681 #endif // _LIBCPP_NO_EXCEPTIONS | 2538 #endif // _LIBCPP_NO_EXCEPTIONS |
2682 for (; __nb > 0; --__nb) | 2539 for (; __nb > 0; --__nb) |
2683 __buf.push_back(__alloc_traits::allocate(__a, __base::__block_size)); | 2540 __buf.push_back(__alloc_traits::allocate(__a, __block_size)); |
2684 #ifndef _LIBCPP_NO_EXCEPTIONS | 2541 #ifndef _LIBCPP_NO_EXCEPTIONS |
2685 } | 2542 } |
2686 catch (...) | 2543 catch (...) |
2687 { | 2544 { |
2688 for (typename __base::__map_pointer __i = __buf.begin(); | 2545 for (__map_pointer __i = __buf.begin(); |
2689 __i != __buf.end(); ++__i) | 2546 __i != __buf.end(); ++__i) |
2690 __alloc_traits::deallocate(__a, *__i, __base::__block_size); | 2547 __alloc_traits::deallocate(__a, *__i, __block_size); |
2691 throw; | 2548 throw; |
2692 } | 2549 } |
2693 #endif // _LIBCPP_NO_EXCEPTIONS | 2550 #endif // _LIBCPP_NO_EXCEPTIONS |
2694 for (; __front_capacity > 0; --__front_capacity) | 2551 for (; __front_capacity > 0; --__front_capacity) |
2695 { | 2552 { |
2696 __buf.push_back(__base::__map_.front()); | 2553 __buf.push_back(__map_.front()); |
2697 __base::__map_.pop_front(); | 2554 __map_.pop_front(); |
2698 } | 2555 } |
2699 for (typename __base::__map_pointer __i = __base::__map_.end(); | 2556 for (__map_pointer __i = __map_.end(); |
2700 __i != __base::__map_.begin();) | 2557 __i != __map_.begin();) |
2701 __buf.push_front(*--__i); | 2558 __buf.push_front(*--__i); |
2702 _VSTD::swap(__base::__map_.__first_, __buf.__first_); | 2559 _VSTD::swap(__map_.__first_, __buf.__first_); |
2703 _VSTD::swap(__base::__map_.__begin_, __buf.__begin_); | 2560 _VSTD::swap(__map_.__begin_, __buf.__begin_); |
2704 _VSTD::swap(__base::__map_.__end_, __buf.__end_); | 2561 _VSTD::swap(__map_.__end_, __buf.__end_); |
2705 _VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap()); | 2562 _VSTD::swap(__map_.__end_cap(), __buf.__end_cap()); |
2706 __base::__start_ -= __ds; | 2563 __start_ -= __ds; |
2707 } | 2564 } |
2708 } | 2565 } |
2709 | 2566 |
2710 template <class _Tp, class _Allocator> | 2567 template <class _Tp, class _Allocator> |
2711 void | 2568 void |
2712 deque<_Tp, _Allocator>::pop_front() | 2569 deque<_Tp, _Allocator>::pop_front() |
2713 { | 2570 { |
2714 allocator_type& __a = __base::__alloc(); | 2571 allocator_type& __a = __alloc(); |
2715 __alloc_traits::destroy(__a, _VSTD::__to_address(*(__base::__map_.begin() + | 2572 __alloc_traits::destroy(__a, _VSTD::__to_address(*(__map_.begin() + |
2716 __base::__start_ / __base::__block_size) + | 2573 __start_ / __block_size) + |
2717 __base::__start_ % __base::__block_size)); | 2574 __start_ % __block_size)); |
2718 --__base::size(); | 2575 --__size(); |
2719 ++__base::__start_; | 2576 ++__start_; |
2720 __maybe_remove_front_spare(); | 2577 __maybe_remove_front_spare(); |
2721 } | 2578 } |
2722 | 2579 |
2723 template <class _Tp, class _Allocator> | 2580 template <class _Tp, class _Allocator> |
2724 void | 2581 void |
2725 deque<_Tp, _Allocator>::pop_back() | 2582 deque<_Tp, _Allocator>::pop_back() |
2726 { | 2583 { |
2727 _LIBCPP_ASSERT(!empty(), "deque::pop_back called on an empty deque"); | 2584 _LIBCPP_ASSERT(!empty(), "deque::pop_back called on an empty deque"); |
2728 allocator_type& __a = __base::__alloc(); | 2585 allocator_type& __a = __alloc(); |
2729 size_type __p = __base::size() + __base::__start_ - 1; | 2586 size_type __p = size() + __start_ - 1; |
2730 __alloc_traits::destroy(__a, _VSTD::__to_address(*(__base::__map_.begin() + | 2587 __alloc_traits::destroy(__a, _VSTD::__to_address(*(__map_.begin() + |
2731 __p / __base::__block_size) + | 2588 __p / __block_size) + |
2732 __p % __base::__block_size)); | 2589 __p % __block_size)); |
2733 --__base::size(); | 2590 --__size(); |
2734 __maybe_remove_back_spare(); | 2591 __maybe_remove_back_spare(); |
2735 } | 2592 } |
2736 | 2593 |
2737 // move assign [__f, __l) to [__r, __r + (__l-__f)). | 2594 // move assign [__f, __l) to [__r, __r + (__l-__f)). |
2738 // If __vt points into [__f, __l), then subtract (__f - __r) from __vt. | 2595 // If __vt points into [__f, __l), then subtract (__f - __r) from __vt. |
2746 // *__r = _VSTD::move(*__f); | 2603 // *__r = _VSTD::move(*__f); |
2747 difference_type __n = __l - __f; | 2604 difference_type __n = __l - __f; |
2748 while (__n > 0) | 2605 while (__n > 0) |
2749 { | 2606 { |
2750 pointer __fb = __f.__ptr_; | 2607 pointer __fb = __f.__ptr_; |
2751 pointer __fe = *__f.__m_iter_ + __base::__block_size; | 2608 pointer __fe = *__f.__m_iter_ + __block_size; |
2752 difference_type __bs = __fe - __fb; | 2609 difference_type __bs = __fe - __fb; |
2753 if (__bs > __n) | 2610 if (__bs > __n) |
2754 { | 2611 { |
2755 __bs = __n; | 2612 __bs = __n; |
2756 __fe = __fb + __bs; | 2613 __fe = __fb + __bs; |
2800 template <class _Tp, class _Allocator> | 2657 template <class _Tp, class _Allocator> |
2801 void | 2658 void |
2802 deque<_Tp, _Allocator>::__move_construct_and_check(iterator __f, iterator __l, | 2659 deque<_Tp, _Allocator>::__move_construct_and_check(iterator __f, iterator __l, |
2803 iterator __r, const_pointer& __vt) | 2660 iterator __r, const_pointer& __vt) |
2804 { | 2661 { |
2805 allocator_type& __a = __base::__alloc(); | 2662 allocator_type& __a = __alloc(); |
2806 // as if | 2663 // as if |
2807 // for (; __f != __l; ++__r, ++__f, ++__base::size()) | 2664 // for (; __f != __l; ++__r, ++__f, ++__size()) |
2808 // __alloc_traits::construct(__a, _VSTD::addressof(*__r), _VSTD::move(*__f)); | 2665 // __alloc_traits::construct(__a, _VSTD::addressof(*__r), _VSTD::move(*__f)); |
2809 difference_type __n = __l - __f; | 2666 difference_type __n = __l - __f; |
2810 while (__n > 0) | 2667 while (__n > 0) |
2811 { | 2668 { |
2812 pointer __fb = __f.__ptr_; | 2669 pointer __fb = __f.__ptr_; |
2813 pointer __fe = *__f.__m_iter_ + __base::__block_size; | 2670 pointer __fe = *__f.__m_iter_ + __block_size; |
2814 difference_type __bs = __fe - __fb; | 2671 difference_type __bs = __fe - __fb; |
2815 if (__bs > __n) | 2672 if (__bs > __n) |
2816 { | 2673 { |
2817 __bs = __n; | 2674 __bs = __n; |
2818 __fe = __fb + __bs; | 2675 __fe = __fb + __bs; |
2819 } | 2676 } |
2820 if (__fb <= __vt && __vt < __fe) | 2677 if (__fb <= __vt && __vt < __fe) |
2821 __vt = (const_iterator(static_cast<__map_const_pointer>(__f.__m_iter_), __vt) += __r - __f).__ptr_; | 2678 __vt = (const_iterator(static_cast<__map_const_pointer>(__f.__m_iter_), __vt) += __r - __f).__ptr_; |
2822 for (; __fb != __fe; ++__fb, ++__r, ++__base::size()) | 2679 for (; __fb != __fe; ++__fb, ++__r, ++__size()) |
2823 __alloc_traits::construct(__a, _VSTD::addressof(*__r), _VSTD::move(*__fb)); | 2680 __alloc_traits::construct(__a, _VSTD::addressof(*__r), _VSTD::move(*__fb)); |
2824 __n -= __bs; | 2681 __n -= __bs; |
2825 __f += __bs; | 2682 __f += __bs; |
2826 } | 2683 } |
2827 } | 2684 } |
2831 template <class _Tp, class _Allocator> | 2688 template <class _Tp, class _Allocator> |
2832 void | 2689 void |
2833 deque<_Tp, _Allocator>::__move_construct_backward_and_check(iterator __f, iterator __l, | 2690 deque<_Tp, _Allocator>::__move_construct_backward_and_check(iterator __f, iterator __l, |
2834 iterator __r, const_pointer& __vt) | 2691 iterator __r, const_pointer& __vt) |
2835 { | 2692 { |
2836 allocator_type& __a = __base::__alloc(); | 2693 allocator_type& __a = __alloc(); |
2837 // as if | 2694 // as if |
2838 // for (iterator __j = __l; __j != __f;) | 2695 // for (iterator __j = __l; __j != __f;) |
2839 // { | 2696 // { |
2840 // __alloc_traitsconstruct(__a, _VSTD::addressof(*--__r), _VSTD::move(*--__j)); | 2697 // __alloc_traitsconstruct(__a, _VSTD::addressof(*--__r), _VSTD::move(*--__j)); |
2841 // --__base::__start_; | 2698 // --__start_; |
2842 // ++__base::size(); | 2699 // ++__size(); |
2843 // } | 2700 // } |
2844 difference_type __n = __l - __f; | 2701 difference_type __n = __l - __f; |
2845 while (__n > 0) | 2702 while (__n > 0) |
2846 { | 2703 { |
2847 --__l; | 2704 --__l; |
2856 if (__lb <= __vt && __vt < __le) | 2713 if (__lb <= __vt && __vt < __le) |
2857 __vt = (const_iterator(static_cast<__map_const_pointer>(__l.__m_iter_), __vt) -= __l - __r + 1).__ptr_; | 2714 __vt = (const_iterator(static_cast<__map_const_pointer>(__l.__m_iter_), __vt) -= __l - __r + 1).__ptr_; |
2858 while (__le != __lb) | 2715 while (__le != __lb) |
2859 { | 2716 { |
2860 __alloc_traits::construct(__a, _VSTD::addressof(*--__r), _VSTD::move(*--__le)); | 2717 __alloc_traits::construct(__a, _VSTD::addressof(*--__r), _VSTD::move(*--__le)); |
2861 --__base::__start_; | 2718 --__start_; |
2862 ++__base::size(); | 2719 ++__size(); |
2863 } | 2720 } |
2864 __n -= __bs; | 2721 __n -= __bs; |
2865 __l -= __bs - 1; | 2722 __l -= __bs - 1; |
2866 } | 2723 } |
2867 } | 2724 } |
2868 | 2725 |
2869 template <class _Tp, class _Allocator> | 2726 template <class _Tp, class _Allocator> |
2870 typename deque<_Tp, _Allocator>::iterator | 2727 typename deque<_Tp, _Allocator>::iterator |
2871 deque<_Tp, _Allocator>::erase(const_iterator __f) | 2728 deque<_Tp, _Allocator>::erase(const_iterator __f) |
2872 { | 2729 { |
2873 iterator __b = __base::begin(); | 2730 iterator __b = begin(); |
2874 difference_type __pos = __f - __b; | 2731 difference_type __pos = __f - __b; |
2875 iterator __p = __b + __pos; | 2732 iterator __p = __b + __pos; |
2876 allocator_type& __a = __base::__alloc(); | 2733 allocator_type& __a = __alloc(); |
2877 if (static_cast<size_t>(__pos) <= (__base::size() - 1) / 2) | 2734 if (static_cast<size_t>(__pos) <= (size() - 1) / 2) |
2878 { // erase from front | 2735 { // erase from front |
2879 _VSTD::move_backward(__b, __p, _VSTD::next(__p)); | 2736 _VSTD::move_backward(__b, __p, _VSTD::next(__p)); |
2880 __alloc_traits::destroy(__a, _VSTD::addressof(*__b)); | 2737 __alloc_traits::destroy(__a, _VSTD::addressof(*__b)); |
2881 --__base::size(); | 2738 --__size(); |
2882 ++__base::__start_; | 2739 ++__start_; |
2883 __maybe_remove_front_spare(); | 2740 __maybe_remove_front_spare(); |
2884 } | 2741 } |
2885 else | 2742 else |
2886 { // erase from back | 2743 { // erase from back |
2887 iterator __i = _VSTD::move(_VSTD::next(__p), __base::end(), __p); | 2744 iterator __i = _VSTD::move(_VSTD::next(__p), end(), __p); |
2888 __alloc_traits::destroy(__a, _VSTD::addressof(*__i)); | 2745 __alloc_traits::destroy(__a, _VSTD::addressof(*__i)); |
2889 --__base::size(); | 2746 --__size(); |
2890 __maybe_remove_back_spare(); | 2747 __maybe_remove_back_spare(); |
2891 } | 2748 } |
2892 return __base::begin() + __pos; | 2749 return begin() + __pos; |
2893 } | 2750 } |
2894 | 2751 |
2895 template <class _Tp, class _Allocator> | 2752 template <class _Tp, class _Allocator> |
2896 typename deque<_Tp, _Allocator>::iterator | 2753 typename deque<_Tp, _Allocator>::iterator |
2897 deque<_Tp, _Allocator>::erase(const_iterator __f, const_iterator __l) | 2754 deque<_Tp, _Allocator>::erase(const_iterator __f, const_iterator __l) |
2898 { | 2755 { |
2899 difference_type __n = __l - __f; | 2756 difference_type __n = __l - __f; |
2900 iterator __b = __base::begin(); | 2757 iterator __b = begin(); |
2901 difference_type __pos = __f - __b; | 2758 difference_type __pos = __f - __b; |
2902 iterator __p = __b + __pos; | 2759 iterator __p = __b + __pos; |
2903 if (__n > 0) | 2760 if (__n > 0) |
2904 { | 2761 { |
2905 allocator_type& __a = __base::__alloc(); | 2762 allocator_type& __a = __alloc(); |
2906 if (static_cast<size_t>(__pos) <= (__base::size() - __n) / 2) | 2763 if (static_cast<size_t>(__pos) <= (size() - __n) / 2) |
2907 { // erase from front | 2764 { // erase from front |
2908 iterator __i = _VSTD::move_backward(__b, __p, __p + __n); | 2765 iterator __i = _VSTD::move_backward(__b, __p, __p + __n); |
2909 for (; __b != __i; ++__b) | 2766 for (; __b != __i; ++__b) |
2910 __alloc_traits::destroy(__a, _VSTD::addressof(*__b)); | 2767 __alloc_traits::destroy(__a, _VSTD::addressof(*__b)); |
2911 __base::size() -= __n; | 2768 __size() -= __n; |
2912 __base::__start_ += __n; | 2769 __start_ += __n; |
2913 while (__maybe_remove_front_spare()) { | 2770 while (__maybe_remove_front_spare()) { |
2914 } | 2771 } |
2915 } | 2772 } |
2916 else | 2773 else |
2917 { // erase from back | 2774 { // erase from back |
2918 iterator __i = _VSTD::move(__p + __n, __base::end(), __p); | 2775 iterator __i = _VSTD::move(__p + __n, end(), __p); |
2919 for (iterator __e = __base::end(); __i != __e; ++__i) | 2776 for (iterator __e = end(); __i != __e; ++__i) |
2920 __alloc_traits::destroy(__a, _VSTD::addressof(*__i)); | 2777 __alloc_traits::destroy(__a, _VSTD::addressof(*__i)); |
2921 __base::size() -= __n; | 2778 __size() -= __n; |
2922 while (__maybe_remove_back_spare()) { | 2779 while (__maybe_remove_back_spare()) { |
2923 } | 2780 } |
2924 } | 2781 } |
2925 } | 2782 } |
2926 return __base::begin() + __pos; | 2783 return begin() + __pos; |
2927 } | 2784 } |
2928 | 2785 |
2929 template <class _Tp, class _Allocator> | 2786 template <class _Tp, class _Allocator> |
2930 void | 2787 void |
2931 deque<_Tp, _Allocator>::__erase_to_end(const_iterator __f) | 2788 deque<_Tp, _Allocator>::__erase_to_end(const_iterator __f) |
2932 { | 2789 { |
2933 iterator __e = __base::end(); | 2790 iterator __e = end(); |
2934 difference_type __n = __e - __f; | 2791 difference_type __n = __e - __f; |
2935 if (__n > 0) | 2792 if (__n > 0) |
2936 { | 2793 { |
2937 allocator_type& __a = __base::__alloc(); | 2794 allocator_type& __a = __alloc(); |
2938 iterator __b = __base::begin(); | 2795 iterator __b = begin(); |
2939 difference_type __pos = __f - __b; | 2796 difference_type __pos = __f - __b; |
2940 for (iterator __p = __b + __pos; __p != __e; ++__p) | 2797 for (iterator __p = __b + __pos; __p != __e; ++__p) |
2941 __alloc_traits::destroy(__a, _VSTD::addressof(*__p)); | 2798 __alloc_traits::destroy(__a, _VSTD::addressof(*__p)); |
2942 __base::size() -= __n; | 2799 __size() -= __n; |
2943 while (__maybe_remove_back_spare()) { | 2800 while (__maybe_remove_back_spare()) { |
2944 } | 2801 } |
2945 } | 2802 } |
2946 } | 2803 } |
2947 | 2804 |
2954 #else | 2811 #else |
2955 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || | 2812 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || |
2956 __is_nothrow_swappable<allocator_type>::value) | 2813 __is_nothrow_swappable<allocator_type>::value) |
2957 #endif | 2814 #endif |
2958 { | 2815 { |
2959 __base::swap(__c); | 2816 __map_.swap(__c.__map_); |
2817 _VSTD::swap(__start_, __c.__start_); | |
2818 _VSTD::swap(__size(), __c.__size()); | |
2819 _VSTD::__swap_allocator(__alloc(), __c.__alloc()); | |
2960 } | 2820 } |
2961 | 2821 |
2962 template <class _Tp, class _Allocator> | 2822 template <class _Tp, class _Allocator> |
2963 inline | 2823 inline |
2964 void | 2824 void |
2965 deque<_Tp, _Allocator>::clear() _NOEXCEPT | 2825 deque<_Tp, _Allocator>::clear() _NOEXCEPT |
2966 { | 2826 { |
2967 __base::clear(); | 2827 allocator_type& __a = __alloc(); |
2968 } | 2828 for (iterator __i = begin(), __e = end(); __i != __e; ++__i) |
2969 | 2829 __alloc_traits::destroy(__a, _VSTD::addressof(*__i)); |
2970 template <class _Tp, class _Allocator> | 2830 __size() = 0; |
2971 inline _LIBCPP_INLINE_VISIBILITY | 2831 while (__map_.size() > 2) |
2832 { | |
2833 __alloc_traits::deallocate(__a, __map_.front(), __block_size); | |
2834 __map_.pop_front(); | |
2835 } | |
2836 switch (__map_.size()) | |
2837 { | |
2838 case 1: | |
2839 __start_ = __block_size / 2; | |
2840 break; | |
2841 case 2: | |
2842 __start_ = __block_size; | |
2843 break; | |
2844 } | |
2845 } | |
2846 | |
2847 template <class _Tp, class _Allocator> | |
2848 inline _LIBCPP_HIDE_FROM_ABI | |
2972 bool | 2849 bool |
2973 operator==(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) | 2850 operator==(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) |
2974 { | 2851 { |
2975 const typename deque<_Tp, _Allocator>::size_type __sz = __x.size(); | 2852 const typename deque<_Tp, _Allocator>::size_type __sz = __x.size(); |
2976 return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); | 2853 return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); |
2977 } | 2854 } |
2978 | 2855 |
2979 template <class _Tp, class _Allocator> | 2856 template <class _Tp, class _Allocator> |
2980 inline _LIBCPP_INLINE_VISIBILITY | 2857 inline _LIBCPP_HIDE_FROM_ABI |
2981 bool | 2858 bool |
2982 operator!=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) | 2859 operator!=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) |
2983 { | 2860 { |
2984 return !(__x == __y); | 2861 return !(__x == __y); |
2985 } | 2862 } |
2986 | 2863 |
2987 template <class _Tp, class _Allocator> | 2864 template <class _Tp, class _Allocator> |
2988 inline _LIBCPP_INLINE_VISIBILITY | 2865 inline _LIBCPP_HIDE_FROM_ABI |
2989 bool | 2866 bool |
2990 operator< (const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) | 2867 operator< (const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) |
2991 { | 2868 { |
2992 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); | 2869 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); |
2993 } | 2870 } |
2994 | 2871 |
2995 template <class _Tp, class _Allocator> | 2872 template <class _Tp, class _Allocator> |
2996 inline _LIBCPP_INLINE_VISIBILITY | 2873 inline _LIBCPP_HIDE_FROM_ABI |
2997 bool | 2874 bool |
2998 operator> (const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) | 2875 operator> (const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) |
2999 { | 2876 { |
3000 return __y < __x; | 2877 return __y < __x; |
3001 } | 2878 } |
3002 | 2879 |
3003 template <class _Tp, class _Allocator> | 2880 template <class _Tp, class _Allocator> |
3004 inline _LIBCPP_INLINE_VISIBILITY | 2881 inline _LIBCPP_HIDE_FROM_ABI |
3005 bool | 2882 bool |
3006 operator>=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) | 2883 operator>=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) |
3007 { | 2884 { |
3008 return !(__x < __y); | 2885 return !(__x < __y); |
3009 } | 2886 } |
3010 | 2887 |
3011 template <class _Tp, class _Allocator> | 2888 template <class _Tp, class _Allocator> |
3012 inline _LIBCPP_INLINE_VISIBILITY | 2889 inline _LIBCPP_HIDE_FROM_ABI |
3013 bool | 2890 bool |
3014 operator<=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) | 2891 operator<=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y) |
3015 { | 2892 { |
3016 return !(__y < __x); | 2893 return !(__y < __x); |
3017 } | 2894 } |
3018 | 2895 |
3019 template <class _Tp, class _Allocator> | 2896 template <class _Tp, class _Allocator> |
3020 inline _LIBCPP_INLINE_VISIBILITY | 2897 inline _LIBCPP_HIDE_FROM_ABI |
3021 void | 2898 void |
3022 swap(deque<_Tp, _Allocator>& __x, deque<_Tp, _Allocator>& __y) | 2899 swap(deque<_Tp, _Allocator>& __x, deque<_Tp, _Allocator>& __y) |
3023 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) | 2900 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) |
3024 { | 2901 { |
3025 __x.swap(__y); | 2902 __x.swap(__y); |
3026 } | 2903 } |
3027 | 2904 |
3028 #if _LIBCPP_STD_VER > 17 | 2905 #if _LIBCPP_STD_VER > 17 |
3029 template <class _Tp, class _Allocator, class _Up> | 2906 template <class _Tp, class _Allocator, class _Up> |
3030 inline _LIBCPP_INLINE_VISIBILITY typename deque<_Tp, _Allocator>::size_type | 2907 inline _LIBCPP_HIDE_FROM_ABI typename deque<_Tp, _Allocator>::size_type |
3031 erase(deque<_Tp, _Allocator>& __c, const _Up& __v) { | 2908 erase(deque<_Tp, _Allocator>& __c, const _Up& __v) { |
3032 auto __old_size = __c.size(); | 2909 auto __old_size = __c.size(); |
3033 __c.erase(_VSTD::remove(__c.begin(), __c.end(), __v), __c.end()); | 2910 __c.erase(_VSTD::remove(__c.begin(), __c.end(), __v), __c.end()); |
3034 return __old_size - __c.size(); | 2911 return __old_size - __c.size(); |
3035 } | 2912 } |
3036 | 2913 |
3037 template <class _Tp, class _Allocator, class _Predicate> | 2914 template <class _Tp, class _Allocator, class _Predicate> |
3038 inline _LIBCPP_INLINE_VISIBILITY typename deque<_Tp, _Allocator>::size_type | 2915 inline _LIBCPP_HIDE_FROM_ABI typename deque<_Tp, _Allocator>::size_type |
3039 erase_if(deque<_Tp, _Allocator>& __c, _Predicate __pred) { | 2916 erase_if(deque<_Tp, _Allocator>& __c, _Predicate __pred) { |
3040 auto __old_size = __c.size(); | 2917 auto __old_size = __c.size(); |
3041 __c.erase(_VSTD::remove_if(__c.begin(), __c.end(), __pred), __c.end()); | 2918 __c.erase(_VSTD::remove_if(__c.begin(), __c.end(), __pred), __c.end()); |
3042 return __old_size - __c.size(); | 2919 return __old_size - __c.size(); |
3043 } | 2920 } |
2921 | |
2922 template <> | |
2923 inline constexpr bool __format::__enable_insertable<std::deque<char>> = true; | |
2924 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS | |
2925 template <> | |
2926 inline constexpr bool __format::__enable_insertable<std::deque<wchar_t>> = true; | |
3044 #endif | 2927 #endif |
3045 | 2928 |
2929 #endif // _LIBCPP_STD_VER > 17 | |
3046 | 2930 |
3047 _LIBCPP_END_NAMESPACE_STD | 2931 _LIBCPP_END_NAMESPACE_STD |
3048 | 2932 |
2933 #if _LIBCPP_STD_VER > 14 | |
2934 _LIBCPP_BEGIN_NAMESPACE_STD | |
2935 namespace pmr { | |
2936 template <class _ValueT> | |
2937 using deque = std::deque<_ValueT, polymorphic_allocator<_ValueT>>; | |
2938 } // namespace pmr | |
2939 _LIBCPP_END_NAMESPACE_STD | |
2940 #endif | |
2941 | |
3049 _LIBCPP_POP_MACROS | 2942 _LIBCPP_POP_MACROS |
3050 | 2943 |
2944 #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 | |
2945 # include <algorithm> | |
2946 # include <functional> | |
2947 # include <iterator> | |
2948 #endif | |
2949 | |
3051 #endif // _LIBCPP_DEQUE | 2950 #endif // _LIBCPP_DEQUE |