1967template <class VALUE_TYPE, class ALLOCATOR>
1968bool operator==(const
vector<VALUE_TYPE, ALLOCATOR>&
lhs,
1969 const
vector<VALUE_TYPE, ALLOCATOR>&
rhs);
1971#ifndef BSLS_COMPILERFEATURES_SUPPORT_THREE_WAY_COMPARISON
1979template <
class VALUE_TYPE,
class ALLOCATOR>
1984#ifdef BSLALG_SYNTHTHREEWAYUTIL_AVAILABLE
1989template <
class VALUE_TYPE,
class ALLOCATOR>
1990BloombergLP::bslalg::SynthThreeWayUtil::Result<VALUE_TYPE> operator<=>(
2007template <
class VALUE_TYPE,
class ALLOCATOR>
2019template <
class VALUE_TYPE,
class ALLOCATOR>
2031template <
class VALUE_TYPE,
class ALLOCATOR>
2043template <
class VALUE_TYPE,
class ALLOCATOR>
2053template <
class VALUE_TYPE,
class ALLOCATOR,
class BDE_OTHER_TYPE>
2059template <
class VALUE_TYPE,
class ALLOCATOR,
class PREDICATE>
2077template <
class VALUE_TYPE,
class ALLOCATOR>
2098template <
class VALUE_TYPE,
class ALLOCATOR>
2103 typedef BloombergLP::bsls::Types::UintPtr UintPtr;
2104#if defined(BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES)
2106 template rebind_alloc<UintPtr> ImplAlloc;
2108 typedef typename ALLOCATOR::template rebind<UintPtr>::other ImplAlloc;
2111 typedef BloombergLP::bslmf::MovableRefUtil MoveUtil;
2141 const ALLOCATOR& basicAllocator = ALLOCATOR());
2145 const ALLOCATOR& basicAllocator = ALLOCATOR());
2147 template <class INPUT_ITER>
2150 const ALLOCATOR& basicAllocator = ALLOCATOR());
2152 template <class t_RANGE>
2156 const ALLOCATOR& basicAllocator =
2165 const typename type_identity<ALLOCATOR>::type& basicAllocator);
2168 const typename type_identity<ALLOCATOR>::type& basicAllocator);
2171#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
2172 vector(std::initializer_list<VALUE_TYPE *> values,
2173 const ALLOCATOR& basicAllocator = ALLOCATOR());
2186 d_impl = MoveUtil::move(MoveUtil::access(
rhs).d_impl)))
2188 d_impl = MoveUtil::move(MoveUtil::access(
rhs).d_impl);
2192#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
2193 vector& operator=(std::initializer_list<VALUE_TYPE *> values);
2195 void assign(std::initializer_list<VALUE_TYPE *> values);
2199 template <
class INPUT_ITER>
2200 void assign(INPUT_ITER first, INPUT_ITER last);
2201 void assign(
size_type numElements, VALUE_TYPE *value);
2203 template <
class t_RANGE>
2229 void resize(
size_type newLength, VALUE_TYPE *value);
2232 void shrink_to_fit();
2236 template <class t_RANGE>
2242# if defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES)
2243 template <
class ARG>
2249 void push_back(VALUE_TYPE *value);
2255# if defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES)
2256 template <
class ARG>
2267 template <
class INPUT_ITER>
2276 INPUT_ITER>::type Iter;
2279 (
const UintPtr *)position, Iter(first), Iter(last));
2282#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
2284 std::initializer_list<VALUE_TYPE *> values);
2287 template <
class t_RANGE>
2295 void swap(
vector<VALUE_TYPE *, ALLOCATOR>& other)
2297 d_impl.swap(other.d_impl)));
2339 return lhs.d_impl ==
rhs.d_impl;
2342#ifdef BSLALG_SYNTHTHREEWAYUTIL_AVAILABLE
2344 friend BloombergLP::bslalg::SynthThreeWayUtil::Result<Impl>
2347 return BloombergLP::bslalg::SynthThreeWayUtil::compare(
lhs.d_impl,
2356 return lhs.d_impl !=
rhs.d_impl;
2362 return lhs.d_impl <
rhs.d_impl;
2368 return lhs.d_impl >
rhs.d_impl;
2374 return lhs.d_impl <=
rhs.d_impl;
2380 return lhs.d_impl >=
rhs.d_impl;
2388 a.d_impl.swap(b.d_impl)))
2390 a.d_impl.swap(b.d_impl);
2394#ifdef BSLS_COMPILERFEATURES_SUPPORT_CTAD
2406 class = bsl::enable_if_t<
2407 bsl::is_convertible_v<
2410 class = bsl::enable_if_t<bsl::is_convertible_v<ALLOC *, DEFAULT_ALLOCATOR>>
2412vector(SIZE_TYPE, VALUE, ALLOC *) -> vector<VALUE>;
2417 class INPUT_ITERATOR,
2419 typename BloombergLP::bslstl::IteratorUtil::IterVal_t<INPUT_ITERATOR>
2421vector(INPUT_ITERATOR, INPUT_ITERATOR) -> vector<VALUE>;
2428 class INPUT_ITERATOR,
2431 typename BloombergLP::bslstl::IteratorUtil::IterVal_t<INPUT_ITERATOR>,
2432 class = bsl::enable_if_t<bsl::IsStdAllocator_v<ALLOCATOR>>
2434vector(INPUT_ITERATOR, INPUT_ITERATOR, ALLOCATOR) -> vector<VALUE, ALLOCATOR>;
2441 class INPUT_ITERATOR,
2444 typename BloombergLP::bslstl::IteratorUtil::IterVal_t<INPUT_ITERATOR>,
2446 class = bsl::enable_if_t<bsl::is_convertible_v<ALLOC *, DEFAULT_ALLOCATOR>>
2448vector(INPUT_ITERATOR, INPUT_ITERATOR, ALLOC *)
2459 class = bsl::enable_if_t<bsl::is_convertible_v<ALLOC *, DEFAULT_ALLOCATOR>>
2461vector(std::initializer_list<VALUE>, ALLOC *)
2464#if defined(BSLS_LIBRARYFEATURES_HAS_CPP20_RANGES)
2467template <ranges::input_range t_RANGE,
2469 allocator<ranges::range_value_t<t_RANGE>>>
2470vector(from_range_t, t_RANGE&&, t_ALLOCATOR = t_ALLOCATOR())
2471-> vector<ranges::range_value_t<t_RANGE>, t_ALLOCATOR>;
2495template <
class VALUE_TYPE,
class ITERATOR>
2504 typedef BloombergLP::bsls::Types::UintPtr
UintPtr;
2509 typedef typename iterator_traits<ITERATOR>::difference_type
2511 typedef typename iterator_traits<ITERATOR>::iterator_category
2538#ifdef BSLS_COMPILERFEATURES_SUPPORT_THREE_WAY_COMPARISON
2563 return lhs.d_iter !=
rhs.d_iter;
2580 return lhs.d_iter ==
rhs.d_iter;
2593 return lhs.d_iter <
rhs.d_iter;
2596#if defined(BSLS_LIBRARYFEATURES_HAS_CPP20_RANGES)
2597 bool operator==(bsl::sentinel_for<ITERATOR>
auto rhs)
const
2599 return d_iter ==
rhs;
2601 friend auto operator-(bsl::sentinel_for<ITERATOR>
auto s,
2602 vector_UintPtrConversionIterator i)
2603 requires random_access_iterator<ITERATOR>
2605 return s - i.d_iter;
2617#ifdef BSLS_LIBRARYFEATURES_HAS_CPP20_CONCEPTS
2618 requires requires {
lhs.d_iter -
rhs.d_iter; }
2621 return lhs.d_iter -
rhs.d_iter;
2630template <
class VALUE_TYPE,
class ITERATOR>
2637template <
class VALUE_TYPE,
class ITERATOR>
2646template <
class VALUE_TYPE,
class ITERATOR>
2655template <
class VALUE_TYPE,
class ITERATOR>
2666template <
class VALUE_TYPE,
class ITERATOR>
2668BloombergLP::bsls::Types::UintPtr
2671 VALUE_TYPE
const ptr = *d_iter;
2672 return reinterpret_cast<UintPtr>(ptr);
2689template <
class t_VALUE_TYPE,
class t_ITERATOR,
class t_SENTINEL>
2705template <
class t_VALUE_TYPE,
class t_ITERATOR,
class t_SENTINEL>
2707vector_UintPtrRangeAdapter<t_VALUE_TYPE, t_ITERATOR, t_SENTINEL>
2728template <
class VALUE_TYPE,
class ALLOCATOR>
2732 VALUE_TYPE *d_target_p;
2733 ALLOCATOR d_allocator;
2768template <
class VALUE_TYPE,
class ALLOCATOR>
2778template <
class VALUE_TYPE,
class ALLOCATOR>
2788template <
class VALUE_TYPE,
class ALLOCATOR>
2795#if defined(BSLS_ASSERT_SAFE_IS_USED)
2800template <
class BSLSTL_ITERATOR,
class SENTINEL>
2804Vector_RangeCheck::isInvalidRange(BSLSTL_ITERATOR, SENTINEL)
2809template <
class BSLSTL_ITERATOR>
2811typename enable_if<Vector_IsRandomAccessIterator<BSLSTL_ITERATOR>::value,
2813Vector_RangeCheck::isInvalidRange(BSLSTL_ITERATOR first, BSLSTL_ITERATOR last)
2815 return last < first;
2818template <
class BSLSTL_ITERATOR,
class SENTINEL>
2820typename enable_if<Vector_IsRandomAccessIterator<BSLSTL_ITERATOR>::value,
2822Vector_RangeCheck::isInvalidRange(BSLSTL_ITERATOR first, SENTINEL last)
2824 return last - first < 0;
2833template <
class VALUE_TYPE>
2844template <
class VALUE_TYPE>
2863template <
class VALUE_TYPE>
2868 return d_dataBegin_p;
2871template <
class VALUE_TYPE>
2879template <
class VALUE_TYPE>
2887template <
class VALUE_TYPE>
2897template <
class VALUE_TYPE>
2904 return d_dataBegin_p[position];
2907template <
class VALUE_TYPE>
2913 BloombergLP::bslstl::StdExceptUtil::throwOutOfRange(
2914 "vector<...>::at(position): invalid position");
2916 return d_dataBegin_p[position];
2919template <
class VALUE_TYPE>
2926 return *d_dataBegin_p;
2929template <
class VALUE_TYPE>
2936 return *(d_dataEnd_p - 1);
2939template <
class VALUE_TYPE>
2944 return d_dataBegin_p;
2950template <
class VALUE_TYPE>
2955 return d_dataBegin_p;
2958template <
class VALUE_TYPE>
2963 return d_dataBegin_p;
2966template <
class VALUE_TYPE>
2974template <
class VALUE_TYPE>
2982template <
class VALUE_TYPE>
2990template <
class VALUE_TYPE>
2998template <
class VALUE_TYPE>
3006template <
class VALUE_TYPE>
3016template <
class VALUE_TYPE>
3021 return d_dataEnd_p - d_dataBegin_p;
3024template <
class VALUE_TYPE>
3032template <
class VALUE_TYPE>
3036 return d_dataEnd_p == d_dataBegin_p;
3040template <
class VALUE_TYPE>
3047 return d_dataBegin_p[position];
3050template <
class VALUE_TYPE>
3056 BloombergLP::bslstl::StdExceptUtil::throwOutOfRange(
3057 "const vector<...>::at(position): invalid position");
3059 return d_dataBegin_p[position];
3062template <
class VALUE_TYPE>
3069 return *d_dataBegin_p;
3072template <
class VALUE_TYPE>
3079 return *(d_dataEnd_p - 1);
3082template <
class VALUE_TYPE>
3087 return d_dataBegin_p;
3095template <
class VALUE_TYPE,
class ALLOCATOR>
3098 std::size_t capacity,
3099 ContainerBase *container)
3101, d_capacity(capacity)
3102, d_container_p(container)
3106template <
class VALUE_TYPE,
class ALLOCATOR>
3108vector<VALUE_TYPE, ALLOCATOR>::Proctor::~Proctor()
3110 using BloombergLP::bslma::AllocatorUtil;
3113 AllocatorUtil::deallocateObject(d_container_p->allocatorRef(),
3114 d_data_p, d_capacity);
3119template <
class VALUE_TYPE,
class ALLOCATOR>
3121void vector<VALUE_TYPE, ALLOCATOR>::Proctor::release()
3131template <
class VALUE_TYPE,
class ALLOCATOR>
3132template <
class t_RANGE,
class t_ITERATOR>
3134void vector<VALUE_TYPE, ALLOCATOR>::privateConstruct(
3141 ranges::end(range)));
3151template <
class VALUE_TYPE,
class ALLOCATOR>
3152template <
class t_RANGE,
class t_ITERATOR>
3154void vector<VALUE_TYPE, ALLOCATOR>::privateConstruct(
3158 std::forward_iterator_tag)
3160#if defined(BSLS_LIBRARYFEATURES_HAS_CPP20_RANGES)
3161 if constexpr (ranges::sized_range<t_RANGE>) {
3162 constructFromSizedRange(begin,
3164 ranges::size(range));
3168 constructFromSizedRange(
3171 BloombergLP::bslstl::IteratorUtil::insertDistance(begin,
3172 ranges::end(range)));
3175template <
class VALUE_TYPE,
class ALLOCATOR>
3176template <
class t_RANGE,
class t_ITERATOR>
3178void vector<VALUE_TYPE, ALLOCATOR>::privateConstruct(
3182 std::input_iterator_tag)
3184#if defined(BSLS_LIBRARYFEATURES_HAS_CPP20_RANGES)
3185 if constexpr (ranges::sized_range<t_RANGE>) {
3186 constructFromSizedRange(begin,
3188 ranges::size(range));
3192 if (begin != ranges::end(range)) {
3193 constructFromRange(begin,
3195 std::input_iterator_tag());
3199template <
class VALUE_TYPE,
class ALLOCATOR>
3200template <
class FWD_ITER,
class SENTINEL>
3202void vector<VALUE_TYPE, ALLOCATOR>::constructFromRange(
3205 std::forward_iterator_tag)
3211 ::canCalculateInsertDistance<FWD_ITER, FWD_ITER>()));
3213 constructFromSizedRange(
3216 BloombergLP::bslstl::IteratorUtil::insertDistance(first, last));
3219template <
class VALUE_TYPE,
class ALLOCATOR>
3220template <
class INPUT_ITER,
class SENTINEL>
3221void vector<VALUE_TYPE, ALLOCATOR>::constructFromRange(
3224 std::input_iterator_tag)
3234 vector temp(this->get_allocator());
3235 while (first != last) {
3236 temp.emplace_back(*first);
3242template <
class VALUE_TYPE,
class ALLOCATOR>
3243template <
class INTEGRAL>
3244void vector<VALUE_TYPE, ALLOCATOR>::constructFromRange(
3245 INTEGRAL initialSize,
3247 BloombergLP::bslmf::Nil)
3258 static_cast<size_type
>(initialSize) > max_size())) {
3260 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
3261 "vector<...>::(repeated-value constructor): input too long");
3264 if (initialSize > 0) {
3265 privateReserveEmpty(initialSize);
3266 Proctor proctor(this->d_dataBegin_p,
3268 static_cast<ContainerBase *
>(
this));
3270 ArrayPrimitives::uninitializedFillN(this->d_dataBegin_p,
3272 static_cast<VALUE_TYPE
>(value),
3273 this->allocatorRef());
3276 this->d_dataEnd_p += initialSize;
3280template <
class VALUE_TYPE,
class ALLOCATOR>
3281template <
class t_ITERATOR,
class t_SENTINEL>
3282void vector<VALUE_TYPE, ALLOCATOR>::constructFromSizedRange(t_ITERATOR first,
3290 const size_type maxSize = max_size();
3293 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
3294 "vector<...>::(range-constructor): input too long");
3298 this->privateReserveEmpty(newCapacity);
3299 Proctor proctor(this->d_dataBegin_p,
3301 static_cast<ContainerBase *
>(
this));
3303 ArrayPrimitives::copyConstruct(this->d_dataEnd_p,
3306 this->allocatorRef());
3308 this->d_dataEnd_p +=
size;
3311template <
class VALUE_TYPE,
class ALLOCATOR>
3312template <
class t_RANGE,
class t_ITERATOR>
3314void vector<VALUE_TYPE, ALLOCATOR>::privateAppendRange(
3326template <
class VALUE_TYPE,
class ALLOCATOR>
3327template <
class t_RANGE,
class t_ITERATOR>
3329void vector<VALUE_TYPE, ALLOCATOR>::privateAppendRange(
3332 std::forward_iterator_tag)
3334#if defined(BSLS_LIBRARYFEATURES_HAS_CPP20_RANGES)
3335 if constexpr (ranges::sized_range<t_RANGE>) {
3336 privateAppendSizedRange(begin,
3338 ranges::size(range));
3342 privateAppendSizedRange(
3345 BloombergLP::bslstl::IteratorUtil::insertDistance(begin,
3346 ranges::end(range)));
3349template <
class VALUE_TYPE,
class ALLOCATOR>
3350template <
class t_RANGE,
class t_ITERATOR>
3352void vector<VALUE_TYPE, ALLOCATOR>::privateAppendRange(
3355 std::input_iterator_tag)
3357#if defined(BSLS_LIBRARYFEATURES_HAS_CPP20_RANGES)
3358 if constexpr (ranges::sized_range<t_RANGE>) {
3359 privateAppendSizedRange(begin,
3361 ranges::size(range));
3366 privateAppendUnsizedRange(begin, ranges::end(range));
3370template <
class VALUE_TYPE,
class ALLOCATOR>
3371template <
class t_ITERATOR,
class t_SENTINEL>
3373void vector<VALUE_TYPE, ALLOCATOR>::privateAppendSizedRange(
3376 size_type rangeSize)
3378 if (rangeSize == 0) {
3382 size_type
size = this->size();
3383 size_type diff = max_size() -
size;
3386 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
3387 "vector<...>::(range-constructor): input too long");
3391 if (size > this->capacity()) {
3395 ArrayPrimitives::copyConstruct(this->d_dataEnd_p,
3398 this->allocatorRef());
3399 this->d_dataEnd_p += rangeSize;
3402template <
class VALUE_TYPE,
class ALLOCATOR>
3403template <
class t_ITERATOR,
class t_SENTINEL>
3405void vector<VALUE_TYPE, ALLOCATOR>::privateAppendUnsizedRange(t_ITERATOR begin,
3409 emplace_back(*begin);
3413template <
class VALUE_TYPE,
class ALLOCATOR>
3414template <
class INPUT_ITER>
3416void vector<VALUE_TYPE, ALLOCATOR>::privateInsertDispatch(
3417 const_iterator position,
3420 BloombergLP::bslmf::MatchArithmeticType ,
3421 BloombergLP::bslmf::Nil )
3426 this->insert(position,
3427 static_cast<size_type
>(count),
3428 static_cast<VALUE_TYPE
>(value));
3431template <
class VALUE_TYPE,
class ALLOCATOR>
3432template <
class INPUT_ITER>
3434void vector<VALUE_TYPE, ALLOCATOR>::privateInsertDispatch(
3435 const_iterator position,
3438 BloombergLP::bslmf::MatchAnyType ,
3439 BloombergLP::bslmf::MatchAnyType )
3446 this->privateInsert(position, first, last, Tag());
3449template <
class VALUE_TYPE,
class ALLOCATOR>
3450template <
class t_ITERATOR,
class t_SENTINEL>
3452void vector<VALUE_TYPE, ALLOCATOR>::privateInsert(const_iterator position,
3458 this->privateInsert(position, first, last, Tag());
3461template <
class VALUE_TYPE,
class ALLOCATOR>
3462template <
class INPUT_ITER,
class SENTINEL>
3463void vector<VALUE_TYPE, ALLOCATOR>::privateInsert(
3464 const_iterator position,
3467 const std::input_iterator_tag&)
3481 if (first == last) {
3485 if (!this->capacity()) {
3486 privateReserveEmpty(size_type(1));
3487 position = this->d_dataBegin_p;
3490 size_type insertOffset = position - this->d_dataBegin_p;
3491 size_type initialEnd = this->size();
3492 size_type tailLength = this->end() - position;
3494 VALUE_TYPE *emplaceBegin = this->d_dataEnd_p;
3495 VALUE_TYPE *emplaceEnd = this->d_dataBegin_p + this->d_capacity;
3496 VALUE_TYPE *emplacePosition = emplaceBegin;
3498 allocator_type alloc(this->get_allocator());
3505 vector resultState(alloc);
3511 BloombergLP::bslma::AutoDestructor<VALUE_TYPE> insertProctor(
3513 while (emplacePosition != emplaceEnd) {
3514 AllocatorTraits::construct(alloc, emplacePosition, *first);
3517 if (++first == last) {
3518 this->d_dataEnd_p = emplacePosition;
3519 insertProctor.release();
3521 ArrayPrimitives::rotate(this->d_dataBegin_p + insertOffset,
3522 this->d_dataBegin_p + initialEnd,
3532 resultState.reserve(this->d_capacity*2);
3533 emplacePosition = resultState.d_dataBegin_p + insertOffset;
3534 ArrayPrimitives::destructiveMove(emplacePosition,
3539 size_type emplaceOffset = (emplaceEnd - emplaceBegin);
3540 insertProctor.reset(emplacePosition);
3541 emplaceBegin = emplacePosition;
3542 emplaceEnd = resultState.d_dataBegin_p + resultState.d_capacity
3544 emplacePosition += emplaceOffset;
3546 while (first != last) {
3547 if (emplacePosition == emplaceEnd) {
3549 vector nextResult(alloc);
3550 nextResult.reserve(resultState.d_capacity*2);
3551 emplacePosition = nextResult.d_dataBegin_p + insertOffset;
3552 ArrayPrimitives::destructiveMove(emplacePosition,
3557 insertProctor.reset(emplacePosition);
3558 emplaceOffset = (emplaceEnd - emplaceBegin);
3559 emplaceBegin = emplacePosition;
3560 emplaceEnd = nextResult.d_dataBegin_p + nextResult.d_capacity
3562 emplacePosition += emplaceOffset;
3565 &resultState.d_dataBegin_p);
3568 AllocatorTraits::construct(alloc, emplacePosition, *first);
3575 ArrayPrimitives::destructiveMove(emplacePosition,
3576 this->d_dataBegin_p + insertOffset,
3577 this->d_dataBegin_p + initialEnd,
3581 this->d_dataEnd_p = this->d_dataBegin_p + insertOffset;
3582 emplacePosition += (initialEnd - insertOffset);
3583 insertProctor.setLength(
3584 insertProctor.length() +
static_cast<int>(initialEnd - insertOffset));
3587 ArrayPrimitives::destructiveMove(resultState.d_dataBegin_p,
3588 this->d_dataBegin_p,
3589 this->d_dataBegin_p + insertOffset,
3595 resultState.d_dataEnd_p = emplacePosition;
3598 insertProctor.release();
3599 this->d_dataEnd_p = this->d_dataBegin_p;
3605template <
class VALUE_TYPE,
class ALLOCATOR>
3606template <
class FWD_ITER,
class SENTINEL>
3607void vector<VALUE_TYPE, ALLOCATOR>::privateInsert(
3608 const_iterator position,
3611 const std::forward_iterator_tag&)
3617 ::canCalculateInsertDistance<FWD_ITER, SENTINEL>()));
3619 const iterator& pos =
const_cast<iterator
>(position);
3621 const size_type maxSize = max_size();
3623 BloombergLP::bslstl::IteratorUtil::insertDistance(first, last);
3627 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
3628 "vector<...>::insert(pos,first,last): vector too long");
3631 const size_type newSize = this->size() + n;
3632 if (newSize > this->d_capacity) {
3638 vector temp(this->get_allocator());
3639 temp.privateReserveEmpty(newCapacity);
3641 ArrayPrimitives::destructiveMoveAndInsert(temp.d_dataBegin_p,
3643 this->d_dataBegin_p,
3649 this->allocatorRef());
3650 temp.d_dataEnd_p += newSize;
3654 ArrayPrimitives::insert(pos,
3659 this->allocatorRef());
3660 this->d_dataEnd_p += n;
3664template <
class VALUE_TYPE,
class ALLOCATOR>
3665void vector<VALUE_TYPE, ALLOCATOR>::privateMoveInsert(
3667 const_iterator position)
3669 const iterator& pos =
const_cast<const iterator&
>(position);
3671 const size_type maxSize = max_size();
3672 const size_type n = fromVector->size();
3675 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
3676 "vector<...>::insert(pos,first,last): vector too long");
3679 const size_type newSize = this->size() + n;
3680 if (newSize > this->d_capacity) {
3686 vector temp(this->get_allocator());
3687 temp.privateReserveEmpty(newCapacity);
3689 ArrayPrimitives::destructiveMoveAndMoveInsert(
3692 &fromVector->d_dataEnd_p,
3693 this->d_dataBegin_p,
3696 fromVector->d_dataBegin_p,
3697 fromVector->d_dataEnd_p,
3699 this->allocatorRef());
3700 temp.d_dataEnd_p += newSize;
3704 ArrayPrimitives::moveInsert(pos,
3706 &fromVector->d_dataEnd_p,
3707 fromVector->d_dataBegin_p,
3708 fromVector->d_dataEnd_p,
3710 this->allocatorRef());
3711 this->d_dataEnd_p += n;
3715template <
class VALUE_TYPE,
class ALLOCATOR>
3717void vector<VALUE_TYPE, ALLOCATOR>::privateReserveEmpty(size_type numElements)
3722 this->d_dataBegin_p = this->d_dataEnd_p =
3723 AllocatorUtil::allocateObject<VALUE_TYPE>(this->allocatorRef(),
3726 this->d_capacity = numElements;
3729#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
3730template <
class VALUE_TYPE,
class ALLOCATOR>
3731template <
class... Args>
3732void vector<VALUE_TYPE, ALLOCATOR>::privateEmplaceBackWithAllocation(
3737 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
3738 "vector<...>:emplace_back(args...): vector too long");
3744 vector temp(this->get_allocator());
3745 temp.privateReserveEmpty(newCapacity);
3748 VALUE_TYPE *pos = temp.d_dataBegin_p + this->size();
3749 AllocatorTraits::construct(
3750 this->allocatorRef(),
3756 Vector_PushProctor<VALUE_TYPE, ALLOCATOR> guard(pos, this->allocatorRef());
3757 ArrayPrimitives::destructiveMove(temp.d_dataBegin_p,
3758 this->d_dataBegin_p,
3760 this->allocatorRef());
3763 this->d_dataEnd_p = this->d_dataBegin_p;
3764 temp.d_dataEnd_p = ++pos;
3769template <
class VALUE_TYPE,
class ALLOCATOR>
3770void vector<VALUE_TYPE, ALLOCATOR>::privatePushBackWithAllocation(
3771 const VALUE_TYPE& value)
3775 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
3776 "vector<...>:push_back(lvalue): vector too long");
3783 vector temp(this->get_allocator());
3784 temp.privateReserveEmpty(newCapacity);
3787 VALUE_TYPE *pos = temp.d_dataBegin_p + this->size();
3788 AllocatorTraits::construct(this->allocatorRef(), pos, value);
3792 Vector_PushProctor<VALUE_TYPE, ALLOCATOR> guard(pos, this->allocatorRef());
3793 ArrayPrimitives::destructiveMove(temp.d_dataBegin_p,
3794 this->d_dataBegin_p,
3796 this->allocatorRef());
3799 this->d_dataEnd_p = this->d_dataBegin_p;
3800 temp.d_dataEnd_p = ++pos;
3804template <
class VALUE_TYPE,
class ALLOCATOR>
3805void vector<VALUE_TYPE, ALLOCATOR>::privatePushBackWithAllocation(
3806 BloombergLP::bslmf::MovableRef<VALUE_TYPE> value)
3808 VALUE_TYPE& lvalue = value;
3811 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
3812 "vector<...>:push_back(rvalue): vector too long");
3819 vector temp(this->get_allocator());
3820 temp.privateReserveEmpty(newCapacity);
3823 VALUE_TYPE *pos = temp.d_dataBegin_p + this->size();
3824 AllocatorTraits::construct(this->allocatorRef(),
3826 MoveUtil::move(lvalue));
3830 Vector_PushProctor<VALUE_TYPE, ALLOCATOR> guard(pos, this->allocatorRef());
3831 ArrayPrimitives::destructiveMove(temp.d_dataBegin_p,
3832 this->d_dataBegin_p,
3834 this->allocatorRef());
3837 this->d_dataEnd_p = this->d_dataBegin_p;
3838 temp.d_dataEnd_p = ++pos;
3846template <
class VALUE_TYPE,
class ALLOCATOR>
3850, ContainerBase(ALLOCATOR())
3854template <
class VALUE_TYPE,
class ALLOCATOR>
3859, ContainerBase(basicAllocator)
3863template <
class VALUE_TYPE,
class ALLOCATOR>
3865 const ALLOCATOR& basicAllocator)
3867, ContainerBase(basicAllocator)
3871 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
3872 "vector<...>::vector(n,v): vector too long");
3874 if (initialSize > 0) {
3875 privateReserveEmpty(initialSize);
3876 Proctor proctor(this->d_dataBegin_p,
3878 static_cast<ContainerBase *
>(
this));
3880 ArrayPrimitives::defaultConstruct(this->d_dataBegin_p,
3882 this->allocatorRef());
3885 this->d_dataEnd_p += initialSize;
3889template <
class VALUE_TYPE,
class ALLOCATOR>
3891 const VALUE_TYPE& value,
3892 const ALLOCATOR& basicAllocator)
3894, ContainerBase(basicAllocator)
3898 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
3899 "vector<...>::vector(n,v): vector too long");
3901 if (initialSize > 0) {
3902 privateReserveEmpty(initialSize);
3903 Proctor proctor(this->d_dataBegin_p,
3905 static_cast<ContainerBase *
>(
this));
3907 ArrayPrimitives::uninitializedFillN(this->d_dataBegin_p,
3910 this->allocatorRef());
3913 this->d_dataEnd_p += initialSize;
3917template <
class VALUE_TYPE,
class ALLOCATOR>
3918template <
class INPUT_ITER>
3922 const ALLOCATOR& basicAllocator)
3924, ContainerBase(basicAllocator)
3933 constructFromRange(first, last, Tag());
3937template <
class VALUE_TYPE,
class ALLOCATOR>
3940, ContainerBase(
AllocatorTraits::select_on_container_copy_construction(
3941 original.get_allocator()))
3943 if (original.
size() > 0) {
3944 privateReserveEmpty(original.
size());
3945 Proctor proctor(this->d_dataBegin_p,
3947 static_cast<ContainerBase *
>(
this));
3949 ArrayPrimitives::copyConstruct(this->d_dataBegin_p,
3952 this->allocatorRef());
3955 this->d_dataEnd_p += original.
size();
3959template <
class VALUE_TYPE,
class ALLOCATOR>
3962 const typename type_identity<ALLOCATOR>::type& basicAllocator)
3964, ContainerBase(basicAllocator)
3966 if (original.
size() > 0) {
3967 privateReserveEmpty(original.
size());
3968 Proctor proctor(this->d_dataBegin_p,
3970 static_cast<ContainerBase *
>(
this));
3972 ArrayPrimitives::copyConstruct(this->d_dataBegin_p,
3975 this->allocatorRef());
3978 this->d_dataEnd_p += original.
size();
3982template <
class VALUE_TYPE,
class ALLOCATOR>
3984 BloombergLP::bslmf::MovableRef<vector> original)
3987, ContainerBase(MoveUtil::access(original).get_allocator())
3989 vector& lvalue = original;
3990 ImpBase::adopt(MoveUtil::move(
static_cast<ImpBase&
>(lvalue)));
3993template <
class VALUE_TYPE,
class ALLOCATOR>
3995 BloombergLP::bslmf::MovableRef<vector> original,
3996 const typename type_identity<ALLOCATOR>::type& basicAllocator)
3998, ContainerBase(basicAllocator)
4000 vector& lvalue = original;
4004 ImpBase::adopt(MoveUtil::move(
static_cast<ImpBase&
>(lvalue)));
4007 if (lvalue.
size() > 0) {
4008 privateReserveEmpty(lvalue.
size());
4009 Proctor proctor(this->d_dataBegin_p,
4011 static_cast<ContainerBase *
>(
this));
4013 ArrayPrimitives::moveConstruct(this->d_dataBegin_p,
4016 this->allocatorRef());
4019 this->d_dataEnd_p += lvalue.
size();
4024#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
4025template <
class VALUE_TYPE,
class ALLOCATOR>
4028 std::initializer_list<VALUE_TYPE> values,
4029 const ALLOCATOR& basicAllocator)
4031, ContainerBase(basicAllocator)
4033 if (values.begin() != values.end()) {
4034 constructFromRange(values.begin(),
4036 std::random_access_iterator_tag());
4042template <
class VALUE_TYPE,
class ALLOCATOR>
4043template <
class t_RANGE>
4049 const ALLOCATOR& basicAllocator)
4051, ContainerBase(basicAllocator)
4055 ranges::begin(range));
4058template <
class VALUE_TYPE,
class ALLOCATOR>
4062 using BloombergLP::bslalg::ArrayDestructionPrimitives;
4065#ifdef BSLS_PLATFORM_CMP_GNU
4066#pragma GCC diagnostic push
4067#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
4069 if (this->d_dataBegin_p) {
4070 ArrayDestructionPrimitives::destroy(this->d_dataBegin_p,
4072 this->allocatorRef());
4073 AllocatorUtil::deallocateObject(this->allocatorRef(),
4074 this->d_dataBegin_p, this->d_capacity);
4076#ifdef BSLS_PLATFORM_CMP_GNU
4077#pragma GCC diagnostic pop
4082template <
class VALUE_TYPE,
class ALLOCATOR>
4090 if (Propagate::value) {
4093 AllocatorUtil::swap(&this->allocatorRef(),
4094 &other.allocatorRef(),
4099 insert(this->begin(),
rhs.begin(),
rhs.end());
4105template <
class VALUE_TYPE,
class ALLOCATOR>
4109 AllocatorTraits::propagate_on_container_move_assignment::value ||
4110 AllocatorTraits::is_always_equal::value)
4113 AllocatorTraits::propagate_on_container_move_assignment Propagate;
4118 vector other(MoveUtil::move(lvalue));
4121 else if (Propagate::value) {
4122 vector other(MoveUtil::move(lvalue));
4123 AllocatorUtil::swap(&this->allocatorRef(),
4124 &other.allocatorRef(),
4129 vector other(MoveUtil::move(lvalue), this->allocatorRef());
4136#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
4137template <
class VALUE_TYPE,
class ALLOCATOR>
4139vector<VALUE_TYPE, ALLOCATOR>&
4141 std::initializer_list<VALUE_TYPE> values)
4143 this->
assign(values.begin(), values.end());
4147template <
class VALUE_TYPE,
class ALLOCATOR>
4150 std::initializer_list<VALUE_TYPE> values)
4152 assign(values.begin(), values.end());
4156template <
class VALUE_TYPE,
class ALLOCATOR>
4157template <
class INPUT_ITER>
4164 insert(this->begin(), first, last);
4167template <
class VALUE_TYPE,
class ALLOCATOR>
4170 const VALUE_TYPE& value)
4173 insert(this->begin(), numElements, value);
4176template <
class VALUE_TYPE,
class ALLOCATOR>
4177template <
class t_RANGE>
4179void
vector<VALUE_TYPE, ALLOCATOR>::assign_range(
4188template <
class VALUE_TYPE,
class ALLOCATOR>
4197 if (newSize <= this->size()) {
4198 BloombergLP::bslalg::ArrayDestructionPrimitives::destroy(
4199 this->d_dataBegin_p + newSize,
4201 this->allocatorRef());
4202 this->d_dataEnd_p = this->d_dataBegin_p + newSize;
4204 else if (0 == this->d_capacity) {
4207 vector temp(newSize, this->get_allocator());
4210 else if (newSize > this->d_capacity) {
4214 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4215 "vector<...>::resize(n): vector too long");
4219 newSize, this->d_capacity, maxSize);
4221 vector temp(this->get_allocator());
4222 temp.privateReserveEmpty(newCapacity);
4224 ArrayPrimitives::destructiveMoveAndInsert(temp.
d_dataBegin_p,
4226 this->d_dataBegin_p,
4229 newSize - this->size(),
4230 this->allocatorRef());
4236 ArrayPrimitives::defaultConstruct(this->d_dataEnd_p,
4237 newSize - this->size(),
4238 this->allocatorRef());
4239 this->d_dataEnd_p = this->d_dataBegin_p + newSize;
4243template <
class VALUE_TYPE,
class ALLOCATOR>
4245 const VALUE_TYPE& value)
4250 if (newSize <= this->size()) {
4251 BloombergLP::bslalg::ArrayDestructionPrimitives::destroy(
4252 this->d_dataBegin_p + newSize,
4254 this->allocatorRef());
4255 this->d_dataEnd_p = this->d_dataBegin_p + newSize;
4258 insert(this->d_dataEnd_p, newSize - this->size(), value);
4262template <
class VALUE_TYPE,
class ALLOCATOR>
4267 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4268 "vector<...>::reserve(newCapacity): vector too long");
4270 if (0 == this->d_capacity && 0 != newCapacity) {
4271 privateReserveEmpty(newCapacity);
4273 else if (this->d_capacity < newCapacity) {
4274 vector temp(this->get_allocator());
4275 temp.privateReserveEmpty(newCapacity);
4278 this->d_dataBegin_p,
4280 this->allocatorRef());
4283 this->d_dataEnd_p = this->d_dataBegin_p;
4288template <
class VALUE_TYPE,
class ALLOCATOR>
4291 if (this->size() < this->d_capacity) {
4292 vector temp(this->get_allocator());
4293 if (this->size() > 0) {
4294 temp.privateReserveEmpty(this->size());
4296 this->d_dataBegin_p,
4298 this->allocatorRef());
4301 this->d_dataEnd_p = this->d_dataBegin_p;
4309template <
class VALUE_TYPE,
class ALLOCATOR>
4310template <
class t_RANGE>
4312void
vector<VALUE_TYPE, ALLOCATOR>::append_range(
4316 ranges::begin(range));
4319#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
4320template <
class VALUE_TYPE,
class ALLOCATOR>
4321template <
class... Args>
4327 AllocatorTraits::construct(
4328 this->allocatorRef(),
4331 ++this->d_dataEnd_p;
4334 privateEmplaceBackWithAllocation(
4337 return *(this->d_dataEnd_p - 1);
4341template <
class VALUE_TYPE,
class ALLOCATOR>
4346 AllocatorTraits::construct(this->allocatorRef(),
4349 ++this->d_dataEnd_p;
4352 privatePushBackWithAllocation(value);
4356template <
class VALUE_TYPE,
class ALLOCATOR>
4359 BloombergLP::bslmf::MovableRef<VALUE_TYPE> value)
4361 VALUE_TYPE& lvalue = value;
4363 AllocatorTraits::construct(this->allocatorRef(),
4365 MoveUtil::move(lvalue));
4366 ++this->d_dataEnd_p;
4369 privatePushBackWithAllocation(MoveUtil::move(lvalue));
4373template <
class VALUE_TYPE,
class ALLOCATOR>
4379 AllocatorTraits::destroy(this->allocatorRef(),
4380 --this->d_dataEnd_p);
4383template <
class VALUE_TYPE,
class ALLOCATOR>
4387 const VALUE_TYPE& value)
4392 return insert(position,
size_type(1), value);
4395template <
class VALUE_TYPE,
class ALLOCATOR>
4399 BloombergLP::bslmf::MovableRef<VALUE_TYPE> value)
4407 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4408 "vector<...>::insert(pos,rv): vector too long");
4411 VALUE_TYPE& lvalue = value;
4413 const size_type index = position - this->begin();
4415 const size_type newSize = this->size() + 1;
4417 if (newSize > this->d_capacity) {
4423 vector temp(this->get_allocator());
4424 temp.privateReserveEmpty(newCapacity);
4426 ArrayPrimitives::destructiveMoveAndEmplace(temp.
d_dataBegin_p,
4428 this->d_dataBegin_p,
4431 this->allocatorRef(),
4432 MoveUtil::move(lvalue));
4438 ArrayPrimitives::insert(pos,
4440 MoveUtil::move(lvalue),
4441 this->allocatorRef());
4442 ++this->d_dataEnd_p;
4445 return this->begin() + index;
4448template <
class VALUE_TYPE,
class ALLOCATOR>
4452 const VALUE_TYPE& value)
4459 numElements > maxSize - this->size())) {
4461 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4462 "vector<...>::insert(pos,n,v): vector too long");
4465 const size_type index = position - this->begin();
4467 const size_type newSize = this->size() + numElements;
4469 if (newSize > this->d_capacity) {
4475 vector temp(this->get_allocator());
4476 temp.privateReserveEmpty(newCapacity);
4478 ArrayPrimitives::destructiveMoveAndInsert(temp.
d_dataBegin_p,
4480 this->d_dataBegin_p,
4485 this->allocatorRef());
4491 ArrayPrimitives::insert(pos,
4495 this->allocatorRef());
4496 this->d_dataEnd_p += numElements;
4498 return this->begin() + index;
4501#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
4502template <
class VALUE_TYPE,
class ALLOCATOR>
4506 const_iterator position,
4507 std::initializer_list<VALUE_TYPE> values)
4509 return insert(position, values.begin(), values.end());
4513template <
class VALUE_TYPE,
class ALLOCATOR>
4514template <
class t_RANGE>
4524 if (position == this->
cend()) {
4527 return this->begin() + oldSize;
4530 const size_type index = position - this->begin();
4531 this->privateInsert(position, ranges::begin(range), ranges::end(range));
4532 return this->begin() + index;
4535template <
class VALUE_TYPE,
class ALLOCATOR>
4543 return erase(position, position + 1);
4549template <
class VALUE_TYPE,
class ALLOCATOR>
4560 ArrayPrimitives::erase(
const_cast<VALUE_TYPE *
>(first),
4561 const_cast<VALUE_TYPE *
>(last),
4563 this->allocatorRef());
4564 this->d_dataEnd_p -= n;
4565 return const_cast<VALUE_TYPE *
>(first);
4568template <
class VALUE_TYPE,
class ALLOCATOR>
4571 AllocatorTraits::propagate_on_container_swap::value ||
4572 AllocatorTraits::is_always_equal::value)
4575 AllocatorTraits::propagate_on_container_swap Propagate;
4577 if (Propagate::value) {
4579 AllocatorUtil::swap(&this->allocatorRef(),
4580 &other.allocatorRef(),
4585 this->get_allocator() == other.get_allocator())) {
4591 vector toOtherCopy(MoveUtil::move(*
this),
4592 other.get_allocator());
4593 vector toThisCopy( MoveUtil::move(other),
4594 this->get_allocator());
4597 &other.d_dataBegin_p);
4599 &this->d_dataBegin_p);
4604template <
class VALUE_TYPE,
class ALLOCATOR>
4608 if (!this->
empty()) {
4609 BloombergLP::bslalg::ArrayDestructionPrimitives::destroy(
4610 this->d_dataBegin_p,
4612 this->allocatorRef());
4613 this->d_dataEnd_p = this->d_dataBegin_p;
4618template <
class VALUE_TYPE,
class ALLOCATOR>
4623 return this->allocatorRef();
4628template <
class VALUE_TYPE,
class ALLOCATOR>
4633 return AllocatorTraits::max_size(this->allocatorRef());