273
273
#include <__undef_min_max>
275
#ifdef _LIBCPP_DEBUG2
278
# define _LIBCPP_ASSERT(x, m) ((void)0)
275
281
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
276
282
#pragma GCC system_header
365
371
{return static_cast<size_type>(__end_cap() - __begin_);}
367
373
_LIBCPP_INLINE_VISIBILITY
368
void __destruct_at_end(const_pointer __new_last) _NOEXCEPT
369
{__destruct_at_end(__new_last, false_type());}
370
_LIBCPP_INLINE_VISIBILITY
371
void __destruct_at_end(const_pointer __new_last, false_type) _NOEXCEPT;
372
_LIBCPP_INLINE_VISIBILITY
373
void __destruct_at_end(const_pointer __new_last, true_type) _NOEXCEPT;
374
void __destruct_at_end(pointer __new_last) _NOEXCEPT;
375
376
_LIBCPP_INLINE_VISIBILITY
376
377
void __copy_assign_alloc(const __vector_base& __c)
437
438
template <class _Tp, class _Allocator>
438
439
_LIBCPP_INLINE_VISIBILITY inline
440
__vector_base<_Tp, _Allocator>::__destruct_at_end(const_pointer __new_last, false_type) _NOEXCEPT
441
__vector_base<_Tp, _Allocator>::__destruct_at_end(pointer __new_last) _NOEXCEPT
442
443
while (__new_last != __end_)
443
__alloc_traits::destroy(__alloc(), const_cast<pointer>(--__end_));
446
template <class _Tp, class _Allocator>
447
_LIBCPP_INLINE_VISIBILITY inline
449
__vector_base<_Tp, _Allocator>::__destruct_at_end(const_pointer __new_last, true_type) _NOEXCEPT
451
__end_ = const_cast<pointer>(__new_last);
444
__alloc_traits::destroy(__alloc(), _VSTD::__to_raw_pointer(--__end_));
454
447
template <class _Tp, class _Allocator>
455
448
_LIBCPP_INLINE_VISIBILITY inline
456
449
__vector_base<_Tp, _Allocator>::__vector_base()
457
450
_NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
464
457
template <class _Tp, class _Allocator>
465
458
_LIBCPP_INLINE_VISIBILITY inline
466
459
__vector_base<_Tp, _Allocator>::__vector_base(const allocator_type& __a)
462
__end_cap_(nullptr, __a)
473
466
template <class _Tp, class _Allocator>
474
467
__vector_base<_Tp, _Allocator>::~__vector_base()
469
if (__begin_ != nullptr)
479
472
__alloc_traits::deallocate(__alloc(), __begin_, capacity());
797
790
_NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
798
791
void __move_assign(vector& __c, false_type);
799
792
_LIBCPP_INLINE_VISIBILITY
800
void __destruct_at_end(const_pointer __new_last) _NOEXCEPT
793
void __destruct_at_end(pointer __new_last) _NOEXCEPT
802
795
#if _LIBCPP_DEBUG_LEVEL >= 2
803
796
__c_node* __c = __get_db()->__find_c_and_lock(this);
879
872
vector<_Tp, _Allocator>::deallocate() _NOEXCEPT
881
if (this->__begin_ != 0)
874
if (this->__begin_ != nullptr)
884
877
__alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity());
885
this->__begin_ = this->__end_ = this->__end_cap() = 0;
878
this->__begin_ = this->__end_ = this->__end_cap() = nullptr;
1171
1164
this->__begin_ = __x.__begin_;
1172
1165
this->__end_ = __x.__end_;
1173
1166
this->__end_cap() = __x.__end_cap();
1174
__x.__begin_ = __x.__end_ = __x.__end_cap() = 0;
1167
__x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
1177
1170
template <class _Tp, class _Allocator>
1598
1591
_LIBCPP_ASSERT(__position != end(),
1599
1592
"vector::erase(iterator) called with a non-dereferenceable iterator");
1600
pointer __p = const_cast<pointer>(&*__position);
1593
difference_type __ps = __position - cbegin();
1594
pointer __p = this->__begin_ + __ps;
1601
1595
iterator __r = __make_iter(__p);
1602
1596
this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p));
1615
1609
_LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range");
1616
1610
pointer __p = this->__begin_ + (__first - begin());
1617
1611
iterator __r = __make_iter(__p);
1618
this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p));
1612
if (__first != __last)
1613
this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p));
1943
1938
vector<_Tp, _Allocator>::__invariants() const
1945
if (this->__begin_ == 0)
1940
if (this->__begin_ == nullptr)
1947
if (this->__end_ != 0 || this->__end_cap() != 0)
1942
if (this->__end_ != nullptr || this->__end_cap() != nullptr)
2306
2301
{return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
2307
2302
_LIBCPP_INLINE_VISIBILITY
2308
2303
iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT
2309
{return iterator(const_cast<__storage_pointer>(__p.__seg_), __p.__ctz_);}
2304
{return begin() + (__p - cbegin());}
2310
2305
#endif // _LIBCPP_DEBUG
2312
2307
_LIBCPP_INLINE_VISIBILITY
2414
2409
vector<bool, _Allocator>::deallocate() _NOEXCEPT
2416
if (this->__begin_ != 0)
2411
if (this->__begin_ != nullptr)
2418
2413
__storage_traits::deallocate(this->__alloc(), this->__begin_, __cap());
2419
2414
__invalidate_all_iterators();
2415
this->__begin_ = nullptr;
2421
2416
this->__size_ = this->__cap() = 0;
2489
2484
template <class _Allocator>
2490
2485
_LIBCPP_INLINE_VISIBILITY inline
2491
2486
vector<bool, _Allocator>::vector(const allocator_type& __a)
2487
: __begin_(nullptr),
2494
2489
__cap_alloc_(0, static_cast<__storage_allocator>(__a))
2524
2519
template <class _Allocator>
2525
2520
vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
2521
: __begin_(nullptr),
2528
2523
__cap_alloc_(0, static_cast<__storage_allocator>(__a))
2539
2534
vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
2540
2535
typename enable_if<__is_input_iterator <_InputIterator>::value &&
2541
2536
!__is_forward_iterator<_InputIterator>::value>::type*)
2537
: __begin_(nullptr),
2544
2539
__cap_alloc_(0)
2566
2561
vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
2567
2562
typename enable_if<__is_input_iterator <_InputIterator>::value &&
2568
2563
!__is_forward_iterator<_InputIterator>::value>::type*)
2564
: __begin_(nullptr),
2571
2566
__cap_alloc_(0, static_cast<__storage_allocator>(__a))
2592
2587
template <class _ForwardIterator>
2593
2588
vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
2594
2589
typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
2590
: __begin_(nullptr),
2597
2592
__cap_alloc_(0)
2608
2603
template <class _ForwardIterator>
2609
2604
vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
2610
2605
typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
2606
: __begin_(nullptr),
2613
2608
__cap_alloc_(0, static_cast<__storage_allocator>(__a))
2639
2634
template <class _Allocator>
2640
2635
vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
2636
: __begin_(nullptr),
2643
2638
__cap_alloc_(0, static_cast<__storage_allocator>(__a))
2655
2650
template <class _Allocator>
2656
2651
vector<bool, _Allocator>::~vector()
2653
if (__begin_ != nullptr)
2659
2654
__storage_traits::deallocate(__alloc(), __begin_, __cap());
2660
2655
#ifdef _LIBCPP_DEBUG
2661
2656
__invalidate_all_iterators();