BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bslstl_vector_cpp03.h
Go to the documentation of this file.
1/// @file bslstl_vector_cpp03.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslstl_vector_cpp03.h -*-C++-*-
8
9// Automatically generated file. **DO NOT EDIT**
10
11#ifndef INCLUDED_BSLSTL_VECTOR_CPP03
12#define INCLUDED_BSLSTL_VECTOR_CPP03
13
14/// @defgroup bslstl_vector_cpp03 bslstl_vector_cpp03
15/// @brief Provide C++03 implementation for bslstl_vector.h
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslstl
19/// @{
20/// @addtogroup bslstl_vector_cpp03
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslstl_vector_cpp03-purpose"> Purpose</a>
25/// * <a href="#bslstl_vector_cpp03-classes"> Classes </a>
26/// * <a href="#bslstl_vector_cpp03-description"> Description </a>
27///
28/// # Purpose {#bslstl_vector_cpp03-purpose}
29/// Provide C++03 implementation for bslstl_vector.h
30///
31/// # Classes {#bslstl_vector_cpp03-classes}
32/// See bslstl_vector.h for list of classes
33///
34/// @see bslstl_vector
35///
36/// # Description {#bslstl_vector_cpp03-description}
37/// This component is the C++03 translation of a C++11 component,
38/// generated by the 'sim_cpp11_features.pl' program. If the original header
39/// contains any specially delimited regions of C++11 code, then this generated
40/// file contains the C++03 equivalent, i.e., with variadic templates expanded
41/// and rvalue-references replaced by 'bslmf::MovableRef' objects. The header
42/// code in this file is designed to be '#include'd into the original header
43/// when compiling with a C++03 compiler. If there are no specially delimited
44/// regions of C++11 code, then this header contains no code and is not
45/// '#include'd in the original header.
46///
47/// Generated on Thu Jul 02 08:20:06 2026
48/// Command line: sim_cpp11_features.py bslstl_vector.h
49/// @}
50/** @} */
51/** @} */
52
53/** @addtogroup bsl
54 * @{
55 */
56/** @addtogroup bslstl
57 * @{
58 */
59/** @addtogroup bslstl_vector_cpp03
60 * @{
61 */
62
63#ifdef COMPILING_BSLSTL_VECTOR_H
64
65namespace bsl {
66
67// Forward declarations
68
69template <class VALUE_TYPE, class ITERATOR>
70class vector_UintPtrConversionIterator;
71
72 // ==================
73 // struct Vector_Util
74 // ==================
75
76/// This `struct` provides a namespace for implementing the `swap` member
77/// function of `vector<VALUE_TYPE, ALLOCATOR>`. `swap` can be implemented
78/// irrespective of the `VALUE_TYPE` or `ALLOCATOR` template parameters, which
79/// is why we implement it in this non-parameterized, non-inlined utility.
80///
81/// See @ref bslstl_vector_cpp03
82struct Vector_Util {
83
84 // CLASS METHODS
85
86 /// Return a capacity that is at least the specified `newLength` and at
87 /// least twice the specified `capacity` if this is less than the specified
88 /// `maxSize`, but never more than `maxSize`.
89 ///
90 /// \pre The behavior is undefined unless `capacity < newLength` and `newLength <= maxSize`.
91 static std::size_t computeNewCapacity(std::size_t newLength,
92 std::size_t capacity,
93 std::size_t maxSize);
94
95 /// Exchange the value of the specified `a` vector with that of the
96 /// specified `b` vector.
97 static void swap(void *a, void *b);
98};
99
100
101 // ===================================
102 // class Vector_DeduceIteratorCategory
103 // ===================================
104
105/// This `struct` provides a primitive means to distinguish between iterator
106/// types and fundamental types, in order to dispatch to the correct
107/// implementation of a function template (or constructor template) passed
108/// two arguments of identical type. By default, it is assumed that any
109/// type that is not a fundamental type, as determined by the type trait
110/// `bsl::is_fundamental`, must be an iterator type. `std::iterator_traits`
111/// is updated in C++17 to provide a SFINAE-friendly instantiation of the
112/// primary-template for types that do not provide all of the nested typedef
113/// names, but we cannot portably rely on such a scheme yet.
114///
115/// See @ref bslstl_vector_cpp03
116template <class BSLSTL_ITERATOR,
117 bool BSLSTL_NOTSPECIALIZED = is_fundamental<BSLSTL_ITERATOR>::value>
118struct Vector_DeduceIteratorCategory {
119
120 // PUBLIC TYPES
121 typedef typename bsl::iterator_traits<BSLSTL_ITERATOR>::iterator_category
122 type;
123};
124
125/// This partial specialization of the `struct` template for fundamental
126/// types provides a nested `type` that is not an iterator category, so can
127/// be used to control the internal dispatch of function template overloads
128/// taking two arguments of the same type.
129template <class BSLSTL_ITERATOR>
130struct Vector_DeduceIteratorCategory<BSLSTL_ITERATOR, true> {
131
132 // PUBLIC TYPES
133 typedef BloombergLP::bslmf::Nil type;
134};
135
136
137 // ==================================
138 // class Vector_RangeIteratorCategory
139 // ==================================
140
141/// This `struct` provides a primitive means to determine the iterator category
142/// for an iterator/sentinel pair where there is a preference to treat any
143/// iterator where the `insertDistance` can be computed as a forward iterator,
144/// even if it does not meet the ranges concepts needed to be treated as one.
145///
146/// See @ref bslstl_vector_cpp03
147template <class t_ITERATOR,
148 class t_SENTINEL,
149 bool t_NOTSPECIALIZED =
152struct Vector_RangeIteratorCategory {
153
154 // PUBLIC TYPES
155#if defined(BSLS_LIBRARYFEATURES_HAS_CPP20_RANGES)
156 // Treat an iterator like an input iterator if we can compute an insert
157 // distance in a SFINAE-friendly manner, otherwise just treat it like an
158 // input iterator.
159 typedef bsl::conditional_t<
160 BloombergLP::bslstl::IteratorUtil
161 ::canCalculateInsertDistance<t_ITERATOR, t_SENTINEL>(),
162 typename bsl::iterator_traits<t_ITERATOR>::iterator_category,
163 std::input_iterator_tag> type;
164#else
165 typedef typename bsl::iterator_traits<t_ITERATOR>::iterator_category type;
166#endif
167};
168
169/// This partial specialization of the `struct` template for fundamental
170/// types provides a nested `type` that is not an iterator category, so can
171/// be used to control the internal dispatch of function template overloads
172/// taking two arguments of the same type.
173template <class t_ITERATOR, class t_SENTINEL>
174struct Vector_RangeIteratorCategory<t_ITERATOR, t_SENTINEL, true> {
175
176 // PUBLIC TYPES
177 typedef BloombergLP::bslmf::Nil type;
178};
179
180 // ======================================
181 // class vector_UintPtrConversionIterator
182 // ======================================
183
184/// This metafunction provides an appropriate iterator adaptor for the
185/// specified (template parameter) type `ITERATOR` in order to implement
186/// members of the `vector` partial template specialization for vectors of
187/// pointers to the (template parameter) type `TARGET`. The metafunction
188/// will return the original `ITERATOR` type unless it truly is an iterator,
189/// using `is_integral` as a proxy for testing that a type is NOT an
190/// iterator. This is needed to disambiguate only the cases of users
191/// passing `0` as a null-pointer value to functions requesting a number of
192/// identical copies of an element.
193///
194/// See @ref bslstl_vector_cpp03
195template <class TARGET, class ITERATOR, bool = is_integral<ITERATOR>::value>
196struct vector_ForwardIteratorForPtrs {
197
198 // PUBLIC TYPES
199 typedef ITERATOR type;
200};
201
202/// This metafunction specialization provides an appropriate iterator
203/// adaptor for the specified (template parameter) type `ITERATOR` in order
204/// to implement members of the `vector` partial template specialization for
205/// vectors of pointers to the (template parameter) type `TARGET`.
206template <class TARGET, class ITERATOR>
207struct vector_ForwardIteratorForPtrs<TARGET, ITERATOR, false> {
208
209 // PUBLIC TYPES
210 typedef vector_UintPtrConversionIterator<TARGET *, ITERATOR> type;
211};
212
213#if defined(BSLS_ASSERT_SAFE_IS_USED)
214
215template <class BSLSTL_ITERATOR>
216struct Vector_IsRandomAccessIterator :
217 bsl::is_same<typename Vector_DeduceIteratorCategory<BSLSTL_ITERATOR>::type,
218 bsl::random_access_iterator_tag>::type
219{
220};
221
222
223 // =======================
224 // class Vector_RangeCheck
225 // =======================
226
227/// This utility class provides a test-support facility to diagnose when a
228/// pair of iterators do *not* form a valid range. This support is offered
229/// only for random access iterators, and identifies only the case of two
230/// valid iterators into the same range forming a "reverse" range.
231///
232/// \note Note that the two functions declared using `enable_if` must be defined inline
233/// in the class definition due to a bug in the Microsoft C++ compiler (see
234/// @ref bslmf_enableif ).
235///
236/// See @ref bslstl_vector_cpp03
237struct Vector_RangeCheck {
238
239 // CLASS METHODS
240
241 /// Return `false`.
242 /// \note Note that we know of no way to identify an input
243 /// iterator range that is guaranteed to be invalid.
244 template <class BSLSTL_ITERATOR, class SENTINEL>
245 static
246 typename bsl::enable_if<
247 !Vector_IsRandomAccessIterator<BSLSTL_ITERATOR>::value, bool>::type
248 isInvalidRange(BSLSTL_ITERATOR, SENTINEL);
249
250 /// Return `true` if `last < first`, and `false` otherwise.
251 ///
252 /// \pre The behavior is undefined unless both `first` and `last` are valid
253 /// iterators that refer to the same range.
254 template <class BSLSTL_ITERATOR>
255 static
256 typename bsl::enable_if<
257 Vector_IsRandomAccessIterator<BSLSTL_ITERATOR>::value, bool>::type
258 isInvalidRange(BSLSTL_ITERATOR first, BSLSTL_ITERATOR last);
259 template <class BSLSTL_ITERATOR, class SENTINEL>
260 static
261 typename bsl::enable_if<
262 Vector_IsRandomAccessIterator<BSLSTL_ITERATOR>::value, bool>::type
263 isInvalidRange(BSLSTL_ITERATOR first, SENTINEL last);
264};
265
266#endif
267
268 // ================
269 // class vectorBase
270 // ================
271
272/// This class describes the basic layout for a vector class, to be included
273/// into the `vector` layout *before* the allocator (provided by
274/// `bslalg::ContainerBase`) to take better advantage of cache prefetching. It
275/// is parameterized by `VALUE_TYPE` only, and implements the portion of
276/// `vector` that does not need to know about its (template parameter) type
277/// `ALLOCATOR` (in order to generate shorter debug strings). This class
278/// intentionally has **no** creators (other than the compiler-generated ones).
279///
280/// See @ref bslstl_vector_cpp03
281template <class VALUE_TYPE>
282class vectorBase {
283
284 // PRIVATE TYPES
285
286 /// This `typedef` is a convenient alias for the utility associated with
287 /// movable references.
288 typedef BloombergLP::bslmf::MovableRefUtil MoveUtil;
289
290 protected:
291 // PROTECTED DATA
292 VALUE_TYPE *d_dataBegin_p; // beginning of data storage (owned)
293 VALUE_TYPE *d_dataEnd_p; // one past the end of data storage
294 std::size_t d_capacity; // capacity of data storage in # of elements
295
296 public:
297 // PUBLIC TYPES
298 typedef VALUE_TYPE value_type;
299 typedef VALUE_TYPE& reference;
300 typedef VALUE_TYPE const& const_reference;
301 typedef VALUE_TYPE *iterator;
302 typedef VALUE_TYPE const *const_iterator;
303 typedef std::size_t size_type;
304 typedef std::ptrdiff_t difference_type;
305 typedef bsl::reverse_iterator<iterator> reverse_iterator;
306 typedef bsl::reverse_iterator<const_iterator> const_reverse_iterator;
307
308 public:
309 // CREATORS
310
311 /// Create an empty base object with no capacity.
312 vectorBase();
313
314 // MANIPULATORS
315
316 /// Adopt all outstanding memory allocations associated with the specified `base` object.
317 ///
318 /// \pre The behavior is undefined unless this object is in a
319 /// default-constructed state.
320 void adopt(BloombergLP::bslmf::MovableRef<vectorBase> base);
321
322 // *** iterators ***
323
324 /// Return an iterator providing modifiable access to the first element in
325 /// this vector, or the past-the-end iterator if this vector is empty.
327
328 /// Return the past-the-end iterator providing modifiable access to this
329 /// vector.
331
332 /// Return a reverse iterator providing modifiable access to the last
333 /// element in this vector, and the past-the-end reverse iterator if this
334 /// vector is empty.
336
337 /// Return the past-the-end reverse iterator providing modifiable access to
338 /// this vector.
340
341 // *** element access ***
342
343 /// Return a reference providing modifiable access to the element at the specified `position` in this vector.
344 ///
345 /// \pre The behavior is undefined unless
346 /// `position < size()`.
347 reference operator[](size_type position);
348
349 /// Return a reference providing modifiable access to the element at the
350 /// specified `position` in this vector. Throw a `std::out_of_range`
351 /// exception if `position >= size()`.
352 reference at(size_type position);
353
354 /// Return a reference providing modifiable access to the first element in this vector.
355 ///
356 /// \pre The behavior is undefined unless this vector is not
357 /// empty.
359
360 /// Return a reference providing modifiable access to the last element in this vector.
361 ///
362 /// \pre The behavior is undefined unless this vector is not
363 /// empty.
364 reference back();
365
366 /// Return the address of the modifiable first element in this vector, or a
367 /// valid, but non-dereferenceable pointer value if this vector is empty.
368 VALUE_TYPE *data() BSLS_KEYWORD_NOEXCEPT;
369
370 // ACCESSORS
371
372 // *** iterators ***
373
375
376 /// Return an iterator providing non-modifiable access to the first element
377 /// in this vector, and the past-the-end iterator if this vector is empty.
379
381
382 /// Return the past-the-end (forward) iterator providing non-modifiable
383 /// access to this vector.
385
387
388 /// Return a reverse iterator providing non-modifiable access to the last
389 /// element in this vector, and the past-the-end reverse iterator if this
390 /// vector is empty.
392
394
395 /// Return the past-the-end reverse iterator providing non-modifiable
396 /// access to this vector.
398
399 // *** capacity ***
400
401 /// Return the number of elements in this vector.
403
404 /// Return the capacity of this vector, i.e., the maximum number of
405 /// elements for which resizing is guaranteed not to trigger a
406 /// reallocation.
408
409 /// Return `true` if this vector has size 0, and `false` otherwise.
410 bool empty() const BSLS_KEYWORD_NOEXCEPT;
411
412 // *** element access ***
413
414 /// Return a reference providing non-modifiable access to the element at
415 /// the specified `position` in this vector.
416 ///
417 /// \pre The behavior is undefined unless `position < size()`.
418 const_reference operator[](size_type position) const;
419
420 /// Return a reference providing non-modifiable access to the element at
421 /// the specified `position` in this vector. Throw a
422 /// `bsl::out_of_range` exception if `position >= size()`.
423 const_reference at(size_type position) const;
424
425 /// Return a reference providing non-modifiable access to the first element in this vector.
426 ///
427 /// \pre The behavior is undefined unless this
428 /// vector is not empty.
429 const_reference front() const;
430
431 /// Return a reference providing non-modifiable access to the last element in this vector.
432 ///
433 /// \pre The behavior is undefined unless this
434 /// vector is not empty.
435 const_reference back() const;
436
437 /// Return the address of the non-modifiable first element in this
438 /// vector, or a valid, but non-dereferenceable pointer value if this
439 /// vector is empty.
440 const VALUE_TYPE *data() const BSLS_KEYWORD_NOEXCEPT;
441};
442
443 // ============
444 // class vector
445 // ============
446
447/// This class template provides an STL-compliant `vector` that conforms to
448/// the `bslma::Allocator` model. For the requirements of a vector class,
449/// consult the C++11 standard. In particular, this implementation offers
450/// the general rules that:
451///
452/// 1. A call to any method that would result in a vector having a size
453/// or capacity greater than the value returned by @ref max_size triggers a
454/// call to `bslstl::StdExceptUtil::throwLengthError`.
455/// 2. A call to an `at` method that attempts to access a position outside
456/// of the valid range of a vector triggers a call to
457/// `bslstl::StdExceptUtil::throwOutOfRange`.
458///
459///
460/// \note Note that portions of the standard methods are implemented in
461/// `vectorBase`, which is parameterized on only `VALUE_TYPE` in order to
462/// generate smaller debug strings.
463///
464/// This class:
465/// * supports a complete set of *value-semantic* operations
466/// - except for `BDEX` serialization
467/// * is *exception-neutral*
468/// * is *alias-safe*
469/// * is `const` *thread-safe*
470/// For terminology see @ref bsldoc_glossary .
471///
472/// In addition, the following members offer a full guarantee of rollback: if
473/// an exception is thrown during the invocation of `push_back` or `insert`
474/// with a single element at the end of a pre-existing object, the object is
475/// left in a valid state and its value is unchanged.
476template <class VALUE_TYPE, class ALLOCATOR = allocator<VALUE_TYPE> >
477class vector : public vectorBase<VALUE_TYPE>
478 , private BloombergLP::bslalg::ContainerBase<ALLOCATOR> {
479
480 // PRIVATE TYPES
481
482 /// This `typedef` is an alias for a utility class that provides many
483 /// useful functions that operate on arrays.
484 typedef BloombergLP::bslalg::ArrayPrimitives ArrayPrimitives;
485
486 /// This `typedef` is a convenient alias for the utility associated with
487 /// movable references.
488 typedef BloombergLP::bslmf::MovableRefUtil MoveUtil;
489
490 /// This `typedef` is an alias for a utility class that provides many
491 /// useful functions that operate on allocators.
492 typedef BloombergLP::bslma::AllocatorUtil AllocatorUtil;
493
494 /// This `typedef` is an alias for the allocator traits type associated
495 /// with this container.
496 typedef allocator_traits<ALLOCATOR> AllocatorTraits;
497
498 public:
499 // PUBLIC TYPES
500 typedef VALUE_TYPE value_type;
501 typedef ALLOCATOR allocator_type;
502 typedef VALUE_TYPE& reference;
503 typedef const VALUE_TYPE& const_reference;
504
505 typedef typename AllocatorTraits::size_type size_type;
506 typedef typename AllocatorTraits::difference_type difference_type;
507 typedef typename AllocatorTraits::pointer pointer;
508 typedef typename AllocatorTraits::const_pointer const_pointer;
509
510 typedef VALUE_TYPE *iterator;
511 typedef VALUE_TYPE const *const_iterator;
512 typedef bsl::reverse_iterator<iterator> reverse_iterator;
513 typedef bsl::reverse_iterator<const_iterator> const_reverse_iterator;
514
515 private:
516 // PRIVATE TYPES
517
518 /// Implementation base type, with iterator-related functionality.
519 typedef vectorBase<VALUE_TYPE> ImpBase;
520
521 /// Container base type, containing the allocator and applying the empty
522 /// base class optimization (EBO) whenever appropriate.
523 typedef BloombergLP::bslalg::ContainerBase<ALLOCATOR> ContainerBase;
524
525 /// This class provides a proctor for deallocating an array of `VALUE_TYPE`
526 /// objects, to be used in the `vector` constructors.
527 ///
528 /// See @ref bslstl_vector_cpp03
529 class Proctor {
530
531 // DATA
532 VALUE_TYPE *d_data_p; // array pointer
533 std::size_t d_capacity; // capacity of the array
534 ContainerBase *d_container_p; // container base pointer
535
536 private:
537 // NOT IMPLEMENTED
538 Proctor(const Proctor&);
539 Proctor& operator=(const Proctor&);
540
541 public:
542 // CREATORS
543
544 /// Create a proctor for the specified `data` array of the specified
545 /// `capacity`, using the `deallocateN` method of the specified
546 /// `container` to return `data` to its allocator upon destruction,
547 /// unless this proctor's `release` is called prior.
548 Proctor(VALUE_TYPE *data,
549 std::size_t capacity,
550 ContainerBase *container);
551
552 /// Destroy this proctor, deallocating any data under management.
553 ~Proctor();
554
555 // MANIPULATORS
556
557 /// Release the data from management by this proctor.
558 void release();
559 };
560
561 // PRIVATE MANIPULATORS
562
563 /// Populate a default-constructed vector with the values held in the
564 /// specified `range`. This method should be called only from a constructor.
565 ///
566 /// \pre The behavior is undefined unless the specified `begin`
567 /// is the first element in `range`.
568 template <class t_RANGE, class t_ITERATOR>
569 void privateConstruct(from_range_t ,
571 t_ITERATOR begin);
572
573 /// Populate a default-constructed vector with the values held in the
574 /// specified `range`. This method should be called only from a constructor.
575 ///
576 /// \pre The behavior is undefined unless the specified `begin`
577 /// is the first element in `range`.
578 template <class t_RANGE, class t_ITERATOR>
579 void privateConstruct(from_range_t ,
581 t_ITERATOR begin,
582 std::forward_iterator_tag);
583 template <class t_RANGE, class t_ITERATOR>
584 void privateConstruct(from_range_t ,
586 t_ITERATOR begin,
587 std::input_iterator_tag);
588
589 /// Populate a default-constructed vector with the values held in the
590 /// specified range `[first, last)`. The additional
591 /// `std::*iterator__tag` should be a default-constructed tag that
592 /// corresponds to that found in `std::iterator_traits` for the
593 /// (template parameter) `*_ITER` type. This method should be called only from a constructor.
594 ///
595 /// \pre The behavior is undefined unless
596 /// `first != last`.
597 template <class FWD_ITER, class SENTINEL>
598 void constructFromRange(FWD_ITER first,
599 SENTINEL last,
600 std::forward_iterator_tag);
601 template <class INPUT_ITER, class SENTINEL>
602 void constructFromRange(INPUT_ITER first,
603 SENTINEL last,
604 std::input_iterator_tag);
605
606 /// Populate a default-constructed vector with the specified
607 /// `initialSize` elements, where each such element is a copy of the
608 /// specified `value`. The `bslmf::Nil` traits value distinguished this
609 /// overload of two identical (presumed integral) types from the pair of
610 /// iterator overloads above. This method should be called only from a
611 /// constructor.
612 template <class INTEGRAL>
613 void constructFromRange(INTEGRAL initialSize,
614 INTEGRAL value,
615 BloombergLP::bslmf::Nil);
616
617
618 /// Populate a default-constructed vector with the values held in the
619 /// specified `[first, last)` range. The specified `size` is the number
620 /// of elements in the range.
621 template <class t_ITERATOR, class t_SENTINEL>
622 void constructFromSizedRange(t_ITERATOR first,
623 t_SENTINEL last,
625
626 /// Append the values from the specified `range`.
627 ///
628 /// \pre The behavior is undefined unless the specified `begin` is the first element in `range`.
629 template <class t_RANGE, class t_ITERATOR>
630 void privateAppendRange(BSLS_COMPILERFEATURES_FORWARD_REF(t_RANGE) range,
631 t_ITERATOR begin);
632 template <class t_RANGE, class t_ITERATOR>
633 void privateAppendRange(BSLS_COMPILERFEATURES_FORWARD_REF(t_RANGE) range,
634 t_ITERATOR begin,
635 std::forward_iterator_tag);
636 template <class t_RANGE, class t_ITERATOR>
637 void privateAppendRange(BSLS_COMPILERFEATURES_FORWARD_REF(t_RANGE) range,
638 t_ITERATOR begin,
639 std::input_iterator_tag);
640
641 /// Append the values from the specified `[begin, end)` range. The
642 /// specified `rangeSize` is the number of elements in the range.
643 template <class t_ITERATOR, class t_SENTINEL>
644 void privateAppendSizedRange(t_ITERATOR begin,
645 t_SENTINEL end,
646 size_type rangeSize);
647
648 /// Append the values from the specified `[begin, end)` range.
649 template <class t_ITERATOR, class t_SENTINEL>
650 void privateAppendUnsizedRange(t_ITERATOR begin, t_SENTINEL end);
651
652 /// Match integral type for `INPUT_ITER`.
653 template <class INPUT_ITER>
654 void privateInsertDispatch(
655 const_iterator position,
656 INPUT_ITER count,
657 INPUT_ITER value,
658 BloombergLP::bslmf::MatchArithmeticType ,
659 BloombergLP::bslmf::Nil );
660
661 /// Match non-integral type for `INPUT_ITER`.
662 template <class INPUT_ITER>
663 void privateInsertDispatch(const_iterator position,
664 INPUT_ITER first,
665 INPUT_ITER last,
666 BloombergLP::bslmf::MatchAnyType ,
667 BloombergLP::bslmf::MatchAnyType );
668
669 /// Range insert implementation function.
670 template <class t_ITERATOR, class t_SENTINEL>
671 void privateInsert(const_iterator position,
672 t_ITERATOR first,
673 t_SENTINEL last);
674
675 /// Specialized insertion for input iterators.
676 template <class INPUT_ITER, class SENTINEL>
677 void privateInsert(const_iterator position,
678 INPUT_ITER first,
679 SENTINEL last,
680 const std::input_iterator_tag&);
681
682 /// Specialized insertion for forward, bidirectional, and random-access
683 /// iterators.
684 template <class FWD_ITER, class SENTINEL>
685 void privateInsert(const_iterator position,
686 FWD_ITER first,
687 SENTINEL last,
688 const std::forward_iterator_tag&);
689
690 /// Destructive move insertion from a temporary vector, to avoid
691 /// duplicate copies after importing from an input iterator into a
692 /// temporary vector.
693 void privateMoveInsert(vector *fromVector,
694 const_iterator position);
695
696 /// Reserve exactly the specified `numElements`.
697 ///
698 /// \pre The behavior is undefined unless this vector is empty and has no capacity.
699 void privateReserveEmpty(size_type numElements);
700
701#if BSLS_COMPILERFEATURES_SIMULATE_VARIADIC_TEMPLATES
702// {{{ BEGIN GENERATED CODE
703// Command line: sim_cpp11_features.py bslstl_vector.h
704#ifndef BSLSTL_VECTOR_VARIADIC_LIMIT
705#define BSLSTL_VECTOR_VARIADIC_LIMIT 10
706#endif
707#ifndef BSLSTL_VECTOR_VARIADIC_LIMIT_A
708#define BSLSTL_VECTOR_VARIADIC_LIMIT_A BSLSTL_VECTOR_VARIADIC_LIMIT
709#endif
710#if BSLSTL_VECTOR_VARIADIC_LIMIT_A >= 0
711 void privateEmplaceBackWithAllocation(
712 );
713#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_A >= 0
714
715#if BSLSTL_VECTOR_VARIADIC_LIMIT_A >= 1
716 template <class Args_01>
717 void privateEmplaceBackWithAllocation(
718 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01);
719#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_A >= 1
720
721#if BSLSTL_VECTOR_VARIADIC_LIMIT_A >= 2
722 template <class Args_01,
723 class Args_02>
724 void privateEmplaceBackWithAllocation(
725 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
726 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02);
727#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_A >= 2
728
729#if BSLSTL_VECTOR_VARIADIC_LIMIT_A >= 3
730 template <class Args_01,
731 class Args_02,
732 class Args_03>
733 void privateEmplaceBackWithAllocation(
734 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
735 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
736 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03);
737#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_A >= 3
738
739#if BSLSTL_VECTOR_VARIADIC_LIMIT_A >= 4
740 template <class Args_01,
741 class Args_02,
742 class Args_03,
743 class Args_04>
744 void privateEmplaceBackWithAllocation(
745 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
746 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
747 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
748 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04);
749#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_A >= 4
750
751#if BSLSTL_VECTOR_VARIADIC_LIMIT_A >= 5
752 template <class Args_01,
753 class Args_02,
754 class Args_03,
755 class Args_04,
756 class Args_05>
757 void privateEmplaceBackWithAllocation(
758 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
759 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
760 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
761 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
762 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05);
763#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_A >= 5
764
765#if BSLSTL_VECTOR_VARIADIC_LIMIT_A >= 6
766 template <class Args_01,
767 class Args_02,
768 class Args_03,
769 class Args_04,
770 class Args_05,
771 class Args_06>
772 void privateEmplaceBackWithAllocation(
773 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
774 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
775 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
776 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
777 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
778 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06);
779#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_A >= 6
780
781#if BSLSTL_VECTOR_VARIADIC_LIMIT_A >= 7
782 template <class Args_01,
783 class Args_02,
784 class Args_03,
785 class Args_04,
786 class Args_05,
787 class Args_06,
788 class Args_07>
789 void privateEmplaceBackWithAllocation(
790 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
791 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
792 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
793 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
794 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
795 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06,
796 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) arguments_07);
797#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_A >= 7
798
799#if BSLSTL_VECTOR_VARIADIC_LIMIT_A >= 8
800 template <class Args_01,
801 class Args_02,
802 class Args_03,
803 class Args_04,
804 class Args_05,
805 class Args_06,
806 class Args_07,
807 class Args_08>
808 void privateEmplaceBackWithAllocation(
809 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
810 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
811 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
812 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
813 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
814 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06,
815 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) arguments_07,
816 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) arguments_08);
817#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_A >= 8
818
819#if BSLSTL_VECTOR_VARIADIC_LIMIT_A >= 9
820 template <class Args_01,
821 class Args_02,
822 class Args_03,
823 class Args_04,
824 class Args_05,
825 class Args_06,
826 class Args_07,
827 class Args_08,
828 class Args_09>
829 void privateEmplaceBackWithAllocation(
830 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
831 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
832 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
833 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
834 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
835 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06,
836 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) arguments_07,
837 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) arguments_08,
838 BSLS_COMPILERFEATURES_FORWARD_REF(Args_09) arguments_09);
839#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_A >= 9
840
841#if BSLSTL_VECTOR_VARIADIC_LIMIT_A >= 10
842 template <class Args_01,
843 class Args_02,
844 class Args_03,
845 class Args_04,
846 class Args_05,
847 class Args_06,
848 class Args_07,
849 class Args_08,
850 class Args_09,
851 class Args_10>
852 void privateEmplaceBackWithAllocation(
853 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
854 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
855 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
856 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
857 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
858 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06,
859 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) arguments_07,
860 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) arguments_08,
861 BSLS_COMPILERFEATURES_FORWARD_REF(Args_09) arguments_09,
862 BSLS_COMPILERFEATURES_FORWARD_REF(Args_10) arguments_10);
863#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_A >= 10
864
865#else
866// The generated code below is a workaround for the absence of perfect
867// forwarding in some compilers.
868 template <class... Args>
869 void privateEmplaceBackWithAllocation(
870 BSLS_COMPILERFEATURES_FORWARD_REF(Args)...arguments);
871// }}} END GENERATED CODE
872#endif
873
874 /// Append a copy of the specified `value` to the end of this vector
875 /// after changing its capacity. If an exception is thrown, `*this` is
876 /// unaffected. Throw `std::length_error` if `size() == max_size()`.
877 void privatePushBackWithAllocation(const VALUE_TYPE& value);
878
879 /// Append the specified move-insertable `value` to the end of this
880 /// vector after changing its capacity. `value` is left in a valid but
881 /// unspecified state. If an exception is thrown (other than by the
882 /// move constructor of a non-copy-insertable `value_type`), `*this` is
883 /// unaffected. Throw `std::length_error` if `size() == max_size()`.
884 void privatePushBackWithAllocation(
885 BloombergLP::bslmf::MovableRef<VALUE_TYPE> value);
886
887 public:
888 // CREATORS
889
890 // *** construct/copy/destroy ***
891
892 vector() BSLS_KEYWORD_NOEXCEPT;
893
894 /// Create an empty vector. Optionally specify a `basicAllocator` used
895 /// to supply memory. If `basicAllocator` is not specified, a
896 /// default-constructed object of the (template parameter) type
897 /// `ALLOCATOR` is used. If the type `ALLOCATOR` is `bsl::allocator`
898 /// and `basicAllocator` is not supplied, the currently installed default allocator is used.
899 ///
900 /// \note Note that a `bslma::Allocator *` can be
901 /// supplied for `basicAllocator` if the type `ALLOCATOR` is
902 /// `bsl::allocator` (the default).
903 explicit vector(const ALLOCATOR& basicAllocator) BSLS_KEYWORD_NOEXCEPT;
904
905 /// Create a vector of the specified `initialSize` whose every element
906 /// is a default-constructed object of the (template parameter) type
907 /// `VALUE_TYPE`. Optionally specify a `basicAllocator` used to supply
908 /// memory. If `basicAllocator` is not specified, a default-constructed
909 /// object of the (template parameter) type `ALLOCATOR` is used. If the
910 /// type `ALLOCATOR` is `bsl::allocator` and `basicAllocator` is not
911 /// supplied, the currently installed default allocator is used. Throw
912 /// `std::length_error` if `initialSize > max_size()`. This method
913 /// requires that the type `VALUE_TYPE` be `default-insertable` into this vector (see {Requirements on `VALUE_TYPE`}).
914 ///
915 /// \note Note that a
916 /// `bslma::Allocator *` can be supplied for `basicAllocator` if the
917 /// type `ALLOCATOR` is `bsl::allocator` (the default).
918 explicit vector(size_type initialSize,
919 const ALLOCATOR& basicAllocator = ALLOCATOR());
920
921 /// Create a vector of the specified `initialSize` whose every element
922 /// is a copy of the specified `value`. Optionally specify a
923 /// `basicAllocator` used to supply memory. If `basicAllocator` is not
924 /// specified, a default-constructed object of the (template parameter)
925 /// type `ALLOCATOR` is used. If the type `ALLOCATOR` is
926 /// `bsl::allocator` and `basicAllocator` is not supplied, the currently
927 /// installed default allocator is used. Throw `std::length_error` if
928 /// `initialSize > max_size()`. This method requires that the (template
929 /// parameter) type `VALUE_TYPE` be `copy-insertable` into this vector (see {Requirements on `VALUE_TYPE`}).
930 ///
931 /// \note Note that a
932 /// `bslma::Allocator *` can be supplied for `basicAllocator` if the
933 /// type `ALLOCATOR` is `bsl::allocator` (the default).
934 vector(size_type initialSize,
935 const VALUE_TYPE& value,
936 const ALLOCATOR& basicAllocator = ALLOCATOR());
937
938 /// Create a vector, and insert (in order) each `VALUE_TYPE` object in
939 /// the range starting at the specified `first` element, and ending
940 /// immediately before the specified `last` element. Optionally specify
941 /// a `basicAllocator` used to supply memory. If `basicAllocator` is
942 /// not specified, a default-constructed object of the (template
943 /// parameter) type `ALLOCATOR` is used. If the type `ALLOCATOR` is
944 /// `bsl::allocator` and `basicAllocator` is not supplied, the currently
945 /// installed default allocator is used. Throw `std::length_error` if
946 /// the number of elements in `[first .. last)` exceeds the value
947 /// returned by the method @ref max_size . The (template parameter) type
948 /// `INPUT_ITER` shall meet the requirements of an input iterator
949 /// defined in the C++11 standard [24.2.3] providing access to values of
950 /// a type convertible to `value_type`, and `value_type` must be
951 /// `emplace-constructible` from `*i` into this vector, where `i` is a
952 /// dereferenceable iterator in the range `[first .. last)` (see {Requirements on `VALUE_TYPE`}).
953 ///
954 /// \pre The behavior is undefined unless
955 /// `first` and `last` refer to a range of valid values where `first` is at a position at or before `last`.
956 ///
957 /// \note Note that a
958 /// `bslma::Allocator *` can be supplied for `basicAllocator` if the
959 /// type `ALLOCATOR` is `bsl::allocator` (the default).
960 template <class INPUT_ITER>
961 vector(INPUT_ITER first,
962 INPUT_ITER last,
963 const ALLOCATOR& basicAllocator = ALLOCATOR());
964
965 /// Create a vector from the elements of the specifed `range`. Optionally
966 /// specify a `basicAllocator` used to supply memory. If `basicAllocator`
967 /// is not specified, a default-constructed object of the (template parameter) type `ALLOCATOR` is used.
968 ///
969 /// \note Note that `range` must meet the
970 /// requirements of an input range and the values from `range` must have a
971 /// type matching or convertible to (template parameter) `VALUE_TYPE`.
972 template <class t_RANGE>
974 vector(from_range_t ,
976 const ALLOCATOR& basicAllocator =
977 ALLOCATOR());
978
979 /// Create a vector having the same value as the specified `original`
980 /// object. Use the allocator returned by
981 /// 'bsl::allocator_traits<ALLOCATOR>::
982 /// select_on_container_copy_construction(original.get_allocator())' to
983 /// allocate memory. This method requires that the (template parameter)
984 /// type `VALUE_TYPE` be `copy-insertable` into this vector (see
985 /// {Requirements on `VALUE_TYPE`}).
986 vector(const vector& original);
987
988 /// Create a vector having the same value as the specified `original`
989 /// object by moving (in constant time) the contents of `original` to
990 /// the new vector. The allocator associated with `original` is
991 /// propagated for use in the newly-created vector. `original` is left
992 /// in a valid but unspecified state.
993 vector(BloombergLP::bslmf::MovableRef<vector> original)
994 BSLS_KEYWORD_NOEXCEPT; // IMPLICIT
995
996 /// Create a vector having the same value as the specified `original`
997 /// object that uses the specified `basicAllocator` to supply memory.
998 /// This method requires that the (template parameter) type `VALUE_TYPE`
999 /// be `copy-insertable` into this vector (see {Requirements on `VALUE_TYPE`}).
1000 ///
1001 /// \note Note that a `bslma::Allocator *` can be supplied
1002 /// for `basicAllocator` if the (template parameter) type `ALLOCATOR` is
1003 /// `bsl::allocator` (the default).
1004 vector(const vector& original,
1005 const typename type_identity<ALLOCATOR>::type& basicAllocator);
1006
1007 /// Create a vector having the same value as the specified `original`
1008 /// object that uses the specified `basicAllocator` to supply memory.
1009 /// The contents of `original` are moved (in constant time) to the new
1010 /// vector if `basicAllocator == original.get_allocator()`, and are
1011 /// move-inserted (in linear time) using `basicAllocator` otherwise.
1012 /// `original` is left in a valid but unspecified state. This method
1013 /// requires that the (template parameter) type `VALUE_TYPE` be
1014 /// `move-insertable` into this vector (see {Requirements on `VALUE_TYPE`}).
1015 ///
1016 /// \note Note that a `bslma::Allocator *` can be supplied
1017 /// for `basicAllocator` if the (template parameter) type `ALLOCATOR` is
1018 /// `bsl::allocator` (the default).
1019 vector(BloombergLP::bslmf::MovableRef<vector> original,
1020 const typename type_identity<ALLOCATOR>::type& basicAllocator);
1021
1022#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
1023 /// Create a vector and insert (in order) each `VALUE_TYPE` object in
1024 /// the specified `values` initializer list. Optionally specify a
1025 /// `basicAllocator` used to supply memory. If `basicAllocator` is not
1026 /// specified, a default-constructed object of the (template parameter)
1027 /// type `ALLOCATOR` is used. If the type `ALLOCATOR` is
1028 /// `bsl::allocator` and `basicAllocator` is not supplied, the currently
1029 /// installed default allocator is used. This method requires that the
1030 /// (template parameter) type `VALUE_TYPE` be `copy-insertable` into this vector (see {Requirements on `VALUE_TYPE`}).
1031 ///
1032 /// \note Note that a
1033 /// `bslma::Allocator *` can be supplied for `basicAllocator` if the
1034 /// type `ALLOCATOR` is `bsl::allocator` (the default).
1035 vector(std::initializer_list<VALUE_TYPE> values,
1036 const ALLOCATOR& basicAllocator = ALLOCATOR());
1037 // IMPLICIT
1038#endif
1039
1040 /// Destroy this vector.
1041 ~vector();
1042
1043 // MANIPULATORS
1044
1045 /// Assign to this object the value of the specified `rhs` object,
1046 /// propagate to this object the allocator of `rhs` if the `ALLOCATOR`
1047 /// type has trait @ref propagate_on_container_copy_assignment , and return
1048 /// a reference providing modifiable access to this object. If an
1049 /// exception is thrown, `*this` is left in a valid but unspecified
1050 /// state. This method requires that the (template parameter) type
1051 /// `VALUE_TYPE` be `copy-assignable` and `copy-insertable` into this
1052 /// vector (see {Requirements on `VALUE_TYPE`}).
1053 vector& operator=(const vector& rhs);
1054
1055 /// Assign to this object the value of the specified `rhs` object,
1056 /// propagate to this object the allocator of `rhs` if the `ALLOCATOR`
1057 /// type has trait @ref propagate_on_container_move_assignment , and return
1058 /// a reference providing modifiable access to this object. The
1059 /// contents of `rhs` are moved (in constant time) to this vector if
1060 /// `get_allocator() == rhs.get_allocator()` (after accounting for the
1061 /// aforementioned trait); otherwise, all elements in this vector are
1062 /// either destroyed or move-assigned to and each additional element in
1063 /// `rhs` is move-inserted into this vector. `rhs` is left in a valid
1064 /// but unspecified state, and if an exception is thrown, `*this` is
1065 /// left in a valid but unspecified state. This method requires that
1066 /// the (template parameter) type `VALUE_TYPE` be `move-assignable` and
1067 /// `move-insertable` into this vector (see {Requirements on `VALUE_TYPE`}).
1068 ///
1069 /// \note Note that the `vector` template arguments must be
1070 /// explicitly spelled out to work around an MSVC 2022 bug, see DRQS
1071 /// 171087946.
1072 vector& operator=(
1073 BloombergLP::bslmf::MovableRef<vector<VALUE_TYPE, ALLOCATOR> > rhs)
1075 AllocatorTraits::propagate_on_container_move_assignment::value ||
1076 AllocatorTraits::is_always_equal::value);
1077
1078#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
1079 /// Assign to this object the value resulting from first clearing this
1080 /// vector and then inserting (in order) each `VALUE_TYPE` object in the
1081 /// specified `values` initializer list, and return a reference
1082 /// providing modifiable access to this object. If an exception is
1083 /// thrown, `*this` is left in a valid but unspecified state. This
1084 /// method requires that the (template parameter) type `VALUE_TYPE` be
1085 /// `copy-insertable` into this vector (see {Requirements on
1086 /// `VALUE_TYPE`}).
1087 vector& operator=(std::initializer_list<VALUE_TYPE> values);
1088
1089 /// Assign to this object the value resulting from first clearing this
1090 /// vector and then inserting (in order) each `VALUE_TYPE` object in the
1091 /// specified `values` initializer list. If an exception is thrown,
1092 /// `*this` is left in a valid but unspecified state. This method
1093 /// requires that the (template parameter) type `VALUE_TYPE` be
1094 /// `copy-insertable` into this vector (see {Requirements on
1095 /// `VALUE_TYPE`}).
1096 void assign(std::initializer_list<VALUE_TYPE> values);
1097#endif
1098
1099 /// Assign to this object the value resulting from first clearing this
1100 /// vector and then inserting (in order) each `value_type` object in the
1101 /// range starting at the specified `first` element, and ending
1102 /// immediately before the specified `last` element. If an exception is
1103 /// thrown, `*this` is left in a valid but unspecified state. Throw
1104 /// `std::length_error` if `distance(first,last) > max_size()`. The
1105 /// (template parameter) type `INPUT_ITER` shall meet the requirements
1106 /// of an input iterator defined in the C++11 standard [24.2.3]
1107 /// providing access to values of a type convertible to `value_type`,
1108 /// and `value_type` must be `emplace-constructible` from `*i` into this
1109 /// vector, where `i` is a dereferenceable iterator in the range
1110 /// `[first .. last)` (see {Requirements on `VALUE_TYPE`}).
1111 ///
1112 /// \pre The behavior is undefined unless `first` and `last` refer to a range of
1113 /// valid values where `first` is at a position at or before `last`.
1114 template <class INPUT_ITER>
1115 void assign(INPUT_ITER first, INPUT_ITER last);
1116
1117 /// Assign to this object the value resulting from first clearing this
1118 /// vector and then inserting the specified `numElements` copies of the
1119 /// specified `value`. If an exception is thrown, `*this` is left in a
1120 /// valid but unspecified state. Throw `std::length_error` if
1121 /// `numElements > max_size()`. This method requires that the (template
1122 /// parameter) type `VALUE_TYPE` be `copy-insertable` into this vector
1123 /// (see {Requirements on `VALUE_TYPE`}).
1124 void assign(size_type numElements, const VALUE_TYPE& value);
1125
1126 /// Assign to this object the elements of the specified `range`.
1127 ///
1128 /// \note Note that `range` must meet the requirements of an input range and the values
1129 /// from `range` must have a type matching or convertible to (template
1130 /// parameter) `VALUE_TYPE`.
1131 template <class t_RANGE>
1133 void assign_range(BSLS_COMPILERFEATURES_FORWARD_REF(t_RANGE) range);
1134
1135 // *** capacity ***
1136
1137 /// Change the size of this vector to the specified `newSize`. If
1138 /// `newSize < size()`, the elements in the range `[newSize .. size())`
1139 /// are erased, and this function does not throw. If
1140 /// `newSize > size()`, the (newly created) elements in the range
1141 /// `[size() .. newSize)` are default-constructed `value_type` objects,
1142 /// and if an exception is thrown (other than by the move constructor of
1143 /// a non-copy-insertable `value_type`), `*this` is unaffected. Throw
1144 /// `std::length_error` if `newSize > max_size()`. This method requires
1145 /// that the (template parameter) type `VALUE_TYPE` be
1146 /// `default-insertable` and `move-insertable` into this vector (see
1147 /// {Requirements on `VALUE_TYPE`}).
1148 void resize(size_type newSize);
1149
1150 /// Change the size of this vector to the specified `newSize`, inserting
1151 /// `newSize - size()` copies of the specified `value` at the end of
1152 /// this vector if `newSize > size()`. If `newSize < size()`, the
1153 /// elements in the range `[newSize .. size())` are erased, `value` is
1154 /// ignored, and this method does not throw. If `newSize > size()` and
1155 /// an exception is thrown, `*this` is unaffected. Throw
1156 /// `std::length_error` if `newSize > max_size()`. This method requires
1157 /// that the (template parameter) type `VALUE_TYPE` be `copy-insertable`
1158 /// into this vector (see {Requirements on `VALUE_TYPE`}).
1159 void resize(size_type newSize, const VALUE_TYPE& value);
1160
1161 /// Change the capacity of this vector to the specified `newCapacity`.
1162 /// If an exception is thrown (other than by the move constructor of a
1163 /// non-copy-insertable `value_type`), `*this` is unaffected. Throw
1164 /// `bsl::length_error` if `newCapacity > max_size()`. This method
1165 /// requires that the (template parameter) type `VALUE_TYPE` be
1166 /// `move-insertable` into this vector (see {Requirements on `VALUE_TYPE`}).
1167 ///
1168 /// \note Note that the capacity of this vector after this
1169 /// operation has completed may be greater than `newCapacity`.
1170 void reserve(size_type newCapacity);
1171
1172 /// Reduce the capacity of this vector to its size. If an exception is
1173 /// thrown (other than by the move constructor of a non-copy-insertable `value_type`), `*this` is unaffected.
1174 ///
1175 /// \note Note that this method has no
1176 /// effect if the capacity is equivalent to the size.
1177 void shrink_to_fit();
1178
1179 // *** modifiers ***
1180
1181 /// Append to the end of this object the elements of the specified `range`.
1182 ///
1183 /// \note Note that `range` must meet the requirements of an input range and the
1184 /// values from `range` must have a type matching or convertible to
1185 /// (template parameter) `VALUE_TYPE`.
1186 template <class t_RANGE>
1188 void append_range(BSLS_COMPILERFEATURES_FORWARD_REF(t_RANGE) range);
1189
1190#if BSLS_COMPILERFEATURES_SIMULATE_VARIADIC_TEMPLATES
1191// {{{ BEGIN GENERATED CODE
1192// Command line: sim_cpp11_features.py bslstl_vector.h
1193#ifndef BSLSTL_VECTOR_VARIADIC_LIMIT
1194#define BSLSTL_VECTOR_VARIADIC_LIMIT 10
1195#endif
1196#ifndef BSLSTL_VECTOR_VARIADIC_LIMIT_B
1197#define BSLSTL_VECTOR_VARIADIC_LIMIT_B BSLSTL_VECTOR_VARIADIC_LIMIT
1198#endif
1199#if BSLSTL_VECTOR_VARIADIC_LIMIT_B >= 0
1200 VALUE_TYPE &emplace_back(
1201 );
1202#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_B >= 0
1203
1204#if BSLSTL_VECTOR_VARIADIC_LIMIT_B >= 1
1205 template <class Args_01>
1206 VALUE_TYPE &emplace_back(
1207 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01);
1208#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_B >= 1
1209
1210#if BSLSTL_VECTOR_VARIADIC_LIMIT_B >= 2
1211 template <class Args_01,
1212 class Args_02>
1213 VALUE_TYPE &emplace_back(
1214 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
1215 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02);
1216#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_B >= 2
1217
1218#if BSLSTL_VECTOR_VARIADIC_LIMIT_B >= 3
1219 template <class Args_01,
1220 class Args_02,
1221 class Args_03>
1222 VALUE_TYPE &emplace_back(
1223 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
1224 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
1225 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03);
1226#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_B >= 3
1227
1228#if BSLSTL_VECTOR_VARIADIC_LIMIT_B >= 4
1229 template <class Args_01,
1230 class Args_02,
1231 class Args_03,
1232 class Args_04>
1233 VALUE_TYPE &emplace_back(
1234 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
1235 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
1236 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
1237 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04);
1238#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_B >= 4
1239
1240#if BSLSTL_VECTOR_VARIADIC_LIMIT_B >= 5
1241 template <class Args_01,
1242 class Args_02,
1243 class Args_03,
1244 class Args_04,
1245 class Args_05>
1246 VALUE_TYPE &emplace_back(
1247 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
1248 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
1249 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
1250 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
1251 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05);
1252#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_B >= 5
1253
1254#if BSLSTL_VECTOR_VARIADIC_LIMIT_B >= 6
1255 template <class Args_01,
1256 class Args_02,
1257 class Args_03,
1258 class Args_04,
1259 class Args_05,
1260 class Args_06>
1261 VALUE_TYPE &emplace_back(
1262 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
1263 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
1264 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
1265 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
1266 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
1267 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06);
1268#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_B >= 6
1269
1270#if BSLSTL_VECTOR_VARIADIC_LIMIT_B >= 7
1271 template <class Args_01,
1272 class Args_02,
1273 class Args_03,
1274 class Args_04,
1275 class Args_05,
1276 class Args_06,
1277 class Args_07>
1278 VALUE_TYPE &emplace_back(
1279 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
1280 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
1281 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
1282 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
1283 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
1284 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06,
1285 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) arguments_07);
1286#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_B >= 7
1287
1288#if BSLSTL_VECTOR_VARIADIC_LIMIT_B >= 8
1289 template <class Args_01,
1290 class Args_02,
1291 class Args_03,
1292 class Args_04,
1293 class Args_05,
1294 class Args_06,
1295 class Args_07,
1296 class Args_08>
1297 VALUE_TYPE &emplace_back(
1298 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
1299 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
1300 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
1301 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
1302 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
1303 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06,
1304 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) arguments_07,
1305 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) arguments_08);
1306#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_B >= 8
1307
1308#if BSLSTL_VECTOR_VARIADIC_LIMIT_B >= 9
1309 template <class Args_01,
1310 class Args_02,
1311 class Args_03,
1312 class Args_04,
1313 class Args_05,
1314 class Args_06,
1315 class Args_07,
1316 class Args_08,
1317 class Args_09>
1318 VALUE_TYPE &emplace_back(
1319 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
1320 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
1321 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
1322 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
1323 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
1324 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06,
1325 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) arguments_07,
1326 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) arguments_08,
1327 BSLS_COMPILERFEATURES_FORWARD_REF(Args_09) arguments_09);
1328#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_B >= 9
1329
1330#if BSLSTL_VECTOR_VARIADIC_LIMIT_B >= 10
1331 template <class Args_01,
1332 class Args_02,
1333 class Args_03,
1334 class Args_04,
1335 class Args_05,
1336 class Args_06,
1337 class Args_07,
1338 class Args_08,
1339 class Args_09,
1340 class Args_10>
1341 VALUE_TYPE &emplace_back(
1342 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
1343 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
1344 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
1345 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
1346 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
1347 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06,
1348 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) arguments_07,
1349 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) arguments_08,
1350 BSLS_COMPILERFEATURES_FORWARD_REF(Args_09) arguments_09,
1351 BSLS_COMPILERFEATURES_FORWARD_REF(Args_10) arguments_10);
1352#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_B >= 10
1353
1354#else
1355// The generated code below is a workaround for the absence of perfect
1356// forwarding in some compilers.
1357 template <class... Args>
1358 VALUE_TYPE &emplace_back(
1359 BSLS_COMPILERFEATURES_FORWARD_REF(Args)... arguments);
1360// }}} END GENERATED CODE
1361#endif
1362
1363 /// Append to the end of this vector a copy of the specified `value`.
1364 /// If an exception is thrown, `*this` is unaffected. Throw
1365 /// `std::length_error` if `size() == max_size()`. This method
1366 /// requires that the (template parameter) type `VALUE_TYPE` be
1367 /// `copy-constructible` (see {Requirements on `VALUE_TYPE`}).
1368 void push_back(const VALUE_TYPE& value);
1369
1370 /// Append to the end of this vector the specified move-insertable
1371 /// `value`. `value` is left in a valid but unspecified state. If an
1372 /// exception is thrown (other than by the move constructor of a
1373 /// non-copy-insertable `value_type`), `*this` is unaffected. Throw
1374 /// `std::length_error` if `size() == max_size()`. This method requires
1375 /// that the (template parameter) type `VALUE_TYPE` be `move-insertable`
1376 /// into this vector (see {Requirements on `VALUE_TYPE`}).
1377 void push_back(BloombergLP::bslmf::MovableRef<VALUE_TYPE> value);
1378
1379 /// Erase the last element from this vector.
1380 ///
1381 /// \pre The behavior is undefined if this vector is empty.
1382 void pop_back();
1383
1384#if BSLS_COMPILERFEATURES_SIMULATE_VARIADIC_TEMPLATES
1385// {{{ BEGIN GENERATED CODE
1386// Command line: sim_cpp11_features.py bslstl_vector.h
1387#ifndef BSLSTL_VECTOR_VARIADIC_LIMIT
1388#define BSLSTL_VECTOR_VARIADIC_LIMIT 10
1389#endif
1390#ifndef BSLSTL_VECTOR_VARIADIC_LIMIT_C
1391#define BSLSTL_VECTOR_VARIADIC_LIMIT_C BSLSTL_VECTOR_VARIADIC_LIMIT
1392#endif
1393#if BSLSTL_VECTOR_VARIADIC_LIMIT_C >= 0
1394 iterator emplace(const_iterator position)
1395 {
1396 BSLS_ASSERT_SAFE(this->begin() <= position);
1397 BSLS_ASSERT_SAFE(position <= this->end());
1398
1399 const size_type index = position - this->begin();
1400
1401 const iterator& pos = const_cast<const iterator&>(position);
1402
1403 const size_type maxSize = max_size();
1405 maxSize - this->size())) {
1407 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
1408 "vector<...>::emplace(pos,arguments): vector too long");
1409 }
1410
1411 const size_type newSize = this->size() + 1;
1412 if (newSize > this->d_capacity) {
1414 newSize, this->d_capacity, maxSize);
1415 vector temp(this->get_allocator());
1416 temp.privateReserveEmpty(newCapacity);
1417
1418 ArrayPrimitives::destructiveMoveAndEmplace(
1419 temp.d_dataBegin_p,
1420 &this->d_dataEnd_p,
1421 this->d_dataBegin_p,
1422 pos,
1423 this->d_dataEnd_p,
1424 this->allocatorRef());
1425
1426 temp.d_dataEnd_p += newSize;
1427 Vector_Util::swap(&this->d_dataBegin_p, &temp.d_dataBegin_p);
1428 }
1429 else {
1430 ArrayPrimitives::emplace(
1431 pos,
1432 this->end(),
1433 this->allocatorRef());
1434 ++this->d_dataEnd_p;
1435 }
1436
1437 return this->begin() + index;
1438 }
1439#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_C >= 0
1440
1441#if BSLSTL_VECTOR_VARIADIC_LIMIT_C >= 1
1442 template <class Args_01>
1443 iterator emplace(const_iterator position,
1444 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01)
1445 {
1446 BSLS_ASSERT_SAFE(this->begin() <= position);
1447 BSLS_ASSERT_SAFE(position <= this->end());
1448
1449 const size_type index = position - this->begin();
1450
1451 const iterator& pos = const_cast<const iterator&>(position);
1452
1453 const size_type maxSize = max_size();
1455 maxSize - this->size())) {
1457 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
1458 "vector<...>::emplace(pos,arguments): vector too long");
1459 }
1460
1461 const size_type newSize = this->size() + 1;
1462 if (newSize > this->d_capacity) {
1464 newSize, this->d_capacity, maxSize);
1465 vector temp(this->get_allocator());
1466 temp.privateReserveEmpty(newCapacity);
1467
1468 ArrayPrimitives::destructiveMoveAndEmplace(
1469 temp.d_dataBegin_p,
1470 &this->d_dataEnd_p,
1471 this->d_dataBegin_p,
1472 pos,
1473 this->d_dataEnd_p,
1474 this->allocatorRef(),
1475 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01));
1476
1477 temp.d_dataEnd_p += newSize;
1478 Vector_Util::swap(&this->d_dataBegin_p, &temp.d_dataBegin_p);
1479 }
1480 else {
1481 ArrayPrimitives::emplace(
1482 pos,
1483 this->end(),
1484 this->allocatorRef(),
1485 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01));
1486 ++this->d_dataEnd_p;
1487 }
1488
1489 return this->begin() + index;
1490 }
1491#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_C >= 1
1492
1493#if BSLSTL_VECTOR_VARIADIC_LIMIT_C >= 2
1494 template <class Args_01,
1495 class Args_02>
1496 iterator emplace(const_iterator position,
1497 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
1498 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02)
1499 {
1500 BSLS_ASSERT_SAFE(this->begin() <= position);
1501 BSLS_ASSERT_SAFE(position <= this->end());
1502
1503 const size_type index = position - this->begin();
1504
1505 const iterator& pos = const_cast<const iterator&>(position);
1506
1507 const size_type maxSize = max_size();
1509 maxSize - this->size())) {
1511 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
1512 "vector<...>::emplace(pos,arguments): vector too long");
1513 }
1514
1515 const size_type newSize = this->size() + 1;
1516 if (newSize > this->d_capacity) {
1518 newSize, this->d_capacity, maxSize);
1519 vector temp(this->get_allocator());
1520 temp.privateReserveEmpty(newCapacity);
1521
1522 ArrayPrimitives::destructiveMoveAndEmplace(
1523 temp.d_dataBegin_p,
1524 &this->d_dataEnd_p,
1525 this->d_dataBegin_p,
1526 pos,
1527 this->d_dataEnd_p,
1528 this->allocatorRef(),
1529 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
1530 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02));
1531
1532 temp.d_dataEnd_p += newSize;
1533 Vector_Util::swap(&this->d_dataBegin_p, &temp.d_dataBegin_p);
1534 }
1535 else {
1536 ArrayPrimitives::emplace(
1537 pos,
1538 this->end(),
1539 this->allocatorRef(),
1540 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
1541 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02));
1542 ++this->d_dataEnd_p;
1543 }
1544
1545 return this->begin() + index;
1546 }
1547#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_C >= 2
1548
1549#if BSLSTL_VECTOR_VARIADIC_LIMIT_C >= 3
1550 template <class Args_01,
1551 class Args_02,
1552 class Args_03>
1553 iterator emplace(const_iterator position,
1554 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
1555 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
1556 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03)
1557 {
1558 BSLS_ASSERT_SAFE(this->begin() <= position);
1559 BSLS_ASSERT_SAFE(position <= this->end());
1560
1561 const size_type index = position - this->begin();
1562
1563 const iterator& pos = const_cast<const iterator&>(position);
1564
1565 const size_type maxSize = max_size();
1567 maxSize - this->size())) {
1569 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
1570 "vector<...>::emplace(pos,arguments): vector too long");
1571 }
1572
1573 const size_type newSize = this->size() + 1;
1574 if (newSize > this->d_capacity) {
1576 newSize, this->d_capacity, maxSize);
1577 vector temp(this->get_allocator());
1578 temp.privateReserveEmpty(newCapacity);
1579
1580 ArrayPrimitives::destructiveMoveAndEmplace(
1581 temp.d_dataBegin_p,
1582 &this->d_dataEnd_p,
1583 this->d_dataBegin_p,
1584 pos,
1585 this->d_dataEnd_p,
1586 this->allocatorRef(),
1587 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
1588 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
1589 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03));
1590
1591 temp.d_dataEnd_p += newSize;
1592 Vector_Util::swap(&this->d_dataBegin_p, &temp.d_dataBegin_p);
1593 }
1594 else {
1595 ArrayPrimitives::emplace(
1596 pos,
1597 this->end(),
1598 this->allocatorRef(),
1599 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
1600 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
1601 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03));
1602 ++this->d_dataEnd_p;
1603 }
1604
1605 return this->begin() + index;
1606 }
1607#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_C >= 3
1608
1609#if BSLSTL_VECTOR_VARIADIC_LIMIT_C >= 4
1610 template <class Args_01,
1611 class Args_02,
1612 class Args_03,
1613 class Args_04>
1614 iterator emplace(const_iterator position,
1615 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
1616 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
1617 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
1618 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04)
1619 {
1620 BSLS_ASSERT_SAFE(this->begin() <= position);
1621 BSLS_ASSERT_SAFE(position <= this->end());
1622
1623 const size_type index = position - this->begin();
1624
1625 const iterator& pos = const_cast<const iterator&>(position);
1626
1627 const size_type maxSize = max_size();
1629 maxSize - this->size())) {
1631 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
1632 "vector<...>::emplace(pos,arguments): vector too long");
1633 }
1634
1635 const size_type newSize = this->size() + 1;
1636 if (newSize > this->d_capacity) {
1638 newSize, this->d_capacity, maxSize);
1639 vector temp(this->get_allocator());
1640 temp.privateReserveEmpty(newCapacity);
1641
1642 ArrayPrimitives::destructiveMoveAndEmplace(
1643 temp.d_dataBegin_p,
1644 &this->d_dataEnd_p,
1645 this->d_dataBegin_p,
1646 pos,
1647 this->d_dataEnd_p,
1648 this->allocatorRef(),
1649 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
1650 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
1651 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
1652 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04));
1653
1654 temp.d_dataEnd_p += newSize;
1655 Vector_Util::swap(&this->d_dataBegin_p, &temp.d_dataBegin_p);
1656 }
1657 else {
1658 ArrayPrimitives::emplace(
1659 pos,
1660 this->end(),
1661 this->allocatorRef(),
1662 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
1663 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
1664 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
1665 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04));
1666 ++this->d_dataEnd_p;
1667 }
1668
1669 return this->begin() + index;
1670 }
1671#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_C >= 4
1672
1673#if BSLSTL_VECTOR_VARIADIC_LIMIT_C >= 5
1674 template <class Args_01,
1675 class Args_02,
1676 class Args_03,
1677 class Args_04,
1678 class Args_05>
1679 iterator emplace(const_iterator position,
1680 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
1681 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
1682 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
1683 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
1684 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05)
1685 {
1686 BSLS_ASSERT_SAFE(this->begin() <= position);
1687 BSLS_ASSERT_SAFE(position <= this->end());
1688
1689 const size_type index = position - this->begin();
1690
1691 const iterator& pos = const_cast<const iterator&>(position);
1692
1693 const size_type maxSize = max_size();
1695 maxSize - this->size())) {
1697 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
1698 "vector<...>::emplace(pos,arguments): vector too long");
1699 }
1700
1701 const size_type newSize = this->size() + 1;
1702 if (newSize > this->d_capacity) {
1704 newSize, this->d_capacity, maxSize);
1705 vector temp(this->get_allocator());
1706 temp.privateReserveEmpty(newCapacity);
1707
1708 ArrayPrimitives::destructiveMoveAndEmplace(
1709 temp.d_dataBegin_p,
1710 &this->d_dataEnd_p,
1711 this->d_dataBegin_p,
1712 pos,
1713 this->d_dataEnd_p,
1714 this->allocatorRef(),
1715 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
1716 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
1717 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
1718 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
1719 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05));
1720
1721 temp.d_dataEnd_p += newSize;
1722 Vector_Util::swap(&this->d_dataBegin_p, &temp.d_dataBegin_p);
1723 }
1724 else {
1725 ArrayPrimitives::emplace(
1726 pos,
1727 this->end(),
1728 this->allocatorRef(),
1729 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
1730 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
1731 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
1732 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
1733 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05));
1734 ++this->d_dataEnd_p;
1735 }
1736
1737 return this->begin() + index;
1738 }
1739#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_C >= 5
1740
1741#if BSLSTL_VECTOR_VARIADIC_LIMIT_C >= 6
1742 template <class Args_01,
1743 class Args_02,
1744 class Args_03,
1745 class Args_04,
1746 class Args_05,
1747 class Args_06>
1748 iterator emplace(const_iterator position,
1749 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
1750 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
1751 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
1752 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
1753 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
1754 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06)
1755 {
1756 BSLS_ASSERT_SAFE(this->begin() <= position);
1757 BSLS_ASSERT_SAFE(position <= this->end());
1758
1759 const size_type index = position - this->begin();
1760
1761 const iterator& pos = const_cast<const iterator&>(position);
1762
1763 const size_type maxSize = max_size();
1765 maxSize - this->size())) {
1767 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
1768 "vector<...>::emplace(pos,arguments): vector too long");
1769 }
1770
1771 const size_type newSize = this->size() + 1;
1772 if (newSize > this->d_capacity) {
1774 newSize, this->d_capacity, maxSize);
1775 vector temp(this->get_allocator());
1776 temp.privateReserveEmpty(newCapacity);
1777
1778 ArrayPrimitives::destructiveMoveAndEmplace(
1779 temp.d_dataBegin_p,
1780 &this->d_dataEnd_p,
1781 this->d_dataBegin_p,
1782 pos,
1783 this->d_dataEnd_p,
1784 this->allocatorRef(),
1785 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
1786 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
1787 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
1788 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
1789 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05),
1790 BSLS_COMPILERFEATURES_FORWARD(Args_06, arguments_06));
1791
1792 temp.d_dataEnd_p += newSize;
1793 Vector_Util::swap(&this->d_dataBegin_p, &temp.d_dataBegin_p);
1794 }
1795 else {
1796 ArrayPrimitives::emplace(
1797 pos,
1798 this->end(),
1799 this->allocatorRef(),
1800 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
1801 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
1802 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
1803 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
1804 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05),
1805 BSLS_COMPILERFEATURES_FORWARD(Args_06, arguments_06));
1806 ++this->d_dataEnd_p;
1807 }
1808
1809 return this->begin() + index;
1810 }
1811#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_C >= 6
1812
1813#if BSLSTL_VECTOR_VARIADIC_LIMIT_C >= 7
1814 template <class Args_01,
1815 class Args_02,
1816 class Args_03,
1817 class Args_04,
1818 class Args_05,
1819 class Args_06,
1820 class Args_07>
1821 iterator emplace(const_iterator position,
1822 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
1823 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
1824 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
1825 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
1826 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
1827 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06,
1828 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) arguments_07)
1829 {
1830 BSLS_ASSERT_SAFE(this->begin() <= position);
1831 BSLS_ASSERT_SAFE(position <= this->end());
1832
1833 const size_type index = position - this->begin();
1834
1835 const iterator& pos = const_cast<const iterator&>(position);
1836
1837 const size_type maxSize = max_size();
1839 maxSize - this->size())) {
1841 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
1842 "vector<...>::emplace(pos,arguments): vector too long");
1843 }
1844
1845 const size_type newSize = this->size() + 1;
1846 if (newSize > this->d_capacity) {
1848 newSize, this->d_capacity, maxSize);
1849 vector temp(this->get_allocator());
1850 temp.privateReserveEmpty(newCapacity);
1851
1852 ArrayPrimitives::destructiveMoveAndEmplace(
1853 temp.d_dataBegin_p,
1854 &this->d_dataEnd_p,
1855 this->d_dataBegin_p,
1856 pos,
1857 this->d_dataEnd_p,
1858 this->allocatorRef(),
1859 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
1860 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
1861 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
1862 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
1863 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05),
1864 BSLS_COMPILERFEATURES_FORWARD(Args_06, arguments_06),
1865 BSLS_COMPILERFEATURES_FORWARD(Args_07, arguments_07));
1866
1867 temp.d_dataEnd_p += newSize;
1868 Vector_Util::swap(&this->d_dataBegin_p, &temp.d_dataBegin_p);
1869 }
1870 else {
1871 ArrayPrimitives::emplace(
1872 pos,
1873 this->end(),
1874 this->allocatorRef(),
1875 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
1876 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
1877 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
1878 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
1879 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05),
1880 BSLS_COMPILERFEATURES_FORWARD(Args_06, arguments_06),
1881 BSLS_COMPILERFEATURES_FORWARD(Args_07, arguments_07));
1882 ++this->d_dataEnd_p;
1883 }
1884
1885 return this->begin() + index;
1886 }
1887#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_C >= 7
1888
1889#if BSLSTL_VECTOR_VARIADIC_LIMIT_C >= 8
1890 template <class Args_01,
1891 class Args_02,
1892 class Args_03,
1893 class Args_04,
1894 class Args_05,
1895 class Args_06,
1896 class Args_07,
1897 class Args_08>
1898 iterator emplace(const_iterator position,
1899 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
1900 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
1901 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
1902 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
1903 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
1904 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06,
1905 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) arguments_07,
1906 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) arguments_08)
1907 {
1908 BSLS_ASSERT_SAFE(this->begin() <= position);
1909 BSLS_ASSERT_SAFE(position <= this->end());
1910
1911 const size_type index = position - this->begin();
1912
1913 const iterator& pos = const_cast<const iterator&>(position);
1914
1915 const size_type maxSize = max_size();
1917 maxSize - this->size())) {
1919 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
1920 "vector<...>::emplace(pos,arguments): vector too long");
1921 }
1922
1923 const size_type newSize = this->size() + 1;
1924 if (newSize > this->d_capacity) {
1926 newSize, this->d_capacity, maxSize);
1927 vector temp(this->get_allocator());
1928 temp.privateReserveEmpty(newCapacity);
1929
1930 ArrayPrimitives::destructiveMoveAndEmplace(
1931 temp.d_dataBegin_p,
1932 &this->d_dataEnd_p,
1933 this->d_dataBegin_p,
1934 pos,
1935 this->d_dataEnd_p,
1936 this->allocatorRef(),
1937 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
1938 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
1939 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
1940 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
1941 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05),
1942 BSLS_COMPILERFEATURES_FORWARD(Args_06, arguments_06),
1943 BSLS_COMPILERFEATURES_FORWARD(Args_07, arguments_07),
1944 BSLS_COMPILERFEATURES_FORWARD(Args_08, arguments_08));
1945
1946 temp.d_dataEnd_p += newSize;
1947 Vector_Util::swap(&this->d_dataBegin_p, &temp.d_dataBegin_p);
1948 }
1949 else {
1950 ArrayPrimitives::emplace(
1951 pos,
1952 this->end(),
1953 this->allocatorRef(),
1954 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
1955 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
1956 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
1957 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
1958 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05),
1959 BSLS_COMPILERFEATURES_FORWARD(Args_06, arguments_06),
1960 BSLS_COMPILERFEATURES_FORWARD(Args_07, arguments_07),
1961 BSLS_COMPILERFEATURES_FORWARD(Args_08, arguments_08));
1962 ++this->d_dataEnd_p;
1963 }
1964
1965 return this->begin() + index;
1966 }
1967#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_C >= 8
1968
1969#if BSLSTL_VECTOR_VARIADIC_LIMIT_C >= 9
1970 template <class Args_01,
1971 class Args_02,
1972 class Args_03,
1973 class Args_04,
1974 class Args_05,
1975 class Args_06,
1976 class Args_07,
1977 class Args_08,
1978 class Args_09>
1979 iterator emplace(const_iterator position,
1980 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
1981 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
1982 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
1983 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
1984 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
1985 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06,
1986 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) arguments_07,
1987 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) arguments_08,
1988 BSLS_COMPILERFEATURES_FORWARD_REF(Args_09) arguments_09)
1989 {
1990 BSLS_ASSERT_SAFE(this->begin() <= position);
1991 BSLS_ASSERT_SAFE(position <= this->end());
1992
1993 const size_type index = position - this->begin();
1994
1995 const iterator& pos = const_cast<const iterator&>(position);
1996
1997 const size_type maxSize = max_size();
1999 maxSize - this->size())) {
2001 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
2002 "vector<...>::emplace(pos,arguments): vector too long");
2003 }
2004
2005 const size_type newSize = this->size() + 1;
2006 if (newSize > this->d_capacity) {
2008 newSize, this->d_capacity, maxSize);
2009 vector temp(this->get_allocator());
2010 temp.privateReserveEmpty(newCapacity);
2011
2012 ArrayPrimitives::destructiveMoveAndEmplace(
2013 temp.d_dataBegin_p,
2014 &this->d_dataEnd_p,
2015 this->d_dataBegin_p,
2016 pos,
2017 this->d_dataEnd_p,
2018 this->allocatorRef(),
2019 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
2020 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
2021 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
2022 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
2023 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05),
2024 BSLS_COMPILERFEATURES_FORWARD(Args_06, arguments_06),
2025 BSLS_COMPILERFEATURES_FORWARD(Args_07, arguments_07),
2026 BSLS_COMPILERFEATURES_FORWARD(Args_08, arguments_08),
2027 BSLS_COMPILERFEATURES_FORWARD(Args_09, arguments_09));
2028
2029 temp.d_dataEnd_p += newSize;
2030 Vector_Util::swap(&this->d_dataBegin_p, &temp.d_dataBegin_p);
2031 }
2032 else {
2033 ArrayPrimitives::emplace(
2034 pos,
2035 this->end(),
2036 this->allocatorRef(),
2037 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
2038 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
2039 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
2040 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
2041 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05),
2042 BSLS_COMPILERFEATURES_FORWARD(Args_06, arguments_06),
2043 BSLS_COMPILERFEATURES_FORWARD(Args_07, arguments_07),
2044 BSLS_COMPILERFEATURES_FORWARD(Args_08, arguments_08),
2045 BSLS_COMPILERFEATURES_FORWARD(Args_09, arguments_09));
2046 ++this->d_dataEnd_p;
2047 }
2048
2049 return this->begin() + index;
2050 }
2051#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_C >= 9
2052
2053#if BSLSTL_VECTOR_VARIADIC_LIMIT_C >= 10
2054 template <class Args_01,
2055 class Args_02,
2056 class Args_03,
2057 class Args_04,
2058 class Args_05,
2059 class Args_06,
2060 class Args_07,
2061 class Args_08,
2062 class Args_09,
2063 class Args_10>
2064 iterator emplace(const_iterator position,
2065 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
2066 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
2067 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
2068 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
2069 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
2070 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06,
2071 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) arguments_07,
2072 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) arguments_08,
2073 BSLS_COMPILERFEATURES_FORWARD_REF(Args_09) arguments_09,
2074 BSLS_COMPILERFEATURES_FORWARD_REF(Args_10) arguments_10)
2075 {
2076 BSLS_ASSERT_SAFE(this->begin() <= position);
2077 BSLS_ASSERT_SAFE(position <= this->end());
2078
2079 const size_type index = position - this->begin();
2080
2081 const iterator& pos = const_cast<const iterator&>(position);
2082
2083 const size_type maxSize = max_size();
2085 maxSize - this->size())) {
2087 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
2088 "vector<...>::emplace(pos,arguments): vector too long");
2089 }
2090
2091 const size_type newSize = this->size() + 1;
2092 if (newSize > this->d_capacity) {
2094 newSize, this->d_capacity, maxSize);
2095 vector temp(this->get_allocator());
2096 temp.privateReserveEmpty(newCapacity);
2097
2098 ArrayPrimitives::destructiveMoveAndEmplace(
2099 temp.d_dataBegin_p,
2100 &this->d_dataEnd_p,
2101 this->d_dataBegin_p,
2102 pos,
2103 this->d_dataEnd_p,
2104 this->allocatorRef(),
2105 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
2106 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
2107 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
2108 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
2109 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05),
2110 BSLS_COMPILERFEATURES_FORWARD(Args_06, arguments_06),
2111 BSLS_COMPILERFEATURES_FORWARD(Args_07, arguments_07),
2112 BSLS_COMPILERFEATURES_FORWARD(Args_08, arguments_08),
2113 BSLS_COMPILERFEATURES_FORWARD(Args_09, arguments_09),
2114 BSLS_COMPILERFEATURES_FORWARD(Args_10, arguments_10));
2115
2116 temp.d_dataEnd_p += newSize;
2117 Vector_Util::swap(&this->d_dataBegin_p, &temp.d_dataBegin_p);
2118 }
2119 else {
2120 ArrayPrimitives::emplace(
2121 pos,
2122 this->end(),
2123 this->allocatorRef(),
2124 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
2125 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
2126 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
2127 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
2128 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05),
2129 BSLS_COMPILERFEATURES_FORWARD(Args_06, arguments_06),
2130 BSLS_COMPILERFEATURES_FORWARD(Args_07, arguments_07),
2131 BSLS_COMPILERFEATURES_FORWARD(Args_08, arguments_08),
2132 BSLS_COMPILERFEATURES_FORWARD(Args_09, arguments_09),
2133 BSLS_COMPILERFEATURES_FORWARD(Args_10, arguments_10));
2134 ++this->d_dataEnd_p;
2135 }
2136
2137 return this->begin() + index;
2138 }
2139#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_C >= 10
2140
2141#else
2142// The generated code below is a workaround for the absence of perfect
2143// forwarding in some compilers.
2144 template <class... Args>
2145 iterator emplace(const_iterator position,
2146 BSLS_COMPILERFEATURES_FORWARD_REF(Args)... arguments)
2147 {
2148 BSLS_ASSERT_SAFE(this->begin() <= position);
2149 BSLS_ASSERT_SAFE(position <= this->end());
2150
2151 const size_type index = position - this->begin();
2152
2153 const iterator& pos = const_cast<const iterator&>(position);
2154
2155 const size_type maxSize = max_size();
2157 maxSize - this->size())) {
2159 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
2160 "vector<...>::emplace(pos,arguments): vector too long");
2161 }
2162
2163 const size_type newSize = this->size() + 1;
2164 if (newSize > this->d_capacity) {
2166 newSize, this->d_capacity, maxSize);
2167 vector temp(this->get_allocator());
2168 temp.privateReserveEmpty(newCapacity);
2169
2170 ArrayPrimitives::destructiveMoveAndEmplace(
2171 temp.d_dataBegin_p,
2172 &this->d_dataEnd_p,
2173 this->d_dataBegin_p,
2174 pos,
2175 this->d_dataEnd_p,
2176 this->allocatorRef(),
2177 BSLS_COMPILERFEATURES_FORWARD(Args, arguments)...);
2178
2179 temp.d_dataEnd_p += newSize;
2180 Vector_Util::swap(&this->d_dataBegin_p, &temp.d_dataBegin_p);
2181 }
2182 else {
2183 ArrayPrimitives::emplace(
2184 pos,
2185 this->end(),
2186 this->allocatorRef(),
2187 BSLS_COMPILERFEATURES_FORWARD(Args, arguments)...);
2188 ++this->d_dataEnd_p;
2189 }
2190
2191 return this->begin() + index;
2192 }
2193// }}} END GENERATED CODE
2194#endif
2195
2196 /// Insert at the specified `position` in this vector a copy of the
2197 /// specified `value`, and return an iterator referring to the newly
2198 /// inserted element. If an exception is thrown (other than by the copy
2199 /// constructor, move constructor, assignment operator, or move
2200 /// assignment operator of `VALUE_TYPE`), `*this` is unaffected. Throw
2201 /// `std::length_error` if `size() == max_size()`.
2202 ///
2203 /// \pre The behavior is undefined unless `position` is an iterator in the range
2204 /// `[begin() .. end()]` (both endpoints included). This method
2205 /// requires that the (template parameter) type `VALUE_TYPE` be
2206 /// `copy-insertable` into this vector (see {Requirements on
2207 /// `VALUE_TYPE`}).
2208 iterator insert(const_iterator position, const VALUE_TYPE& value);
2209
2210 /// Insert at the specified `position` in this vector the specified
2211 /// move-insertable `value`, and return an iterator referring to the
2212 /// newly inserted element. `value` is left in a valid but unspecified
2213 /// state. If an exception is thrown (other than by the copy
2214 /// constructor, move constructor, assignment operator, or move
2215 /// assignment operator of `VALUE_TYPE`), `this` is unaffected. Throw
2216 /// `std::length_error` if `size() == max_size()`.
2217 ///
2218 /// \pre The behavior is undefined unless `position` is an iterator in the range
2219 /// `[begin() .. end()]` (both endpoints included). This method
2220 /// requires that the (template parameter) type `VALUE_TYPE` be
2221 /// `move-insertable` into this vector (see {Requirements on
2222 /// `VALUE_TYPE`}).
2223 iterator insert(const_iterator position,
2224 BloombergLP::bslmf::MovableRef<VALUE_TYPE> value);
2225
2226 /// Insert at the specified `position` in this vector the specified
2227 /// `numElements` copies of the specified `value`, and return an
2228 /// iterator referring to the first newly inserted element. If an
2229 /// exception is thrown (other than by the copy constructor, move
2230 /// constructor, assignment operator, or move assignment operator of
2231 /// `VALUE_TYPE`), `*this` is unaffected. Throw `std::length_error` if
2232 /// `size() + numElements > max_size()`.
2233 ///
2234 /// \pre The behavior is undefined unless `position` is an iterator in the range `[begin() .. end()]`
2235 /// (both endpoints included). This method requires that the (template
2236 /// parameter) type `VALUE_TYPE` be `copy-insertable` into this vector
2237 /// (see {Requirements on `VALUE_TYPE`}).
2238 iterator insert(const_iterator position,
2239 size_type numElements,
2240 const VALUE_TYPE& value);
2241
2242 /// Insert at the specified `position` in this vector the values in the
2243 /// range starting at the specified `first` element, and ending
2244 /// immediately before the specified `last` element. Return an iterator
2245 /// referring to the first newly inserted element. If an exception is
2246 /// thrown (other than by the copy constructor, move constructor,
2247 /// assignment operator, or move assignment operator of `value_type`),
2248 /// `*this` is unaffected. Throw `std::length_error` if
2249 /// `size() + distance(first, last) > max_size()`. The (template
2250 /// parameter) type `INPUT_ITER` shall meet the requirements of an input
2251 /// iterator defined in the C++11 standard [24.2.3] providing access to
2252 /// values of a type convertible to `value_type`, and `value_type` must
2253 /// be `emplace-constructible` from `*i` into this vector, where `i` is
2254 /// a dereferenceable iterator in the range `[first .. last)` (see {Requirements on `VALUE_TYPE`}).
2255 ///
2256 /// \pre The behavior is undefined unless
2257 /// `position` is an iterator in the range `[begin() .. end()]` (both
2258 /// endpoints included), and `first` and `last` refer to a range of
2259 /// valid values where `first` is at a position at or before `last`.
2260 ///
2261 /// NOTE: This function has been implemented inline due to an issue with
2262 /// the Sun compiler.
2263 template <class INPUT_ITER>
2264 iterator insert(const_iterator position, INPUT_ITER first, INPUT_ITER last)
2265 {
2266 BSLS_ASSERT_SAFE(this->begin() <= position);
2267 BSLS_ASSERT_SAFE(position <= this->end());
2268 BSLS_ASSERT_SAFE(!Vector_RangeCheck::isInvalidRange(first, last));
2269
2270 // If 'first' and 'last' are integral, then they are not iterators and
2271 // we should call 'insert(position, first, last)', where 'first' is
2272 // actually a misnamed count, and 'last' is a misnamed value. We can
2273 // assume that any fundamental type passed to this function is integral
2274 // or else compilation errors will result. The extra argument,
2275 // 'bslmf::Nil()', is to avoid an overloading ambiguity: In case
2276 // 'first' is an integral type, it would be convertible both to
2277 // 'bslmf::MatchArithmeticType' and 'bslmf::MatchAnyType'; but the
2278 // 'bslmf::Nil()' will be an exact match to 'bslmf::Nil', so the
2279 // overload with 'bslmf::MatchArithmeticType' will be preferred.
2280
2281 const size_type index = position - this->begin();
2282 privateInsertDispatch(
2283 position, first, last, first, BloombergLP::bslmf::Nil());
2284 return this->begin() + index;
2285 }
2286
2287#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
2288 /// Insert at the specified `position` in this vector each `VALUE_TYPE`
2289 /// object in the specified `values` initializer list, and return an
2290 /// iterator referring to the first newly inserted element. If an
2291 /// exception is thrown (other than by the copy constructor, move
2292 /// constructor, assignment operator, and move assignment operator of
2293 /// `VALUE_TYPE`), `*this` is unaffected. Throw `std::length_error` if
2294 /// `size() + values.size() > max_size()`.
2295 ///
2296 /// \pre The behavior is undefined unless `position` is an iterator in the range `[begin() .. end()]`
2297 /// (both endpoints included). This method requires that the (template
2298 /// parameter) type `VALUE_TYPE` be `copy-insertable` into this vector
2299 /// (see {Requirements on `VALUE_TYPE`}).
2300 iterator insert(const_iterator position,
2301 std::initializer_list<VALUE_TYPE> values);
2302#endif
2303
2304 /// Insert at the specified `position` in this object the elements of the specified `range`.
2305 ///
2306 /// \note Note that `range` must meet the requirements of an
2307 /// input range and the values from `range` must have a type matching or
2308 /// convertible to (template parameter) `VALUE_TYPE`.
2309 template <class t_RANGE>
2311 iterator insert_range(const_iterator position,
2312 BSLS_COMPILERFEATURES_FORWARD_REF(t_RANGE) range);
2313
2314 /// Remove from this vector the element at the specified `position`, and
2315 /// return an iterator providing modifiable access to the element
2316 /// immediately following the removed element, or the position returned
2317 /// by the method `end` if the removed element was the last in the sequence.
2318 ///
2319 /// \pre The behavior is undefined unless `position` is an
2320 /// iterator in the range `[cbegin() .. cend())`.
2321 iterator erase(const_iterator position);
2322
2323 /// Remove from this vector the sequence of elements starting at the
2324 /// specified `first` position and ending before the specified `last`
2325 /// position, and return an iterator providing modifiable access to the
2326 /// element immediately following the last removed element, or the
2327 /// position returned by the method `end` if the removed elements were last in the sequence.
2328 ///
2329 /// \pre The behavior is undefined unless `first` is
2330 /// an iterator in the range `[cbegin() .. cend()]` (both endpoints
2331 /// included) and `last` is an iterator in the range
2332 /// `[first .. cend()]` (both endpoints included).
2334
2335 /// Exchange the value of this object with that of the specified `other`
2336 /// object; also exchange the allocator of this object with that of `other`
2337 /// if the (template parameter) type `ALLOCATOR` has the
2338 /// @ref propagate_on_container_swap trait, and do not modify either allocator
2339 /// otherwise. This method provides the no-throw exception-safety
2340 /// guarantee. This operation has `O[1]` complexity if either this object
2341 /// was created with the same allocator as `other` or `ALLOCATOR` has the
2342 /// @ref propagate_on_container_swap trait; otherwise, it has `O[n + m]`
2343 /// complexity, where `n` and `m` are the number of elements in this object and `other`, respectively.
2344 ///
2345 /// \note Note that this method`s support for
2346 /// swapping objects created with different allocators when `ALLOCATOR`
2347 /// does not have the @ref propagate_on_container_swap trait is a departure
2348 /// from the C++ Standard.
2349 void swap(vector& other) BSLS_KEYWORD_NOEXCEPT_SPECIFICATION(
2350 AllocatorTraits::propagate_on_container_swap::value ||
2351 AllocatorTraits::is_always_equal::value);
2352
2353 /// Remove all elements from this vector making its size 0.
2354 ///
2355 /// \note Note that although this vector is empty after this method returns, it preserves
2356 /// the same capacity it had before the method was called.
2357 void clear() BSLS_KEYWORD_NOEXCEPT;
2358
2359 // ACCESSORS
2360
2361 /// Return (a copy of) the allocator used for memory allocation by this
2362 /// vector.
2363 allocator_type get_allocator() const BSLS_KEYWORD_NOEXCEPT;
2364
2365 /// Return a theoretical upper bound on the largest number of elements that this vector could possibly hold.
2366 ///
2367 /// \note Note that there is no guarantee that
2368 /// the vector can successfully grow to the returned size, or even close to
2369 /// that size without running out of resources. Also note that requests to
2370 /// create a vector longer than this number of elements are guaranteed to
2371 /// raise a `std::length_error` exception.
2372 size_type max_size() const BSLS_KEYWORD_NOEXCEPT;
2373};
2374
2375// FREE OPERATORS
2376
2377 // *** relational operators ***
2378
2379/// Return `true` if the specified `lhs` and `rhs` objects have the same value,
2380/// and `false` otherwise. Two `vector` objects `lhs` and `rhs` have the same
2381/// value if they have the same number of elements, and each element in the
2382/// ordered sequence of elements of `lhs` has the same value as the
2383/// corresponding element in the ordered sequence of elements of `rhs`. This
2384/// method requires that the (template parameter) type `VALUE_TYPE` be
2385/// `equality-comparable` (see {Requirements on `VALUE_TYPE`}).
2386template <class VALUE_TYPE, class ALLOCATOR>
2387bool operator==(const vector<VALUE_TYPE, ALLOCATOR>& lhs,
2388 const vector<VALUE_TYPE, ALLOCATOR>& rhs);
2389
2390#ifndef BSLS_COMPILERFEATURES_SUPPORT_THREE_WAY_COMPARISON
2391/// Return `true` if the specified `lhs` and `rhs` objects do not have the same
2392/// value, and `false` otherwise. Two `vector` objects `lhs` and `rhs` do not
2393/// have the same value if they do not have the same number of elements, or
2394/// some element in the ordered sequence of elements of `lhs` does not have the
2395/// same value as the corresponding element in the ordered sequence of elements
2396/// of `rhs`. This method requires that the (template parameter) type
2397/// `VALUE_TYPE` be `equality-comparable` (see {Requirements on `VALUE_TYPE`}).
2398template <class VALUE_TYPE, class ALLOCATOR>
2399bool operator!=(const vector<VALUE_TYPE, ALLOCATOR>& lhs,
2400 const vector<VALUE_TYPE, ALLOCATOR>& rhs);
2401#endif // BSLS_COMPILERFEATURES_SUPPORT_THREE_WAY_COMPARISON
2402
2403#ifdef BSLALG_SYNTHTHREEWAYUTIL_AVAILABLE
2404
2405/// Perform a lexicographic three-way comparison of the specified `lhs` and the
2406/// specified `rhs` vectors by using the comparison operators of `VALUE_TYPE`
2407/// on each element; return the result of that comparison.
2408template <class VALUE_TYPE, class ALLOCATOR>
2409BloombergLP::bslalg::SynthThreeWayUtil::Result<VALUE_TYPE> operator<=>(
2410 const vector<VALUE_TYPE, ALLOCATOR>& lhs,
2411 const vector<VALUE_TYPE, ALLOCATOR>& rhs);
2412
2413#else
2414
2415/// Return `true` if the value of the specified `lhs` vector is
2416/// lexicographically less than that of the specified `rhs` vector, and
2417/// `false` otherwise. Given iterators `i` and `j` over the respective
2418/// sequences `[lhs.begin() .. lhs.end())` and `[rhs.begin() .. rhs.end())`,
2419/// the value of vector `lhs` is lexicographically less than that of vector
2420/// `rhs` if `true == *i < *j` for the first pair of corresponding iterator
2421/// positions where `*i < *j` and `*j < *i` are not both `false`. If no
2422/// such corresponding iterator position exists, the value of `lhs` is
2423/// lexicographically less than that of `rhs` if `lhs.size() < rhs.size()`.
2424/// This method requires that `operator<`, inducing a total order, be
2425/// defined for `value_type`.
2426template <class VALUE_TYPE, class ALLOCATOR>
2427bool operator<(const vector<VALUE_TYPE, ALLOCATOR>& lhs,
2428 const vector<VALUE_TYPE, ALLOCATOR>& rhs);
2429
2430/// Return `true` if the value of the specified `lhs` vector is
2431/// lexicographically greater than that of the specified `rhs` vector, and
2432/// `false` otherwise. The value of vector `lhs` is lexicographically
2433/// greater than that of vector `rhs` if `rhs` is lexicographically less
2434/// than `lhs` (see `operator<`). This method requires that `operator<`, inducing a total order, be defined for `value_type`.
2435///
2436/// \note Note that this
2437/// operator returns `rhs < lhs`.
2438template <class VALUE_TYPE, class ALLOCATOR>
2439bool operator>(const vector<VALUE_TYPE, ALLOCATOR>& lhs,
2440 const vector<VALUE_TYPE, ALLOCATOR>& rhs);
2441
2442/// Return `true` if the value of the specified `lhs` vector is
2443/// lexicographically less than or equal to that of the specified `rhs`
2444/// vector, and `false` otherwise. The value of vector `lhs` is
2445/// lexicographically less than or equal to that of vector `rhs` if `rhs` is
2446/// not lexicographically less than `lhs` (see `operator<`). This method
2447/// requires that `operator<`, inducing a total order, be defined for `value_type`.
2448///
2449/// \note Note that this operator returns `!(rhs < lhs)`.
2450template <class VALUE_TYPE, class ALLOCATOR>
2451bool operator<=(const vector<VALUE_TYPE, ALLOCATOR>& lhs,
2452 const vector<VALUE_TYPE, ALLOCATOR>& rhs);
2453
2454/// Return `true` if the value of the specified `lhs` vector is
2455/// lexicographically greater than or equal to that of the specified `rhs`
2456/// vector, and `false` otherwise. The value of vector `lhs` is
2457/// lexicographically greater than or equal to that of vector `rhs` if `lhs`
2458/// is not lexicographically less than `rhs` (see `operator<`). This method
2459/// requires that `operator<`, inducing a total order, be defined for `value_type`.
2460///
2461/// \note Note that this operator returns `!(lhs < rhs)`.
2462template <class VALUE_TYPE, class ALLOCATOR>
2463bool operator>=(const vector<VALUE_TYPE, ALLOCATOR>& lhs,
2464 const vector<VALUE_TYPE, ALLOCATOR>& rhs);
2465
2466#endif // BSLALG_SYNTHTHREEWAYUTIL_AVAILABLE
2467
2468// FREE FUNCTIONS
2469
2470/// Erase all the elements in the specified vector `vec` that compare equal
2471/// to the specified `value`. Return the number of elements erased.
2472template <class VALUE_TYPE, class ALLOCATOR, class BDE_OTHER_TYPE>
2474erase(vector<VALUE_TYPE, ALLOCATOR>& vec, const BDE_OTHER_TYPE& value);
2475
2476/// Erase all the elements in the specified vector `vec` that satisfy the
2477/// specified predicate `predicate`. Return the number of elements erased.
2478template <class VALUE_TYPE, class ALLOCATOR, class PREDICATE>
2480erase_if(vector<VALUE_TYPE, ALLOCATOR>& vec, PREDICATE predicate);
2481
2482/// Exchange the value of the specified `a` object with that of the
2483/// specified `b` object; also exchange the allocator of `a` with that of
2484/// `b` if the (template parameter) type `ALLOCATOR` has the
2485/// @ref propagate_on_container_swap trait, and do not modify either allocator
2486/// otherwise. This function provides the no-throw exception-safety
2487/// guarantee. This operation has `O[1]` complexity if either `a` was
2488/// created with the same allocator as `b` or `ALLOCATOR` has the
2489/// @ref propagate_on_container_swap trait; otherwise, it has `O[n + m]`
2490/// complexity, where `n` and `m` are the number of elements in `a` and `b`, respectively.
2491///
2492/// \note Note that this function`s support for swapping objects
2493/// created with different allocators when `ALLOCATOR` does not have the
2494/// @ref propagate_on_container_swap trait is a departure from the C++
2495/// Standard.
2496template <class VALUE_TYPE, class ALLOCATOR>
2497void swap(vector<VALUE_TYPE, ALLOCATOR>& a,
2498 vector<VALUE_TYPE, ALLOCATOR>& b)
2500 a.swap(b)));
2501
2502
2503 // =====================================
2504 // class vector<VALUE_TYPE *, ALLOCATOR>
2505 // =====================================
2506
2507/// This partial specialization of `vector` for pointer types to a (template
2508/// parameter) `VALUE_TYPE` type is implemented in terms of
2509/// `vector<UintPtr>` to reduce the amount of code generated.
2510///
2511/// \note Note that this specialization rebinds the (template parameter) `ALLOCATOR` type to
2512/// an allocator of `UintPtr` so as to satisfy the invariant in the `vector` base class.
2513///
2514/// \note Note that the contract for all members is the same as the
2515/// primary template, so documentation is not repeated to avoid accidentally
2516/// introducing inconsistency over time.
2517template <class VALUE_TYPE, class ALLOCATOR>
2518class vector<VALUE_TYPE *, ALLOCATOR>
2519{
2520
2521 // PRIVATE TYPES
2522 typedef BloombergLP::bsls::Types::UintPtr UintPtr;
2523#if defined(BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES)
2524 typedef typename allocator_traits<ALLOCATOR>::
2525 template rebind_alloc<UintPtr> ImplAlloc;
2526#else
2527 typedef typename ALLOCATOR::template rebind<UintPtr>::other ImplAlloc;
2528#endif
2529 typedef vector<UintPtr, ImplAlloc> Impl;
2530 typedef BloombergLP::bslmf::MovableRefUtil MoveUtil;
2531
2532 // PRIVATE DATA
2533 Impl d_impl; // The 'UintPtr' vector used for the implementation.
2534
2535 public:
2536 // PUBLIC TYPES
2537 typedef VALUE_TYPE *value_type;
2538 typedef value_type& reference;
2539 typedef const value_type& const_reference;
2540 typedef VALUE_TYPE **iterator;
2541 typedef VALUE_TYPE *const *const_iterator;
2542 typedef std::size_t size_type;
2543 typedef std::ptrdiff_t difference_type;
2544 typedef ALLOCATOR allocator_type;
2545 typedef typename allocator_traits<ALLOCATOR>::pointer
2546 pointer;
2547 typedef typename allocator_traits<ALLOCATOR>::const_pointer
2548 const_pointer;
2549 typedef bsl::reverse_iterator<iterator> reverse_iterator;
2550 typedef bsl::reverse_iterator<const_iterator> const_reverse_iterator;
2551
2552 // *** construct/copy/destroy ***
2553
2554 // CREATORS
2555 vector() BSLS_KEYWORD_NOEXCEPT;
2556
2557 explicit vector(const ALLOCATOR& basicAllocator) BSLS_KEYWORD_NOEXCEPT;
2558
2559 explicit vector(size_type initialSize,
2560 const ALLOCATOR& basicAllocator = ALLOCATOR());
2561
2562 vector(size_type initialSize,
2563 VALUE_TYPE *value,
2564 const ALLOCATOR& basicAllocator = ALLOCATOR());
2565
2566 template <class INPUT_ITER>
2567 vector(INPUT_ITER first,
2568 INPUT_ITER last,
2569 const ALLOCATOR& basicAllocator = ALLOCATOR());
2570
2571 template <class t_RANGE>
2573 vector(from_range_t ,
2574 BSLS_COMPILERFEATURES_FORWARD_REF(t_RANGE) range,
2575 const ALLOCATOR& basicAllocator =
2576 ALLOCATOR());
2577
2578 vector(const vector& original);
2579
2580 vector(BloombergLP::bslmf::MovableRef<vector> original)
2581 BSLS_KEYWORD_NOEXCEPT; // IMPLICIT
2582
2583 vector(const vector& original,
2584 const typename type_identity<ALLOCATOR>::type& basicAllocator);
2585
2586 vector(BloombergLP::bslmf::MovableRef<vector> original,
2587 const typename type_identity<ALLOCATOR>::type& basicAllocator);
2588
2589
2590#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
2591 vector(std::initializer_list<VALUE_TYPE *> values,
2592 const ALLOCATOR& basicAllocator = ALLOCATOR());
2593#endif
2594
2595 ~vector();
2596
2597 // MANIPULATORS
2598 vector& operator=(const vector& rhs);
2599
2600 /// NOTE: This function has been implemented inline due to an issue with
2601 /// the Sun compiler.
2602 vector& operator=(
2603 BloombergLP::bslmf::MovableRef<vector<VALUE_TYPE *, ALLOCATOR> > rhs)
2605 d_impl = MoveUtil::move(MoveUtil::access(rhs).d_impl)))
2606 {
2607 d_impl = MoveUtil::move(MoveUtil::access(rhs).d_impl);
2608 return *this;
2609 }
2610
2611#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
2612 vector& operator=(std::initializer_list<VALUE_TYPE *> values);
2613
2614 void assign(std::initializer_list<VALUE_TYPE *> values);
2615
2616#endif
2617
2618 template <class INPUT_ITER>
2619 void assign(INPUT_ITER first, INPUT_ITER last);
2620 void assign(size_type numElements, VALUE_TYPE *value);
2621
2622 template <class t_RANGE>
2624 void assign_range(BSLS_COMPILERFEATURES_FORWARD_REF(t_RANGE) range);
2625
2626
2627 // *** iterators ***
2628
2631
2634
2635 // *** element access ***
2636
2637 reference operator[](size_type position);
2638 reference at(size_type position);
2639
2640 reference front();
2641 reference back();
2642
2643 VALUE_TYPE **data() BSLS_KEYWORD_NOEXCEPT;
2644
2645 // *** capacity ***
2646
2647 void resize(size_type newLength);
2648 void resize(size_type newLength, VALUE_TYPE *value);
2649
2650 void reserve(size_type newCapacity);
2651 void shrink_to_fit();
2652
2653 // *** modifiers ***
2654
2655 template <class t_RANGE>
2657 void append_range(BSLS_COMPILERFEATURES_FORWARD_REF(t_RANGE) range);
2658
2659 value_type &emplace_back();
2660
2661# if defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES)
2662 template <class ARG>
2663 value_type &emplace_back(ARG&& arg);
2664# else
2665 value_type &emplace_back(VALUE_TYPE *ptr);
2666# endif
2667
2668 void push_back(VALUE_TYPE *value);
2669
2670 void pop_back();
2671
2672 iterator emplace(const_iterator position);
2673
2674# if defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES)
2675 template <class ARG>
2676 iterator emplace(const_iterator position, ARG&& arg);
2677# else
2678 iterator emplace(const_iterator position, VALUE_TYPE *ptr);
2679# endif
2680
2681 iterator insert(const_iterator position, VALUE_TYPE *value);
2682 iterator insert(const_iterator position,
2683 size_type numElements,
2684 VALUE_TYPE *value);
2685
2686 template <class INPUT_ITER>
2687 iterator insert(const_iterator position,
2688 INPUT_ITER first,
2689 INPUT_ITER last)
2690 {
2691 // NOTE: This function has been implemented inline due to an issue with
2692 // the Sun compiler.
2693
2694 typedef typename vector_ForwardIteratorForPtrs<VALUE_TYPE,
2695 INPUT_ITER>::type Iter;
2696
2697 return (iterator)d_impl.insert(
2698 (const UintPtr *)position, Iter(first), Iter(last));
2699 }
2700
2701#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
2702 iterator insert(const_iterator position,
2703 std::initializer_list<VALUE_TYPE *> values);
2704#endif
2705
2706 template <class t_RANGE>
2708 iterator insert_range(const_iterator position,
2709 BSLS_COMPILERFEATURES_FORWARD_REF(t_RANGE) range);
2710
2711 iterator erase(const_iterator position);
2713
2714 void swap(vector<VALUE_TYPE *, ALLOCATOR>& other)
2716 d_impl.swap(other.d_impl)));
2717
2718 void clear() BSLS_KEYWORD_NOEXCEPT;
2719
2720 // ACCESSORS
2721 allocator_type get_allocator() const BSLS_KEYWORD_NOEXCEPT;
2722
2723 size_type max_size() const BSLS_KEYWORD_NOEXCEPT;
2724
2725 // *** iterators ***
2726
2731
2736
2737 // *** capacity ***
2738
2741 bool empty() const BSLS_KEYWORD_NOEXCEPT;
2742
2743 // *** element access ***
2744
2745 const_reference operator[](size_type position) const;
2746
2747 const_reference at(size_type position) const;
2748
2749 const_reference front() const;
2750 const_reference back() const;
2751
2752 VALUE_TYPE *const *data() const BSLS_KEYWORD_NOEXCEPT;
2753
2754 // FRIENDS
2755 friend
2756 bool operator==(const vector& lhs, const vector& rhs)
2757 {
2758 return lhs.d_impl == rhs.d_impl;
2759 }
2760
2761#ifdef BSLALG_SYNTHTHREEWAYUTIL_AVAILABLE
2762
2763 friend BloombergLP::bslalg::SynthThreeWayUtil::Result<Impl>
2764 operator<=>(const vector& lhs, const vector& rhs)
2765 {
2766 return BloombergLP::bslalg::SynthThreeWayUtil::compare(lhs.d_impl,
2767 rhs.d_impl);
2768 }
2769
2770#else
2771
2772 friend
2773 bool operator!=(const vector& lhs, const vector& rhs)
2774 {
2775 return lhs.d_impl != rhs.d_impl;
2776 }
2777
2778 friend
2779 bool operator<(const vector& lhs, const vector& rhs)
2780 {
2781 return lhs.d_impl < rhs.d_impl;
2782 }
2783
2784 friend
2785 bool operator>(const vector& lhs, const vector& rhs)
2786 {
2787 return lhs.d_impl > rhs.d_impl;
2788 }
2789
2790 friend
2791 bool operator<=(const vector& lhs, const vector& rhs)
2792 {
2793 return lhs.d_impl <= rhs.d_impl;
2794 }
2795
2796 friend
2797 bool operator>=(const vector& lhs, const vector& rhs)
2798 {
2799 return lhs.d_impl >= rhs.d_impl;
2800 }
2801
2802#endif // BSLALG_SYNTHTHREEWAYUTIL_AVAILABLE
2803
2804 friend
2805 void swap(vector& a, vector& b)
2807 a.d_impl.swap(b.d_impl)))
2808 {
2809 a.d_impl.swap(b.d_impl);
2810 }
2811};
2812
2813#ifdef BSLS_COMPILERFEATURES_SUPPORT_CTAD
2814// CLASS TEMPLATE DEDUCTION GUIDES
2815
2816/// Deduce the template parameter `VALUE` from the corresponding parameter
2817/// supplied to the constructor of `vector`. This deduction guide does not
2818/// participate unless the supplied allocator is convertible to
2819/// `bsl::allocator<VALUE>`.
2820template <
2821 class SIZE_TYPE,
2822 class VALUE,
2823 class ALLOC,
2824 class DEFAULT_ALLOCATOR = bsl::allocator<VALUE>,
2825 class = bsl::enable_if_t<
2826 bsl::is_convertible_v<
2827 SIZE_TYPE,
2829 class = bsl::enable_if_t<bsl::is_convertible_v<ALLOC *, DEFAULT_ALLOCATOR>>
2830 >
2831vector(SIZE_TYPE, VALUE, ALLOC *) -> vector<VALUE>;
2832
2833/// Deduce the template parameter `VALUE` from the `value_type` of the
2834/// iterators supplied to the constructor of `vector`.
2835template <
2836 class INPUT_ITERATOR,
2837 class VALUE =
2838 typename BloombergLP::bslstl::IteratorUtil::IterVal_t<INPUT_ITERATOR>
2839 >
2840vector(INPUT_ITERATOR, INPUT_ITERATOR) -> vector<VALUE>;
2841
2842/// Deduce the template parameter `VALUE` from the `value_type` of the
2843/// iterators supplied to the constructor of `vector`. This deduction
2844/// guide does not participate unless the supplied allocator meets the
2845/// requirements of a standard allocator.
2846template<
2847 class INPUT_ITERATOR,
2848 class ALLOCATOR,
2849 class VALUE =
2850 typename BloombergLP::bslstl::IteratorUtil::IterVal_t<INPUT_ITERATOR>,
2851 class = bsl::enable_if_t<bsl::IsStdAllocator_v<ALLOCATOR>>
2852 >
2853vector(INPUT_ITERATOR, INPUT_ITERATOR, ALLOCATOR) -> vector<VALUE, ALLOCATOR>;
2854
2855/// Deduce the template parameter `VALUE` from the `value_type` of the
2856/// iterators supplied to the constructor of `vector`. This deduction
2857/// guide does not participate unless the supplied allocator is convertible
2858/// to `bsl::allocator<VALUE>`.
2859template<
2860 class INPUT_ITERATOR,
2861 class ALLOC,
2862 class VALUE =
2863 typename BloombergLP::bslstl::IteratorUtil::IterVal_t<INPUT_ITERATOR>,
2864 class DEFAULT_ALLOCATOR = bsl::allocator<VALUE>,
2865 class = bsl::enable_if_t<bsl::is_convertible_v<ALLOC *, DEFAULT_ALLOCATOR>>
2866 >
2867vector(INPUT_ITERATOR, INPUT_ITERATOR, ALLOC *)
2868-> vector<VALUE>;
2869
2870/// Deduce the template parameter `VALUE` from the `value_type` of the
2871/// initializer_list supplied to the constructor of `vector`. This
2872/// deduction guide does not participate unless the supplied allocator is
2873/// convertible to `bsl::allocator<VALUE>`.
2874template<
2875 class VALUE,
2876 class ALLOC,
2877 class DEFAULT_ALLOCATOR = bsl::allocator<VALUE>,
2878 class = bsl::enable_if_t<bsl::is_convertible_v<ALLOC *, DEFAULT_ALLOCATOR>>
2879 >
2880vector(std::initializer_list<VALUE>, ALLOC *)
2881-> vector<VALUE>;
2882
2883#if defined(BSLS_LIBRARYFEATURES_HAS_CPP20_RANGES)
2884/// Deduce the template parameters `VALUE_TYPE` and `ALLOCATOR` from the
2885/// parameters supplied to the constructor of `vector`.
2886template <ranges::input_range t_RANGE,
2887 class t_ALLOCATOR =
2888 allocator<ranges::range_value_t<t_RANGE>>>
2889vector(from_range_t, t_RANGE&&, t_ALLOCATOR = t_ALLOCATOR())
2890-> vector<ranges::range_value_t<t_RANGE>, t_ALLOCATOR>;
2891#endif
2892#endif
2893
2894
2895// ============================================================================
2896// TEMPLATE AND INLINE FUNCTION DEFINITIONS
2897// ============================================================================
2898// See IMPLEMENTATION NOTES in the .cpp before modifying anything below.
2899
2900 // ======================================
2901 // class vector_UintPtrConversionIterator
2902 // ======================================
2903
2904/// This class provides a minimal proxy iterator adapter, transforming pointers
2905/// to `uintptr_t` values on the fly, for only the operations needed to
2906/// implement the member functions and constructors of the `vector` partial
2907/// template specialization that take iterator ranges as arguments. While it
2908/// does not provide a standard conforming iterator itself, if provides exactly
2909/// sufficient behavior to implement all the needed members. `VALUE_TYPE`
2910/// shall be a pointer type, and `ITERATOR` shall be a standard conforming
2911/// iterator that dereferences to a type implicitly convertible to `VALUE_TYPE`
2912///
2913/// See @ref bslstl_vector_cpp03
2914template <class VALUE_TYPE, class ITERATOR>
2915class vector_UintPtrConversionIterator {
2916
2917 private:
2918 // DATA
2919 ITERATOR d_iter;
2920
2921 public:
2922 // PUBLIC TYPES
2923 typedef BloombergLP::bsls::Types::UintPtr UintPtr;
2924
2925 typedef UintPtr value_type;
2926 typedef UintPtr *pointer;
2927 typedef UintPtr reference;
2928 typedef typename iterator_traits<ITERATOR>::difference_type
2929 difference_type;
2930 typedef typename iterator_traits<ITERATOR>::iterator_category
2931 iterator_category;
2932
2933 // CREATORS
2934
2935 /// Create an uninitialized proxy iterator.
2936 vector_UintPtrConversionIterator();
2937
2938 /// Create a proxy iterator adapting the specified `it`.
2939 vector_UintPtrConversionIterator(ITERATOR it); // IMPLICIT
2940
2941 // MANIPULATORS
2942
2943 /// Increment this iterator to refer to the next element in the underlying
2944 /// sequence, and return a reference to this object.
2945 vector_UintPtrConversionIterator& operator++();
2946
2947 /// Return this object, and increment this iterator to refer to the next
2948 /// element in the underlying sequence.
2949 vector_UintPtrConversionIterator operator++(int);
2950
2951 // ACCESSORS
2952
2953 /// Return the value of the pointer this iterator refers to, converted to
2954 /// an unsigned integer.
2955 UintPtr operator*() const;
2956
2957#ifdef BSLS_COMPILERFEATURES_SUPPORT_THREE_WAY_COMPARISON
2958
2959 /// Perform a three-way comparison with the specified `other` object and
2960 /// return the result of that comparison. Where the underlying (wrapped)
2961 /// iterator of type `ITERATOR` supports 3 way comparison, the default
2962 /// spaceship operator will defer to `ITERATOR::operator<=>` and have
2963 /// the same return type as `ITERATOR::operator<=>`; otherwise, this
2964 /// operator will be deleted.
2965 auto
2966 operator<=>(const vector_UintPtrConversionIterator& other) const = default;
2967
2968#else
2969
2970 // FRIENDS
2971
2972 /// Return `true` if the specified `lhs` and `rhs` iterators do not
2973 /// refer to the same element in the same underlying sequence and no
2974 /// more than one refers to the past-the-end element of the sequence, and `false` otherwise.
2975 ///
2976 /// \pre The behavior is undefined if `lhs` and `rhs`
2977 /// do not iterate over the same sequence.
2978 friend
2979 bool operator!=(const vector_UintPtrConversionIterator& lhs,
2980 const vector_UintPtrConversionIterator& rhs)
2981 {
2982 return lhs.d_iter != rhs.d_iter;
2983 }
2984
2985#endif // BSLS_COMPILERFEATURES_SUPPORT_THREE_WAY_COMPARISON
2986
2987 // FRIENDS
2988
2989 /// Return `true` if the specified `lhs` and `rhs` iterators refer to
2990 /// the same element in the same underlying sequence or both refer to
2991 /// the past-the-end element of the same sequence, and `false` otherwise.
2992 ///
2993 /// \pre The behavior is undefined if `lhs` and `rhs` do not
2994 /// iterate over the same sequence.
2995 friend
2996 bool operator==(const vector_UintPtrConversionIterator& lhs,
2997 const vector_UintPtrConversionIterator& rhs)
2998 {
2999 return lhs.d_iter == rhs.d_iter;
3000 }
3001
3002 /// Return `true` if the specified `lhs` iterator is earlier in the
3003 /// underlying sequence than the specified `rhs` iterator, and `false` otherwise.
3004 ///
3005 /// \pre The behavior is undefined if `lhs` and `rhs` do not
3006 /// iterate over the same sequence, or if the (template parameter) type
3007 /// `ITERATOR` is not a random access iterator.
3008 friend
3009 bool operator<(const vector_UintPtrConversionIterator& lhs,
3010 const vector_UintPtrConversionIterator& rhs)
3011 {
3012 return lhs.d_iter < rhs.d_iter;
3013 }
3014
3015#if defined(BSLS_LIBRARYFEATURES_HAS_CPP20_RANGES)
3016 bool operator==(bsl::sentinel_for<ITERATOR> auto rhs) const
3017 {
3018 return d_iter == rhs;
3019 }
3020 friend auto operator-(bsl::sentinel_for<ITERATOR> auto s,
3021 vector_UintPtrConversionIterator i)
3022 requires random_access_iterator<ITERATOR>
3023 {
3024 return s - i.d_iter;
3025 }
3026#endif
3027
3028 /// Return the distance between the specified `lhs` iterator and the specified `rhs` iterator.
3029 ///
3030 /// \pre The behavior is undefined if `lhs` and
3031 /// `rhs` do not iterate over the same sequence, or if the (template
3032 /// parameter) type `ITERATOR` is not a random access iterator.
3033 friend
3034 difference_type operator-(const vector_UintPtrConversionIterator& lhs,
3035 const vector_UintPtrConversionIterator& rhs)
3036#ifdef BSLS_LIBRARYFEATURES_HAS_CPP20_CONCEPTS
3037 requires requires { lhs.d_iter - rhs.d_iter; }
3038#endif
3039 {
3040 return lhs.d_iter - rhs.d_iter;
3041 }
3042};
3043
3044 // --------------------------------------
3045 // class vector_UintPtrConversionIterator
3046 // --------------------------------------
3047
3048// CREATORS
3049template <class VALUE_TYPE, class ITERATOR>
3050inline
3053{
3054}
3055
3056template <class VALUE_TYPE, class ITERATOR>
3057inline
3060: d_iter(it)
3061{
3062}
3063
3064// MANIPULATORS
3065template <class VALUE_TYPE, class ITERATOR>
3066inline
3067vector_UintPtrConversionIterator<VALUE_TYPE, ITERATOR>&
3068vector_UintPtrConversionIterator<VALUE_TYPE, ITERATOR>::operator++()
3069{
3070 ++d_iter;
3071 return *this;
3072}
3073
3074template <class VALUE_TYPE, class ITERATOR>
3075inline
3076vector_UintPtrConversionIterator<VALUE_TYPE, ITERATOR>
3077vector_UintPtrConversionIterator<VALUE_TYPE, ITERATOR>::operator++(int)
3078{
3079 vector_UintPtrConversionIterator tmp(*this);
3080 ++d_iter;
3081 return tmp;
3082}
3083
3084// ACCESSORS
3085template <class VALUE_TYPE, class ITERATOR>
3086inline
3087BloombergLP::bsls::Types::UintPtr
3088vector_UintPtrConversionIterator<VALUE_TYPE, ITERATOR>::operator*() const
3089{
3090 VALUE_TYPE const ptr = *d_iter;
3091 return reinterpret_cast<UintPtr>(ptr);
3092}
3093
3094 // =================================
3095 // struct vector_UintPtrRangeAdapter
3096 // =================================
3097
3098/// This class provides a minimal proxy range adapter, transforming pointers
3099/// to `uintptr_t` values on the fly, for only the operations needed to
3100/// implement the member functions and constructors of the `vector` partial
3101/// template specialization that take iterator ranges as arguments. While it
3102/// does not provide a standard conforming iterator itself, if provides exactly
3103/// sufficient behavior to implement all the needed members. `t_VALUE_TYPE`
3104/// shall be a pointer type, and `[d_begin, d_end)` is a range of the input
3105/// values.
3106///
3107/// See @ref bslstl_vector_cpp03
3108template <class t_VALUE_TYPE, class t_ITERATOR, class t_SENTINEL>
3109struct vector_UintPtrRangeAdapter {
3110 // TYPES
3111 typedef vector_UintPtrConversionIterator<t_VALUE_TYPE,t_ITERATOR> iterator;
3112 typedef iterator const_iterator;
3113
3114 // PUBLIC DATA
3115 t_ITERATOR d_begin;
3116 t_SENTINEL d_end;
3117
3118 // ACCESSORS
3119 iterator begin() const { return iterator(d_begin); }
3120 t_SENTINEL end() const { return d_end; }
3121};
3122
3123/// Factory function for `vector_UintPtrRangeAdapter`.
3124template <class t_VALUE_TYPE, class t_ITERATOR, class t_SENTINEL>
3125inline
3126vector_UintPtrRangeAdapter<t_VALUE_TYPE, t_ITERATOR, t_SENTINEL>
3127vector_makeUintPtrRangeAdapter(t_ITERATOR begin, t_SENTINEL end)
3128{
3129 vector_UintPtrRangeAdapter<t_VALUE_TYPE, t_ITERATOR, t_SENTINEL> range =
3130 {begin, end};
3131 return range;
3132}
3133
3134 // ========================
3135 // class Vector_PushProctor
3136 // ========================
3137
3138/// This class template provides a proctor for a newly created object that
3139/// is managed by an allocator. The object will be constructed through a
3140/// call to `allocator_traits<ALLOCATOR>::construct`, and it should be
3141/// destroyed by a call to `allocator_traits<ALLOCATOR>::destroy`.
3142///
3143/// \note Note that this proctor takes no responsibility for the allocated memory that
3144/// the supplied value is constructed in.
3145///
3146/// See @ref bslstl_vector_cpp03
3147template <class VALUE_TYPE, class ALLOCATOR>
3148class Vector_PushProctor {
3149
3150 // DATA
3151 VALUE_TYPE *d_target_p; // managed object
3152 ALLOCATOR d_allocator; // allocator to be used to destroy managed object
3153
3154 private:
3155 // NOT IMPLEMENTED
3156 Vector_PushProctor(const Vector_PushProctor&); // = delete;
3157 Vector_PushProctor& operator=(const Vector_PushProctor&); // = delete;
3158
3159 public:
3160 // CREATORS
3161
3162 /// Create a proctor that conditionally manages the specified `target`
3163 /// object (if non-zero) by destroying the managed object with a call to
3164 /// `allocator_traits<ALLOCATOR>::destroy` using the specified
3165 /// `allocator` upon destruction of this proctor, unless the managed
3166 /// objects has been released.
3167 Vector_PushProctor(VALUE_TYPE *target, const ALLOCATOR& allocator);
3168
3169 /// Destroy this proctor, and destroy the object it manages (if any) by
3170 /// a call to `allocator_traits<ALLOCATOR>::destroy` using the allocator
3171 /// supplied at construction. If no object is currently being managed,
3172 /// this method has no effect.
3173 ~Vector_PushProctor();
3174
3175 // MANIPULATORS
3176
3177 /// Release from management the object currently managed by this proctor.
3178 /// If no object is currently being managed, this method has no effect.
3179 void release();
3180};
3181
3182 // ------------------------
3183 // class Vector_PushProctor
3184 // ------------------------
3185
3186// CREATORS
3187template <class VALUE_TYPE, class ALLOCATOR>
3188inline
3189Vector_PushProctor<VALUE_TYPE,ALLOCATOR>::Vector_PushProctor(
3190 VALUE_TYPE *target,
3191 const ALLOCATOR& allocator)
3192: d_target_p(target)
3193, d_allocator(allocator)
3194{
3195}
3196
3197template <class VALUE_TYPE, class ALLOCATOR>
3198inline
3199Vector_PushProctor<VALUE_TYPE,ALLOCATOR>::~Vector_PushProctor()
3200{
3201 if (d_target_p) {
3202 bsl::allocator_traits<ALLOCATOR>::destroy(d_allocator, d_target_p);
3203 }
3204}
3205
3206// MANIPULATORS
3207template <class VALUE_TYPE, class ALLOCATOR>
3208inline
3209void Vector_PushProctor<VALUE_TYPE,ALLOCATOR>::release()
3210{
3211 d_target_p = 0;
3212}
3213
3214#if defined(BSLS_ASSERT_SAFE_IS_USED)
3215 // -----------------------
3216 // class Vector_RangeCheck
3217 // -----------------------
3218
3219template <class BSLSTL_ITERATOR, class SENTINEL>
3220inline
3221typename enable_if<!Vector_IsRandomAccessIterator<BSLSTL_ITERATOR>::value,
3222 bool>::type
3223Vector_RangeCheck::isInvalidRange(BSLSTL_ITERATOR, SENTINEL)
3224{
3225 return false;
3226}
3227
3228template <class BSLSTL_ITERATOR>
3229inline
3230typename enable_if<Vector_IsRandomAccessIterator<BSLSTL_ITERATOR>::value,
3231 bool>::type
3232Vector_RangeCheck::isInvalidRange(BSLSTL_ITERATOR first, BSLSTL_ITERATOR last)
3233{
3234 return last < first;
3235}
3236
3237template <class BSLSTL_ITERATOR, class SENTINEL>
3238inline
3239typename enable_if<Vector_IsRandomAccessIterator<BSLSTL_ITERATOR>::value,
3240 bool>::type
3241Vector_RangeCheck::isInvalidRange(BSLSTL_ITERATOR first, SENTINEL last)
3242{
3243 return last - first < 0;
3244}
3245#endif
3246
3247 // ----------------
3248 // class vectorBase
3249 // ----------------
3250
3251// CREATORS
3252template <class VALUE_TYPE>
3253inline
3254vectorBase<VALUE_TYPE>::vectorBase()
3255: d_dataBegin_p(0)
3256, d_dataEnd_p(0)
3257, d_capacity(0)
3258{
3259}
3260
3261// MANIPULATORS
3262
3263template <class VALUE_TYPE>
3264inline
3265void
3266vectorBase<VALUE_TYPE>::adopt(BloombergLP::bslmf::MovableRef<vectorBase> base)
3267{
3268 BSLS_ASSERT_SAFE(0 == d_dataBegin_p);
3269 BSLS_ASSERT_SAFE(0 == d_dataEnd_p);
3270 BSLS_ASSERT_SAFE(0 == d_capacity);
3271
3272 vectorBase& lvalue = base;
3273 d_dataBegin_p = lvalue.d_dataBegin_p;
3274 d_dataEnd_p = lvalue.d_dataEnd_p;
3275 d_capacity = lvalue.d_capacity;
3276
3277 lvalue.d_dataBegin_p = 0;
3278 lvalue.d_dataEnd_p = 0;
3279 lvalue.d_capacity = 0;
3280}
3281 // *** iterators ***
3282template <class VALUE_TYPE>
3283inline
3284typename vectorBase<VALUE_TYPE>::iterator
3285vectorBase<VALUE_TYPE>::begin() BSLS_KEYWORD_NOEXCEPT
3286{
3287 return d_dataBegin_p;
3288}
3289
3290template <class VALUE_TYPE>
3291inline
3292typename vectorBase<VALUE_TYPE>::iterator
3293vectorBase<VALUE_TYPE>::end() BSLS_KEYWORD_NOEXCEPT
3294{
3295 return d_dataEnd_p;
3296}
3297
3298template <class VALUE_TYPE>
3299inline
3300typename vectorBase<VALUE_TYPE>::reverse_iterator
3301vectorBase<VALUE_TYPE>::rbegin() BSLS_KEYWORD_NOEXCEPT
3302{
3303 return reverse_iterator(end());
3304}
3305
3306template <class VALUE_TYPE>
3307inline
3308typename vectorBase<VALUE_TYPE>::reverse_iterator
3309vectorBase<VALUE_TYPE>::rend() BSLS_KEYWORD_NOEXCEPT
3310{
3311 return reverse_iterator(begin());
3312}
3313
3314 // *** element access ***
3315
3316template <class VALUE_TYPE>
3317inline
3318typename vectorBase<VALUE_TYPE>::reference
3319vectorBase<VALUE_TYPE>::operator[](size_type position)
3320{
3321 BSLS_ASSERT_SAFE(size() > position);
3322
3323 return d_dataBegin_p[position];
3324}
3325
3326template <class VALUE_TYPE>
3327typename vectorBase<VALUE_TYPE>::reference
3328vectorBase<VALUE_TYPE>::at(size_type position)
3329{
3330 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(position >= size())) {
3332 BloombergLP::bslstl::StdExceptUtil::throwOutOfRange(
3333 "vector<...>::at(position): invalid position");
3334 }
3335 return d_dataBegin_p[position];
3336}
3337
3338template <class VALUE_TYPE>
3339inline
3340typename vectorBase<VALUE_TYPE>::reference
3341vectorBase<VALUE_TYPE>::front()
3342{
3344
3345 return *d_dataBegin_p;
3346}
3347
3348template <class VALUE_TYPE>
3349inline
3350typename vectorBase<VALUE_TYPE>::reference
3351vectorBase<VALUE_TYPE>::back()
3352{
3354
3355 return *(d_dataEnd_p - 1);
3356}
3357
3358template <class VALUE_TYPE>
3359inline
3360VALUE_TYPE *
3361vectorBase<VALUE_TYPE>::data() BSLS_KEYWORD_NOEXCEPT
3362{
3363 return d_dataBegin_p;
3364}
3365
3366// ACCESSORS
3367
3368 // *** iterators ***
3369template <class VALUE_TYPE>
3370inline
3371typename vectorBase<VALUE_TYPE>::const_iterator
3372vectorBase<VALUE_TYPE>::begin() const BSLS_KEYWORD_NOEXCEPT
3373{
3374 return d_dataBegin_p;
3375}
3376
3377template <class VALUE_TYPE>
3378inline
3379typename vectorBase<VALUE_TYPE>::const_iterator
3380vectorBase<VALUE_TYPE>::cbegin() const BSLS_KEYWORD_NOEXCEPT
3381{
3382 return d_dataBegin_p;
3383}
3384
3385template <class VALUE_TYPE>
3386inline
3387typename vectorBase<VALUE_TYPE>::const_iterator
3388vectorBase<VALUE_TYPE>::end() const BSLS_KEYWORD_NOEXCEPT
3389{
3390 return d_dataEnd_p;
3391}
3392
3393template <class VALUE_TYPE>
3394inline
3395typename vectorBase<VALUE_TYPE>::const_iterator
3396vectorBase<VALUE_TYPE>::cend() const BSLS_KEYWORD_NOEXCEPT
3397{
3398 return d_dataEnd_p;
3399}
3400
3401template <class VALUE_TYPE>
3402inline
3403typename vectorBase<VALUE_TYPE>::const_reverse_iterator
3404vectorBase<VALUE_TYPE>::rbegin() const BSLS_KEYWORD_NOEXCEPT
3405{
3406 return const_reverse_iterator(end());
3407}
3408
3409template <class VALUE_TYPE>
3410inline
3411typename vectorBase<VALUE_TYPE>::const_reverse_iterator
3412vectorBase<VALUE_TYPE>::crbegin() const BSLS_KEYWORD_NOEXCEPT
3413{
3414 return const_reverse_iterator(end());
3415}
3416
3417template <class VALUE_TYPE>
3418inline
3419typename vectorBase<VALUE_TYPE>::const_reverse_iterator
3420vectorBase<VALUE_TYPE>::rend() const BSLS_KEYWORD_NOEXCEPT
3421{
3422 return const_reverse_iterator(begin());
3423}
3424
3425template <class VALUE_TYPE>
3426inline
3427typename vectorBase<VALUE_TYPE>::const_reverse_iterator
3428vectorBase<VALUE_TYPE>::crend() const BSLS_KEYWORD_NOEXCEPT
3429{
3430 return const_reverse_iterator(begin());
3431}
3432
3433 // *** capacity ***
3434
3435template <class VALUE_TYPE>
3436inline
3437typename vectorBase<VALUE_TYPE>::size_type
3438vectorBase<VALUE_TYPE>::size() const BSLS_KEYWORD_NOEXCEPT
3439{
3440 return d_dataEnd_p - d_dataBegin_p;
3441}
3442
3443template <class VALUE_TYPE>
3444inline
3445typename vectorBase<VALUE_TYPE>::size_type
3446vectorBase<VALUE_TYPE>::capacity() const BSLS_KEYWORD_NOEXCEPT
3447{
3448 return d_capacity;
3449}
3450
3451template <class VALUE_TYPE>
3452inline
3453bool vectorBase<VALUE_TYPE>::empty() const BSLS_KEYWORD_NOEXCEPT
3454{
3455 return d_dataEnd_p == d_dataBegin_p;
3456}
3457
3458 // *** element access ***
3459template <class VALUE_TYPE>
3460inline
3461typename vectorBase<VALUE_TYPE>::const_reference
3462vectorBase<VALUE_TYPE>::operator[](size_type position) const
3463{
3464 BSLS_ASSERT_SAFE(size() > position);
3465
3466 return d_dataBegin_p[position];
3467}
3468
3469template <class VALUE_TYPE>
3470typename vectorBase<VALUE_TYPE>::const_reference
3471vectorBase<VALUE_TYPE>::at(size_type position) const
3472{
3473 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(position >= size())) {
3475 BloombergLP::bslstl::StdExceptUtil::throwOutOfRange(
3476 "const vector<...>::at(position): invalid position");
3477 }
3478 return d_dataBegin_p[position];
3479}
3480
3481template <class VALUE_TYPE>
3482inline
3483typename vectorBase<VALUE_TYPE>::const_reference
3484vectorBase<VALUE_TYPE>::front() const
3485{
3487
3488 return *d_dataBegin_p;
3489}
3490
3491template <class VALUE_TYPE>
3492inline
3493typename vectorBase<VALUE_TYPE>::const_reference
3494vectorBase<VALUE_TYPE>::back() const
3495{
3497
3498 return *(d_dataEnd_p - 1);
3499}
3500
3501template <class VALUE_TYPE>
3502inline
3503const VALUE_TYPE *
3504vectorBase<VALUE_TYPE>::data() const BSLS_KEYWORD_NOEXCEPT
3505{
3506 return d_dataBegin_p;
3507}
3508
3509 // --------------------------------------------
3510 // class vector<VALUE_TYPE, ALLOCATOR>::Proctor
3511 // --------------------------------------------
3512
3513// CREATORS
3514template <class VALUE_TYPE, class ALLOCATOR>
3516vector<VALUE_TYPE, ALLOCATOR>::Proctor::Proctor(VALUE_TYPE *data,
3517 std::size_t capacity,
3518 ContainerBase *container)
3519: d_data_p(data)
3520, d_capacity(capacity)
3521, d_container_p(container)
3522{
3523}
3524
3525template <class VALUE_TYPE, class ALLOCATOR>
3527vector<VALUE_TYPE, ALLOCATOR>::Proctor::~Proctor()
3528{
3529 using BloombergLP::bslma::AllocatorUtil;
3530
3531 if (d_data_p) {
3532 AllocatorUtil::deallocateObject(d_container_p->allocatorRef(),
3533 d_data_p, d_capacity);
3534 }
3535}
3536
3537// MANIPULATORS
3538template <class VALUE_TYPE, class ALLOCATOR>
3540void vector<VALUE_TYPE, ALLOCATOR>::Proctor::release()
3541{
3542 d_data_p = 0;
3543}
3544
3545 // ------------
3546 // class vector
3547 // ------------
3548
3549// PRIVATE MANIPULATORS
3550template <class VALUE_TYPE, class ALLOCATOR>
3551template <class t_RANGE, class t_ITERATOR>
3552inline
3553void vector<VALUE_TYPE, ALLOCATOR>::privateConstruct(
3554 from_range_t ,
3555 BSLS_COMPILERFEATURES_FORWARD_REF(t_RANGE) range,
3556 t_ITERATOR begin)
3557{
3558 BSLS_ASSERT_SAFE(begin == ranges::begin(range));
3559 BSLS_ASSERT_SAFE(!Vector_RangeCheck::isInvalidRange(begin,
3560 ranges::end(range)));
3561
3562 typedef typename Vector_DeduceIteratorCategory<t_ITERATOR>::type Tag;
3563
3564 privateConstruct(from_range,
3565 BSLS_COMPILERFEATURES_FORWARD(t_RANGE, range),
3566 begin,
3567 Tag());
3568}
3569
3570template <class VALUE_TYPE, class ALLOCATOR>
3571template <class t_RANGE, class t_ITERATOR>
3572inline
3573void vector<VALUE_TYPE, ALLOCATOR>::privateConstruct(
3574 from_range_t ,
3575 BSLS_COMPILERFEATURES_FORWARD_REF(t_RANGE) range,
3576 t_ITERATOR begin,
3577 std::forward_iterator_tag)
3578{
3579#if defined(BSLS_LIBRARYFEATURES_HAS_CPP20_RANGES)
3580 if constexpr (ranges::sized_range<t_RANGE>) {
3581 constructFromSizedRange(begin,
3582 ranges::end(range),
3583 ranges::size(range));
3584 }
3585 else //
3586#endif
3587 constructFromSizedRange(
3588 begin,
3589 ranges::end(range),
3590 BloombergLP::bslstl::IteratorUtil::insertDistance(begin,
3591 ranges::end(range)));
3592}
3593
3594template <class VALUE_TYPE, class ALLOCATOR>
3595template <class t_RANGE, class t_ITERATOR>
3596inline
3597void vector<VALUE_TYPE, ALLOCATOR>::privateConstruct(
3598 from_range_t ,
3599 BSLS_COMPILERFEATURES_FORWARD_REF(t_RANGE) range,
3600 t_ITERATOR begin,
3601 std::input_iterator_tag)
3602{
3603#if defined(BSLS_LIBRARYFEATURES_HAS_CPP20_RANGES)
3604 if constexpr (ranges::sized_range<t_RANGE>) {
3605 constructFromSizedRange(begin,
3606 ranges::end(range),
3607 ranges::size(range));
3608 }
3609 else // ...
3610#endif
3611 if (begin != ranges::end(range)) {
3612 constructFromRange(begin,
3613 ranges::end(range),
3614 std::input_iterator_tag());
3615 }
3616}
3617
3618template <class VALUE_TYPE, class ALLOCATOR>
3619template <class FWD_ITER, class SENTINEL>
3620inline
3621void vector<VALUE_TYPE, ALLOCATOR>::constructFromRange(
3622 FWD_ITER first,
3623 SENTINEL last,
3624 std::forward_iterator_tag)
3625{
3626 // Specialization for all iterators except input iterators: 'size' can be
3627 // computed in advance.
3628 BSLS_ASSERT_SAFE(!Vector_RangeCheck::isInvalidRange(first, last));
3629 BSLS_ASSERT_OPT((BloombergLP::bslstl::IteratorUtil
3630 ::canCalculateInsertDistance<FWD_ITER, FWD_ITER>()));
3631
3632 constructFromSizedRange(
3633 first,
3634 last,
3635 BloombergLP::bslstl::IteratorUtil::insertDistance(first, last));
3636}
3637
3638template <class VALUE_TYPE, class ALLOCATOR>
3639template <class INPUT_ITER, class SENTINEL>
3640void vector<VALUE_TYPE, ALLOCATOR>::constructFromRange(
3641 INPUT_ITER first,
3642 SENTINEL last,
3643 std::input_iterator_tag)
3644{
3645 // IMPLEMENTATION NOTES: construct this vector by iterated 'push_back',
3646 // which may reallocate memory multiple times, but unfortunately is
3647 // required because we can't compute the size in advance (as with
3648 // @ref forward_iterator_tag ) because input iterators can be traversed only
3649 // once. A temporary vector is populated and then swapped to ensure that
3650 // all memory is reclaimed if @ref emplace_back throws, as the destructor will
3651 // not run when this method is called from a constructor.
3652
3653 vector temp(this->get_allocator());
3654 while (first != last) {
3655 temp.emplace_back(*first);
3656 ++first;
3657 }
3658 Vector_Util::swap(&this->d_dataBegin_p, &temp.d_dataBegin_p);
3659}
3660
3661template <class VALUE_TYPE, class ALLOCATOR>
3662template <class INTEGRAL>
3663void vector<VALUE_TYPE, ALLOCATOR>::constructFromRange(
3664 INTEGRAL initialSize,
3665 INTEGRAL value,
3666 BloombergLP::bslmf::Nil)
3667{
3668 // IMPLEMENTATION NOTES: this constructor is trying to construct a range of
3669 // 'initialSize' elements having the specified integral 'value'. Without
3670 // this extra overload, such calls would match an attempt to construct from
3671 // a range specified by two iterators. Note that as 'VALUE_TYPE' must be
3672 // a (trivial) integral type, a proctor is almost certainly not needed.
3673 // The only risk of a throw is for user-defined allocators doing strange
3674 // extra (potentially throwing) work in their 'construct' call.
3675
3677 static_cast<size_type>(initialSize) > max_size())) {
3679 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
3680 "vector<...>::(repeated-value constructor): input too long");
3681 }
3682
3683 if (initialSize > 0) {
3684 privateReserveEmpty(initialSize);
3685 Proctor proctor(this->d_dataBegin_p,
3686 this->d_capacity,
3687 static_cast<ContainerBase *>(this));
3688
3689 ArrayPrimitives::uninitializedFillN(this->d_dataBegin_p,
3690 initialSize,
3691 static_cast<VALUE_TYPE>(value),
3692 this->allocatorRef());
3693
3694 proctor.release();
3695 this->d_dataEnd_p += initialSize;
3696 }
3697}
3698
3699template <class VALUE_TYPE, class ALLOCATOR>
3700template <class t_ITERATOR, class t_SENTINEL>
3701void vector<VALUE_TYPE, ALLOCATOR>::constructFromSizedRange(t_ITERATOR first,
3702 t_SENTINEL last,
3703 size_type size)
3704{
3705 if (size == 0) {
3706 return; // RETURN
3707 }
3708
3709 const size_type maxSize = max_size();
3710 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(size > maxSize)) {
3712 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
3713 "vector<...>::(range-constructor): input too long");
3714 }
3715
3716 size_type newCapacity = Vector_Util::computeNewCapacity(size, 0, maxSize);
3717 this->privateReserveEmpty(newCapacity);
3718 Proctor proctor(this->d_dataBegin_p,
3719 this->d_capacity,
3720 static_cast<ContainerBase *>(this));
3721
3722 ArrayPrimitives::copyConstruct(this->d_dataEnd_p,
3723 first,
3724 last,
3725 this->allocatorRef());
3726 proctor.release();
3727 this->d_dataEnd_p += size;
3728}
3729
3730template <class VALUE_TYPE, class ALLOCATOR>
3731template <class t_RANGE, class t_ITERATOR>
3732inline
3733void vector<VALUE_TYPE, ALLOCATOR>::privateAppendRange(
3734 BSLS_COMPILERFEATURES_FORWARD_REF(t_RANGE) range,
3735 t_ITERATOR begin)
3736{
3737 BSLS_ASSERT_SAFE(begin == ranges::begin(range));
3738
3739 typedef typename Vector_DeduceIteratorCategory<t_ITERATOR>::type Tag;
3740 privateAppendRange(BSLS_COMPILERFEATURES_FORWARD(t_RANGE, range),
3741 begin,
3742 Tag());
3743}
3744
3745template <class VALUE_TYPE, class ALLOCATOR>
3746template <class t_RANGE, class t_ITERATOR>
3747inline
3748void vector<VALUE_TYPE, ALLOCATOR>::privateAppendRange(
3749 BSLS_COMPILERFEATURES_FORWARD_REF(t_RANGE) range,
3750 t_ITERATOR begin,
3751 std::forward_iterator_tag)
3752{
3753#if defined(BSLS_LIBRARYFEATURES_HAS_CPP20_RANGES)
3754 if constexpr (ranges::sized_range<t_RANGE>) {
3755 privateAppendSizedRange(begin,
3756 ranges::end(range),
3757 ranges::size(range));
3758 }
3759 else //
3760#endif
3761 privateAppendSizedRange(
3762 begin,
3763 ranges::end(range),
3764 BloombergLP::bslstl::IteratorUtil::insertDistance(begin,
3765 ranges::end(range)));
3766}
3767
3768template <class VALUE_TYPE, class ALLOCATOR>
3769template <class t_RANGE, class t_ITERATOR>
3770inline
3771void vector<VALUE_TYPE, ALLOCATOR>::privateAppendRange(
3772 BSLS_COMPILERFEATURES_FORWARD_REF(t_RANGE) range,
3773 t_ITERATOR begin,
3774 std::input_iterator_tag)
3775{
3776#if defined(BSLS_LIBRARYFEATURES_HAS_CPP20_RANGES)
3777 if constexpr (ranges::sized_range<t_RANGE>) {
3778 privateAppendSizedRange(begin,
3779 ranges::end(range),
3780 ranges::size(range));
3781 }
3782 else // ...
3783#endif
3784 {
3785 privateAppendUnsizedRange(begin, ranges::end(range));
3786 }
3787}
3788
3789template <class VALUE_TYPE, class ALLOCATOR>
3790template <class t_ITERATOR, class t_SENTINEL>
3791inline
3792void vector<VALUE_TYPE, ALLOCATOR>::privateAppendSizedRange(
3793 t_ITERATOR begin,
3794 t_SENTINEL end,
3795 size_type rangeSize)
3796{
3797 if (rangeSize == 0) {
3798 return; // RETURN
3799 }
3800
3801 size_type size = this->size();
3802 size_type diff = max_size() - size;
3803 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(rangeSize > diff)) {
3805 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
3806 "vector<...>::(range-constructor): input too long");
3807 }
3808
3809 size += rangeSize;
3810 if (size > this->capacity()) {
3811 this->reserve(size);
3812 }
3813 BSLS_ASSERT_SAFE(this->capacity() >= size);
3814 ArrayPrimitives::copyConstruct(this->d_dataEnd_p,
3815 begin,
3816 end,
3817 this->allocatorRef());
3818 this->d_dataEnd_p += rangeSize;
3819}
3820
3821template <class VALUE_TYPE, class ALLOCATOR>
3822template <class t_ITERATOR, class t_SENTINEL>
3823inline
3824void vector<VALUE_TYPE, ALLOCATOR>::privateAppendUnsizedRange(t_ITERATOR begin,
3825 t_SENTINEL end)
3826{
3827 for (; begin != end; ++begin) {
3828 emplace_back(*begin);
3829 }
3830}
3831
3832template <class VALUE_TYPE, class ALLOCATOR>
3833template <class INPUT_ITER>
3834inline
3835void vector<VALUE_TYPE, ALLOCATOR>::privateInsertDispatch(
3836 const_iterator position,
3837 INPUT_ITER count,
3838 INPUT_ITER value,
3839 BloombergLP::bslmf::MatchArithmeticType ,
3840 BloombergLP::bslmf::Nil )
3841{
3842 // 'count' and 'value' are integral types that just happen to be the same.
3843 // They are not iterators, so we call 'insert(position, count, value)'.
3844
3845 this->insert(position,
3846 static_cast<size_type>(count),
3847 static_cast<VALUE_TYPE>(value));
3848}
3849
3850template <class VALUE_TYPE, class ALLOCATOR>
3851template <class INPUT_ITER>
3852inline
3853void vector<VALUE_TYPE, ALLOCATOR>::privateInsertDispatch(
3854 const_iterator position,
3855 INPUT_ITER first,
3856 INPUT_ITER last,
3857 BloombergLP::bslmf::MatchAnyType ,
3858 BloombergLP::bslmf::MatchAnyType )
3859{
3860 // Dispatch based on iterator category.
3861 BSLS_ASSERT_SAFE(!Vector_RangeCheck::isInvalidRange(first, last));
3862
3863 typedef typename Vector_RangeIteratorCategory<INPUT_ITER,INPUT_ITER>::type
3864 Tag;
3865 this->privateInsert(position, first, last, Tag());
3866}
3867
3868template <class VALUE_TYPE, class ALLOCATOR>
3869template <class t_ITERATOR, class t_SENTINEL>
3870inline
3871void vector<VALUE_TYPE, ALLOCATOR>::privateInsert(const_iterator position,
3872 t_ITERATOR first,
3873 t_SENTINEL last)
3874{
3875 typedef typename Vector_RangeIteratorCategory<t_ITERATOR, t_SENTINEL>::type
3876 Tag;
3877 this->privateInsert(position, first, last, Tag());
3878}
3879
3880template <class VALUE_TYPE, class ALLOCATOR>
3881template <class INPUT_ITER, class SENTINEL>
3882void vector<VALUE_TYPE, ALLOCATOR>::privateInsert(
3883 const_iterator position,
3884 INPUT_ITER first,
3885 SENTINEL last,
3886 const std::input_iterator_tag&)
3887{
3888 // IMPLEMENTATION NOTES: We can't compute the size in advance. Append onto
3889 // the back of the current vector while capacity remains. This honors the
3890 // idea of not allocating unnecessarily for the temporary vector, and so
3891 // saves important cycles from a sequential allocator. We then need to
3892 // shuffle the data back into the correct position. If capacity must grow,
3893 // then create a new vector and move just the newly inserted elements into
3894 // place, moving the original vector elements only in the event that all
3895 // iterated elements are correctly inserted.
3896
3897 // Short-circuit if there is nothing to do, do not allocate for an empty
3898 // 'vector' as that would invalidate 'begin'.
3899
3900 if (first == last) {
3901 return; // RETURN
3902 }
3903
3904 if (!this->capacity()) {
3905 privateReserveEmpty(size_type(1));
3906 position = this->d_dataBegin_p; // 'position' must have been null
3907 }
3908
3909 size_type insertOffset = position - this->d_dataBegin_p;
3910 size_type initialEnd = this->size();
3911 size_type tailLength = this->end() - position;
3912
3913 VALUE_TYPE *emplaceBegin = this->d_dataEnd_p;
3914 VALUE_TYPE *emplaceEnd = this->d_dataBegin_p + this->d_capacity;
3915 VALUE_TYPE *emplacePosition = emplaceBegin;
3916
3917 allocator_type alloc(this->get_allocator()); // need non-'const' lvalue
3918
3919 // This vector is not used if sufficient capacity can be found in the
3920 // current vector for all the insertions. However, it must have a
3921 // lifetime longer than the destructor guard below, in order to ensure
3922 // that the guarded elements are destroyed before the allocated storage
3923 // that holds them if an exception is thrown.
3924 vector resultState(alloc); // vector that will build the final state
3925
3926 // TBD: We really need an allocator-aware 'AutoDestructor' that will call
3927 // 'allocator_traits<ALLOC>::destroy(allocator, pointer)' rather than
3928 // invoke the destructor directly. 'bslalg::AutoArrayDestructor' is close,
3929 // but lacks 'reset'.
3930 BloombergLP::bslma::AutoDestructor<VALUE_TYPE> insertProctor(
3931 emplacePosition);
3932 while (emplacePosition != emplaceEnd) {
3933 AllocatorTraits::construct(alloc, emplacePosition, *first);
3934 ++insertProctor;
3935 ++emplacePosition;
3936 if (++first == last) {
3937 this->d_dataEnd_p = emplacePosition;
3938 insertProctor.release();
3939
3940 ArrayPrimitives::rotate(this->d_dataBegin_p + insertOffset,
3941 this->d_dataBegin_p + initialEnd,
3942 this->d_dataEnd_p);
3943 return; // RETURN
3944 }
3945 }
3946
3947 // Now we need to grow a buffer and destructive-move only the new elements.
3948 // This needs to be handled in a loop that can allow for multiple growth
3949 // spurts.
3950
3951 resultState.reserve(this->d_capacity*2);
3952 emplacePosition = resultState.d_dataBegin_p + insertOffset;
3953 ArrayPrimitives::destructiveMove(emplacePosition,
3954 emplaceBegin,
3955 emplaceEnd,
3956 alloc);
3957
3958 size_type emplaceOffset = (emplaceEnd - emplaceBegin);
3959 insertProctor.reset(emplacePosition);
3960 emplaceBegin = emplacePosition;
3961 emplaceEnd = resultState.d_dataBegin_p + resultState.d_capacity
3962 - tailLength;
3963 emplacePosition += emplaceOffset;
3964
3965 while (first != last) {
3966 if (emplacePosition == emplaceEnd) {
3967 // need to grow again
3968 vector nextResult(alloc);
3969 nextResult.reserve(resultState.d_capacity*2);
3970 emplacePosition = nextResult.d_dataBegin_p + insertOffset;
3971 ArrayPrimitives::destructiveMove(emplacePosition,
3972 emplaceBegin,
3973 emplaceEnd,
3974 alloc);
3975
3976 insertProctor.reset(emplacePosition);
3977 emplaceOffset = (emplaceEnd - emplaceBegin);
3978 emplaceBegin = emplacePosition;
3979 emplaceEnd = nextResult.d_dataBegin_p + nextResult.d_capacity
3980 - tailLength;
3981 emplacePosition += emplaceOffset;
3982
3983 Vector_Util::swap(&nextResult.d_dataBegin_p,
3984 &resultState.d_dataBegin_p);
3985 }
3986
3987 AllocatorTraits::construct(alloc, emplacePosition, *first);
3988 ++insertProctor;
3989 ++emplacePosition;
3990 ++first;
3991 }
3992
3993 // move tail
3994 ArrayPrimitives::destructiveMove(emplacePosition,
3995 this->d_dataBegin_p + insertOffset,
3996 this->d_dataBegin_p + initialEnd,
3997 alloc);
3998
3999 // reset 'end' in case a throw follows:
4000 this->d_dataEnd_p = this->d_dataBegin_p + insertOffset;
4001 emplacePosition += (initialEnd - insertOffset);
4002 insertProctor.setLength(
4003 insertProctor.length() + static_cast<int>(initialEnd - insertOffset));
4004
4005 // move prefix
4006 ArrayPrimitives::destructiveMove(resultState.d_dataBegin_p,
4007 this->d_dataBegin_p,
4008 this->d_dataBegin_p + insertOffset,
4009 alloc);
4010
4011 // Nothing after this point can throw.
4012
4013 // 'resultState' adopts ownership of all elements
4014 resultState.d_dataEnd_p = emplacePosition;
4015
4016 // We no longer own any data to protect
4017 insertProctor.release();
4018 this->d_dataEnd_p = this->d_dataBegin_p;
4019
4020 // Finally, swap states
4021 Vector_Util::swap(&this->d_dataBegin_p, &resultState.d_dataBegin_p);
4022}
4023
4024template <class VALUE_TYPE, class ALLOCATOR>
4025template <class FWD_ITER, class SENTINEL>
4026void vector<VALUE_TYPE, ALLOCATOR>::privateInsert(
4027 const_iterator position,
4028 FWD_ITER first,
4029 SENTINEL last,
4030 const std::forward_iterator_tag&)
4031{
4032 // Specialization for all iterators except input iterators: 'size' can be
4033 // computed in advance.
4034 BSLS_ASSERT_SAFE(!Vector_RangeCheck::isInvalidRange(first, last));
4035 BSLS_ASSERT_OPT((BloombergLP::bslstl::IteratorUtil
4036 ::canCalculateInsertDistance<FWD_ITER, SENTINEL>()));
4037
4038 const iterator& pos = const_cast<iterator>(position);
4039
4040 const size_type maxSize = max_size();
4041 const size_type n =
4042 BloombergLP::bslstl::IteratorUtil::insertDistance(first, last);
4043
4044 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(n > maxSize - this->size())) {
4046 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4047 "vector<...>::insert(pos,first,last): vector too long");
4048 }
4049
4050 const size_type newSize = this->size() + n;
4051 if (newSize > this->d_capacity) {
4052 size_type newCapacity = Vector_Util::computeNewCapacity(
4053 newSize,
4054 this->d_capacity,
4055 maxSize);
4056
4057 vector temp(this->get_allocator());
4058 temp.privateReserveEmpty(newCapacity);
4059
4060 ArrayPrimitives::destructiveMoveAndInsert(temp.d_dataBegin_p,
4061 &this->d_dataEnd_p,
4062 this->d_dataBegin_p,
4063 pos,
4064 this->d_dataEnd_p,
4065 first,
4066 last,
4067 n,
4068 this->allocatorRef());
4069 temp.d_dataEnd_p += newSize;
4070 Vector_Util::swap(&this->d_dataBegin_p, &temp.d_dataBegin_p);
4071 }
4072 else {
4073 ArrayPrimitives::insert(pos,
4074 this->end(),
4075 first,
4076 last,
4077 n,
4078 this->allocatorRef());
4079 this->d_dataEnd_p += n;
4080 }
4081}
4082
4083template <class VALUE_TYPE, class ALLOCATOR>
4084void vector<VALUE_TYPE, ALLOCATOR>::privateMoveInsert(
4085 vector *fromVector,
4086 const_iterator position)
4087{
4088 const iterator& pos = const_cast<const iterator&>(position);
4089
4090 const size_type maxSize = max_size();
4091 const size_type n = fromVector->size();
4092 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(n > maxSize - this->size())) {
4094 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4095 "vector<...>::insert(pos,first,last): vector too long");
4096 }
4097
4098 const size_type newSize = this->size() + n;
4099 if (newSize > this->d_capacity) {
4100 const size_type newCapacity = Vector_Util::computeNewCapacity(
4101 newSize,
4102 this->d_capacity,
4103 maxSize);
4104
4105 vector temp(this->get_allocator());
4106 temp.privateReserveEmpty(newCapacity);
4107
4108 ArrayPrimitives::destructiveMoveAndMoveInsert(
4109 temp.d_dataBegin_p,
4110 &this->d_dataEnd_p,
4111 &fromVector->d_dataEnd_p,
4112 this->d_dataBegin_p,
4113 pos,
4114 this->d_dataEnd_p,
4115 fromVector->d_dataBegin_p,
4116 fromVector->d_dataEnd_p,
4117 n,
4118 this->allocatorRef());
4119 temp.d_dataEnd_p += newSize;
4120 Vector_Util::swap(&this->d_dataBegin_p, &temp.d_dataBegin_p);
4121 }
4122 else {
4123 ArrayPrimitives::moveInsert(pos,
4124 this->end(),
4125 &fromVector->d_dataEnd_p,
4126 fromVector->d_dataBegin_p,
4127 fromVector->d_dataEnd_p,
4128 n,
4129 this->allocatorRef());
4130 this->d_dataEnd_p += n;
4131 }
4132}
4133
4134template <class VALUE_TYPE, class ALLOCATOR>
4135inline
4136void vector<VALUE_TYPE, ALLOCATOR>::privateReserveEmpty(size_type numElements)
4137{
4138 BSLS_ASSERT_SAFE(this->empty());
4139 BSLS_ASSERT_SAFE(0 == this->capacity());
4140
4141 this->d_dataBegin_p = this->d_dataEnd_p =
4142 AllocatorUtil::allocateObject<VALUE_TYPE>(this->allocatorRef(),
4143 numElements);
4144
4145 this->d_capacity = numElements;
4146}
4147
4148#if BSLS_COMPILERFEATURES_SIMULATE_VARIADIC_TEMPLATES
4149// {{{ BEGIN GENERATED CODE
4150// Command line: sim_cpp11_features.py bslstl_vector.h
4151#ifndef BSLSTL_VECTOR_VARIADIC_LIMIT
4152#define BSLSTL_VECTOR_VARIADIC_LIMIT 10
4153#endif
4154#ifndef BSLSTL_VECTOR_VARIADIC_LIMIT_D
4155#define BSLSTL_VECTOR_VARIADIC_LIMIT_D BSLSTL_VECTOR_VARIADIC_LIMIT
4156#endif
4157#if BSLSTL_VECTOR_VARIADIC_LIMIT_D >= 0
4158template <class VALUE_TYPE, class ALLOCATOR>
4159void vector<VALUE_TYPE, ALLOCATOR>::privateEmplaceBackWithAllocation(
4160 )
4161{
4162 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(max_size() == this->size())) {
4164 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4165 "vector<...>:emplace_back(args...): vector too long");
4166 }
4167
4168 size_type newCapacity = Vector_Util::computeNewCapacity(this->size() + 1,
4169 this->d_capacity,
4170 this->max_size());
4171 vector temp(this->get_allocator());
4172 temp.privateReserveEmpty(newCapacity);
4173
4174 VALUE_TYPE *pos = temp.d_dataBegin_p + this->size();
4175 AllocatorTraits::construct(
4176 this->allocatorRef(),
4177 pos);
4178
4179 Vector_PushProctor<VALUE_TYPE, ALLOCATOR> guard(pos, this->allocatorRef());
4180 ArrayPrimitives::destructiveMove(temp.d_dataBegin_p,
4181 this->d_dataBegin_p,
4182 this->d_dataEnd_p,
4183 this->allocatorRef());
4184 guard.release();
4185
4186 this->d_dataEnd_p = this->d_dataBegin_p;
4187 temp.d_dataEnd_p = ++pos;
4188 Vector_Util::swap(&this->d_dataBegin_p, &temp.d_dataBegin_p);
4189}
4190#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_D >= 0
4191
4192#if BSLSTL_VECTOR_VARIADIC_LIMIT_D >= 1
4193template <class VALUE_TYPE, class ALLOCATOR>
4194template <class Args_01>
4195void vector<VALUE_TYPE, ALLOCATOR>::privateEmplaceBackWithAllocation(
4196 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01)
4197{
4198 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(max_size() == this->size())) {
4200 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4201 "vector<...>:emplace_back(args...): vector too long");
4202 }
4203
4204 size_type newCapacity = Vector_Util::computeNewCapacity(this->size() + 1,
4205 this->d_capacity,
4206 this->max_size());
4207 vector temp(this->get_allocator());
4208 temp.privateReserveEmpty(newCapacity);
4209
4210 VALUE_TYPE *pos = temp.d_dataBegin_p + this->size();
4211 AllocatorTraits::construct(
4212 this->allocatorRef(),
4213 pos,
4214 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01));
4215
4216 Vector_PushProctor<VALUE_TYPE, ALLOCATOR> guard(pos, this->allocatorRef());
4217 ArrayPrimitives::destructiveMove(temp.d_dataBegin_p,
4218 this->d_dataBegin_p,
4219 this->d_dataEnd_p,
4220 this->allocatorRef());
4221 guard.release();
4222
4223 this->d_dataEnd_p = this->d_dataBegin_p;
4224 temp.d_dataEnd_p = ++pos;
4225 Vector_Util::swap(&this->d_dataBegin_p, &temp.d_dataBegin_p);
4226}
4227#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_D >= 1
4228
4229#if BSLSTL_VECTOR_VARIADIC_LIMIT_D >= 2
4230template <class VALUE_TYPE, class ALLOCATOR>
4231template <class Args_01,
4232 class Args_02>
4233void vector<VALUE_TYPE, ALLOCATOR>::privateEmplaceBackWithAllocation(
4234 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
4235 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02)
4236{
4237 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(max_size() == this->size())) {
4239 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4240 "vector<...>:emplace_back(args...): vector too long");
4241 }
4242
4243 size_type newCapacity = Vector_Util::computeNewCapacity(this->size() + 1,
4244 this->d_capacity,
4245 this->max_size());
4246 vector temp(this->get_allocator());
4247 temp.privateReserveEmpty(newCapacity);
4248
4249 VALUE_TYPE *pos = temp.d_dataBegin_p + this->size();
4250 AllocatorTraits::construct(
4251 this->allocatorRef(),
4252 pos,
4253 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
4254 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02));
4255
4256 Vector_PushProctor<VALUE_TYPE, ALLOCATOR> guard(pos, this->allocatorRef());
4257 ArrayPrimitives::destructiveMove(temp.d_dataBegin_p,
4258 this->d_dataBegin_p,
4259 this->d_dataEnd_p,
4260 this->allocatorRef());
4261 guard.release();
4262
4263 this->d_dataEnd_p = this->d_dataBegin_p;
4264 temp.d_dataEnd_p = ++pos;
4265 Vector_Util::swap(&this->d_dataBegin_p, &temp.d_dataBegin_p);
4266}
4267#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_D >= 2
4268
4269#if BSLSTL_VECTOR_VARIADIC_LIMIT_D >= 3
4270template <class VALUE_TYPE, class ALLOCATOR>
4271template <class Args_01,
4272 class Args_02,
4273 class Args_03>
4274void vector<VALUE_TYPE, ALLOCATOR>::privateEmplaceBackWithAllocation(
4275 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
4276 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
4277 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03)
4278{
4279 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(max_size() == this->size())) {
4281 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4282 "vector<...>:emplace_back(args...): vector too long");
4283 }
4284
4285 size_type newCapacity = Vector_Util::computeNewCapacity(this->size() + 1,
4286 this->d_capacity,
4287 this->max_size());
4288 vector temp(this->get_allocator());
4289 temp.privateReserveEmpty(newCapacity);
4290
4291 VALUE_TYPE *pos = temp.d_dataBegin_p + this->size();
4292 AllocatorTraits::construct(
4293 this->allocatorRef(),
4294 pos,
4295 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
4296 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
4297 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03));
4298
4299 Vector_PushProctor<VALUE_TYPE, ALLOCATOR> guard(pos, this->allocatorRef());
4300 ArrayPrimitives::destructiveMove(temp.d_dataBegin_p,
4301 this->d_dataBegin_p,
4302 this->d_dataEnd_p,
4303 this->allocatorRef());
4304 guard.release();
4305
4306 this->d_dataEnd_p = this->d_dataBegin_p;
4307 temp.d_dataEnd_p = ++pos;
4308 Vector_Util::swap(&this->d_dataBegin_p, &temp.d_dataBegin_p);
4309}
4310#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_D >= 3
4311
4312#if BSLSTL_VECTOR_VARIADIC_LIMIT_D >= 4
4313template <class VALUE_TYPE, class ALLOCATOR>
4314template <class Args_01,
4315 class Args_02,
4316 class Args_03,
4317 class Args_04>
4318void vector<VALUE_TYPE, ALLOCATOR>::privateEmplaceBackWithAllocation(
4319 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
4320 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
4321 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
4322 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04)
4323{
4324 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(max_size() == this->size())) {
4326 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4327 "vector<...>:emplace_back(args...): vector too long");
4328 }
4329
4330 size_type newCapacity = Vector_Util::computeNewCapacity(this->size() + 1,
4331 this->d_capacity,
4332 this->max_size());
4333 vector temp(this->get_allocator());
4334 temp.privateReserveEmpty(newCapacity);
4335
4336 VALUE_TYPE *pos = temp.d_dataBegin_p + this->size();
4337 AllocatorTraits::construct(
4338 this->allocatorRef(),
4339 pos,
4340 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
4341 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
4342 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
4343 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04));
4344
4345 Vector_PushProctor<VALUE_TYPE, ALLOCATOR> guard(pos, this->allocatorRef());
4346 ArrayPrimitives::destructiveMove(temp.d_dataBegin_p,
4347 this->d_dataBegin_p,
4348 this->d_dataEnd_p,
4349 this->allocatorRef());
4350 guard.release();
4351
4352 this->d_dataEnd_p = this->d_dataBegin_p;
4353 temp.d_dataEnd_p = ++pos;
4354 Vector_Util::swap(&this->d_dataBegin_p, &temp.d_dataBegin_p);
4355}
4356#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_D >= 4
4357
4358#if BSLSTL_VECTOR_VARIADIC_LIMIT_D >= 5
4359template <class VALUE_TYPE, class ALLOCATOR>
4360template <class Args_01,
4361 class Args_02,
4362 class Args_03,
4363 class Args_04,
4364 class Args_05>
4365void vector<VALUE_TYPE, ALLOCATOR>::privateEmplaceBackWithAllocation(
4366 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
4367 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
4368 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
4369 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
4370 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05)
4371{
4372 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(max_size() == this->size())) {
4374 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4375 "vector<...>:emplace_back(args...): vector too long");
4376 }
4377
4378 size_type newCapacity = Vector_Util::computeNewCapacity(this->size() + 1,
4379 this->d_capacity,
4380 this->max_size());
4381 vector temp(this->get_allocator());
4382 temp.privateReserveEmpty(newCapacity);
4383
4384 VALUE_TYPE *pos = temp.d_dataBegin_p + this->size();
4385 AllocatorTraits::construct(
4386 this->allocatorRef(),
4387 pos,
4388 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
4389 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
4390 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
4391 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
4392 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05));
4393
4394 Vector_PushProctor<VALUE_TYPE, ALLOCATOR> guard(pos, this->allocatorRef());
4395 ArrayPrimitives::destructiveMove(temp.d_dataBegin_p,
4396 this->d_dataBegin_p,
4397 this->d_dataEnd_p,
4398 this->allocatorRef());
4399 guard.release();
4400
4401 this->d_dataEnd_p = this->d_dataBegin_p;
4402 temp.d_dataEnd_p = ++pos;
4403 Vector_Util::swap(&this->d_dataBegin_p, &temp.d_dataBegin_p);
4404}
4405#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_D >= 5
4406
4407#if BSLSTL_VECTOR_VARIADIC_LIMIT_D >= 6
4408template <class VALUE_TYPE, class ALLOCATOR>
4409template <class Args_01,
4410 class Args_02,
4411 class Args_03,
4412 class Args_04,
4413 class Args_05,
4414 class Args_06>
4415void vector<VALUE_TYPE, ALLOCATOR>::privateEmplaceBackWithAllocation(
4416 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
4417 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
4418 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
4419 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
4420 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
4421 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06)
4422{
4423 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(max_size() == this->size())) {
4425 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4426 "vector<...>:emplace_back(args...): vector too long");
4427 }
4428
4429 size_type newCapacity = Vector_Util::computeNewCapacity(this->size() + 1,
4430 this->d_capacity,
4431 this->max_size());
4432 vector temp(this->get_allocator());
4433 temp.privateReserveEmpty(newCapacity);
4434
4435 VALUE_TYPE *pos = temp.d_dataBegin_p + this->size();
4436 AllocatorTraits::construct(
4437 this->allocatorRef(),
4438 pos,
4439 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
4440 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
4441 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
4442 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
4443 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05),
4444 BSLS_COMPILERFEATURES_FORWARD(Args_06, arguments_06));
4445
4446 Vector_PushProctor<VALUE_TYPE, ALLOCATOR> guard(pos, this->allocatorRef());
4447 ArrayPrimitives::destructiveMove(temp.d_dataBegin_p,
4448 this->d_dataBegin_p,
4449 this->d_dataEnd_p,
4450 this->allocatorRef());
4451 guard.release();
4452
4453 this->d_dataEnd_p = this->d_dataBegin_p;
4454 temp.d_dataEnd_p = ++pos;
4455 Vector_Util::swap(&this->d_dataBegin_p, &temp.d_dataBegin_p);
4456}
4457#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_D >= 6
4458
4459#if BSLSTL_VECTOR_VARIADIC_LIMIT_D >= 7
4460template <class VALUE_TYPE, class ALLOCATOR>
4461template <class Args_01,
4462 class Args_02,
4463 class Args_03,
4464 class Args_04,
4465 class Args_05,
4466 class Args_06,
4467 class Args_07>
4468void vector<VALUE_TYPE, ALLOCATOR>::privateEmplaceBackWithAllocation(
4469 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
4470 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
4471 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
4472 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
4473 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
4474 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06,
4475 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) arguments_07)
4476{
4477 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(max_size() == this->size())) {
4479 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4480 "vector<...>:emplace_back(args...): vector too long");
4481 }
4482
4483 size_type newCapacity = Vector_Util::computeNewCapacity(this->size() + 1,
4484 this->d_capacity,
4485 this->max_size());
4486 vector temp(this->get_allocator());
4487 temp.privateReserveEmpty(newCapacity);
4488
4489 VALUE_TYPE *pos = temp.d_dataBegin_p + this->size();
4490 AllocatorTraits::construct(
4491 this->allocatorRef(),
4492 pos,
4493 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
4494 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
4495 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
4496 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
4497 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05),
4498 BSLS_COMPILERFEATURES_FORWARD(Args_06, arguments_06),
4499 BSLS_COMPILERFEATURES_FORWARD(Args_07, arguments_07));
4500
4501 Vector_PushProctor<VALUE_TYPE, ALLOCATOR> guard(pos, this->allocatorRef());
4502 ArrayPrimitives::destructiveMove(temp.d_dataBegin_p,
4503 this->d_dataBegin_p,
4504 this->d_dataEnd_p,
4505 this->allocatorRef());
4506 guard.release();
4507
4508 this->d_dataEnd_p = this->d_dataBegin_p;
4509 temp.d_dataEnd_p = ++pos;
4510 Vector_Util::swap(&this->d_dataBegin_p, &temp.d_dataBegin_p);
4511}
4512#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_D >= 7
4513
4514#if BSLSTL_VECTOR_VARIADIC_LIMIT_D >= 8
4515template <class VALUE_TYPE, class ALLOCATOR>
4516template <class Args_01,
4517 class Args_02,
4518 class Args_03,
4519 class Args_04,
4520 class Args_05,
4521 class Args_06,
4522 class Args_07,
4523 class Args_08>
4524void vector<VALUE_TYPE, ALLOCATOR>::privateEmplaceBackWithAllocation(
4525 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
4526 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
4527 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
4528 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
4529 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
4530 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06,
4531 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) arguments_07,
4532 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) arguments_08)
4533{
4534 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(max_size() == this->size())) {
4536 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4537 "vector<...>:emplace_back(args...): vector too long");
4538 }
4539
4540 size_type newCapacity = Vector_Util::computeNewCapacity(this->size() + 1,
4541 this->d_capacity,
4542 this->max_size());
4543 vector temp(this->get_allocator());
4544 temp.privateReserveEmpty(newCapacity);
4545
4546 VALUE_TYPE *pos = temp.d_dataBegin_p + this->size();
4547 AllocatorTraits::construct(
4548 this->allocatorRef(),
4549 pos,
4550 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
4551 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
4552 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
4553 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
4554 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05),
4555 BSLS_COMPILERFEATURES_FORWARD(Args_06, arguments_06),
4556 BSLS_COMPILERFEATURES_FORWARD(Args_07, arguments_07),
4557 BSLS_COMPILERFEATURES_FORWARD(Args_08, arguments_08));
4558
4559 Vector_PushProctor<VALUE_TYPE, ALLOCATOR> guard(pos, this->allocatorRef());
4560 ArrayPrimitives::destructiveMove(temp.d_dataBegin_p,
4561 this->d_dataBegin_p,
4562 this->d_dataEnd_p,
4563 this->allocatorRef());
4564 guard.release();
4565
4566 this->d_dataEnd_p = this->d_dataBegin_p;
4567 temp.d_dataEnd_p = ++pos;
4568 Vector_Util::swap(&this->d_dataBegin_p, &temp.d_dataBegin_p);
4569}
4570#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_D >= 8
4571
4572#if BSLSTL_VECTOR_VARIADIC_LIMIT_D >= 9
4573template <class VALUE_TYPE, class ALLOCATOR>
4574template <class Args_01,
4575 class Args_02,
4576 class Args_03,
4577 class Args_04,
4578 class Args_05,
4579 class Args_06,
4580 class Args_07,
4581 class Args_08,
4582 class Args_09>
4583void vector<VALUE_TYPE, ALLOCATOR>::privateEmplaceBackWithAllocation(
4584 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
4585 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
4586 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
4587 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
4588 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
4589 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06,
4590 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) arguments_07,
4591 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) arguments_08,
4592 BSLS_COMPILERFEATURES_FORWARD_REF(Args_09) arguments_09)
4593{
4594 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(max_size() == this->size())) {
4596 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4597 "vector<...>:emplace_back(args...): vector too long");
4598 }
4599
4600 size_type newCapacity = Vector_Util::computeNewCapacity(this->size() + 1,
4601 this->d_capacity,
4602 this->max_size());
4603 vector temp(this->get_allocator());
4604 temp.privateReserveEmpty(newCapacity);
4605
4606 VALUE_TYPE *pos = temp.d_dataBegin_p + this->size();
4607 AllocatorTraits::construct(
4608 this->allocatorRef(),
4609 pos,
4610 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
4611 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
4612 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
4613 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
4614 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05),
4615 BSLS_COMPILERFEATURES_FORWARD(Args_06, arguments_06),
4616 BSLS_COMPILERFEATURES_FORWARD(Args_07, arguments_07),
4617 BSLS_COMPILERFEATURES_FORWARD(Args_08, arguments_08),
4618 BSLS_COMPILERFEATURES_FORWARD(Args_09, arguments_09));
4619
4620 Vector_PushProctor<VALUE_TYPE, ALLOCATOR> guard(pos, this->allocatorRef());
4621 ArrayPrimitives::destructiveMove(temp.d_dataBegin_p,
4622 this->d_dataBegin_p,
4623 this->d_dataEnd_p,
4624 this->allocatorRef());
4625 guard.release();
4626
4627 this->d_dataEnd_p = this->d_dataBegin_p;
4628 temp.d_dataEnd_p = ++pos;
4629 Vector_Util::swap(&this->d_dataBegin_p, &temp.d_dataBegin_p);
4630}
4631#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_D >= 9
4632
4633#if BSLSTL_VECTOR_VARIADIC_LIMIT_D >= 10
4634template <class VALUE_TYPE, class ALLOCATOR>
4635template <class Args_01,
4636 class Args_02,
4637 class Args_03,
4638 class Args_04,
4639 class Args_05,
4640 class Args_06,
4641 class Args_07,
4642 class Args_08,
4643 class Args_09,
4644 class Args_10>
4645void vector<VALUE_TYPE, ALLOCATOR>::privateEmplaceBackWithAllocation(
4646 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
4647 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
4648 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
4649 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
4650 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
4651 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06,
4652 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) arguments_07,
4653 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) arguments_08,
4654 BSLS_COMPILERFEATURES_FORWARD_REF(Args_09) arguments_09,
4655 BSLS_COMPILERFEATURES_FORWARD_REF(Args_10) arguments_10)
4656{
4657 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(max_size() == this->size())) {
4659 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4660 "vector<...>:emplace_back(args...): vector too long");
4661 }
4662
4663 size_type newCapacity = Vector_Util::computeNewCapacity(this->size() + 1,
4664 this->d_capacity,
4665 this->max_size());
4666 vector temp(this->get_allocator());
4667 temp.privateReserveEmpty(newCapacity);
4668
4669 VALUE_TYPE *pos = temp.d_dataBegin_p + this->size();
4670 AllocatorTraits::construct(
4671 this->allocatorRef(),
4672 pos,
4673 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
4674 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
4675 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
4676 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
4677 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05),
4678 BSLS_COMPILERFEATURES_FORWARD(Args_06, arguments_06),
4679 BSLS_COMPILERFEATURES_FORWARD(Args_07, arguments_07),
4680 BSLS_COMPILERFEATURES_FORWARD(Args_08, arguments_08),
4681 BSLS_COMPILERFEATURES_FORWARD(Args_09, arguments_09),
4682 BSLS_COMPILERFEATURES_FORWARD(Args_10, arguments_10));
4683
4684 Vector_PushProctor<VALUE_TYPE, ALLOCATOR> guard(pos, this->allocatorRef());
4685 ArrayPrimitives::destructiveMove(temp.d_dataBegin_p,
4686 this->d_dataBegin_p,
4687 this->d_dataEnd_p,
4688 this->allocatorRef());
4689 guard.release();
4690
4691 this->d_dataEnd_p = this->d_dataBegin_p;
4692 temp.d_dataEnd_p = ++pos;
4693 Vector_Util::swap(&this->d_dataBegin_p, &temp.d_dataBegin_p);
4694}
4695#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_D >= 10
4696
4697#else
4698// The generated code below is a workaround for the absence of perfect
4699// forwarding in some compilers.
4700template <class VALUE_TYPE, class ALLOCATOR>
4701template <class... Args>
4702void vector<VALUE_TYPE, ALLOCATOR>::privateEmplaceBackWithAllocation(
4703 BSLS_COMPILERFEATURES_FORWARD_REF(Args)...arguments)
4704{
4705 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(max_size() == this->size())) {
4707 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4708 "vector<...>:emplace_back(args...): vector too long");
4709 }
4710
4711 size_type newCapacity = Vector_Util::computeNewCapacity(this->size() + 1,
4712 this->d_capacity,
4713 this->max_size());
4714 vector temp(this->get_allocator());
4715 temp.privateReserveEmpty(newCapacity);
4716
4717 VALUE_TYPE *pos = temp.d_dataBegin_p + this->size();
4718 AllocatorTraits::construct(
4719 this->allocatorRef(),
4720 pos,
4721 BSLS_COMPILERFEATURES_FORWARD(Args, arguments)...);
4722
4723 Vector_PushProctor<VALUE_TYPE, ALLOCATOR> guard(pos, this->allocatorRef());
4724 ArrayPrimitives::destructiveMove(temp.d_dataBegin_p,
4725 this->d_dataBegin_p,
4726 this->d_dataEnd_p,
4727 this->allocatorRef());
4728 guard.release();
4729
4730 this->d_dataEnd_p = this->d_dataBegin_p;
4731 temp.d_dataEnd_p = ++pos;
4732 Vector_Util::swap(&this->d_dataBegin_p, &temp.d_dataBegin_p);
4733}
4734// }}} END GENERATED CODE
4735#endif
4736
4737template <class VALUE_TYPE, class ALLOCATOR>
4738void vector<VALUE_TYPE, ALLOCATOR>::privatePushBackWithAllocation(
4739 const VALUE_TYPE& value)
4740{
4741 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(max_size() == this->size())) {
4743 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4744 "vector<...>:push_back(lvalue): vector too long");
4745 }
4746
4747 size_type newCapacity = Vector_Util::computeNewCapacity(this->size() + 1,
4748 this->d_capacity,
4749 this->max_size());
4750
4751 vector temp(this->get_allocator());
4752 temp.privateReserveEmpty(newCapacity);
4753
4754 // Construct before we risk invalidating the reference
4755 VALUE_TYPE *pos = temp.d_dataBegin_p + this->size();
4756 AllocatorTraits::construct(this->allocatorRef(), pos, value);
4757
4758 // Nothing else should throw, but probably worth guarding the above
4759 // 'construct' call for types with potentially-throwing destructive moves.
4760 Vector_PushProctor<VALUE_TYPE, ALLOCATOR> guard(pos, this->allocatorRef());
4761 ArrayPrimitives::destructiveMove(temp.d_dataBegin_p,
4762 this->d_dataBegin_p,
4763 this->d_dataEnd_p,
4764 this->allocatorRef());
4765 guard.release(); // Nothing after this can throw
4766
4767 this->d_dataEnd_p = this->d_dataBegin_p;
4768 temp.d_dataEnd_p = ++pos;
4769 Vector_Util::swap(&this->d_dataBegin_p, &temp.d_dataBegin_p);
4770}
4771
4772template <class VALUE_TYPE, class ALLOCATOR>
4773void vector<VALUE_TYPE, ALLOCATOR>::privatePushBackWithAllocation(
4774 BloombergLP::bslmf::MovableRef<VALUE_TYPE> value)
4775{
4776 VALUE_TYPE& lvalue = value;
4777 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(max_size() == this->size())) {
4779 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4780 "vector<...>:push_back(rvalue): vector too long");
4781 }
4782
4783 size_type newCapacity = Vector_Util::computeNewCapacity(this->size() + 1,
4784 this->d_capacity,
4785 this->max_size());
4786
4787 vector temp(this->get_allocator());
4788 temp.privateReserveEmpty(newCapacity);
4789
4790 // Construct before we risk invalidating the reference
4791 VALUE_TYPE *pos = temp.d_dataBegin_p + this->size();
4792 AllocatorTraits::construct(this->allocatorRef(),
4793 pos,
4794 MoveUtil::move(lvalue));
4795
4796 // Nothing else should throw, but probably worth guarding the above
4797 // 'construct' call for types with potentially-throwing destructive moves.
4798 Vector_PushProctor<VALUE_TYPE, ALLOCATOR> guard(pos, this->allocatorRef());
4799 ArrayPrimitives::destructiveMove(temp.d_dataBegin_p,
4800 this->d_dataBegin_p,
4801 this->d_dataEnd_p,
4802 this->allocatorRef());
4803 guard.release(); // Nothing after this can throw
4804
4805 this->d_dataEnd_p = this->d_dataBegin_p;
4806 temp.d_dataEnd_p = ++pos;
4807 Vector_Util::swap(&this->d_dataBegin_p, &temp.d_dataBegin_p);
4808}
4809
4810// CREATORS
4811
4812 // *** construct/copy/destroy ***
4813
4814template <class VALUE_TYPE, class ALLOCATOR>
4815inline
4816vector<VALUE_TYPE, ALLOCATOR>::vector() BSLS_KEYWORD_NOEXCEPT
4817: vectorBase<VALUE_TYPE>()
4818, ContainerBase(ALLOCATOR())
4819{
4820}
4821
4822template <class VALUE_TYPE, class ALLOCATOR>
4823inline
4824vector<VALUE_TYPE, ALLOCATOR>::vector(const ALLOCATOR& basicAllocator)
4826: vectorBase<VALUE_TYPE>()
4827, ContainerBase(basicAllocator)
4828{
4829}
4830
4831template <class VALUE_TYPE, class ALLOCATOR>
4832vector<VALUE_TYPE, ALLOCATOR>::vector(size_type initialSize,
4833 const ALLOCATOR& basicAllocator)
4834: vectorBase<VALUE_TYPE>()
4835, ContainerBase(basicAllocator)
4836{
4837 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(initialSize > max_size())) {
4839 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4840 "vector<...>::vector(n,v): vector too long");
4841 }
4842 if (initialSize > 0) {
4843 privateReserveEmpty(initialSize);
4844 Proctor proctor(this->d_dataBegin_p,
4845 this->d_capacity,
4846 static_cast<ContainerBase *>(this));
4847
4848 ArrayPrimitives::defaultConstruct(this->d_dataBegin_p,
4849 initialSize,
4850 this->allocatorRef());
4851
4852 proctor.release();
4853 this->d_dataEnd_p += initialSize;
4854 }
4855}
4856
4857template <class VALUE_TYPE, class ALLOCATOR>
4858vector<VALUE_TYPE, ALLOCATOR>::vector(size_type initialSize,
4859 const VALUE_TYPE& value,
4860 const ALLOCATOR& basicAllocator)
4861: vectorBase<VALUE_TYPE>()
4862, ContainerBase(basicAllocator)
4863{
4864 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(initialSize > max_size())) {
4866 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4867 "vector<...>::vector(n,v): vector too long");
4868 }
4869 if (initialSize > 0) {
4870 privateReserveEmpty(initialSize);
4871 Proctor proctor(this->d_dataBegin_p,
4872 this->d_capacity,
4873 static_cast<ContainerBase *>(this));
4874
4875 ArrayPrimitives::uninitializedFillN(this->d_dataBegin_p,
4876 initialSize,
4877 value,
4878 this->allocatorRef());
4879
4880 proctor.release();
4881 this->d_dataEnd_p += initialSize;
4882 }
4883}
4884
4885template <class VALUE_TYPE, class ALLOCATOR>
4886template <class INPUT_ITER>
4888vector<VALUE_TYPE, ALLOCATOR>::vector(INPUT_ITER first,
4889 INPUT_ITER last,
4890 const ALLOCATOR& basicAllocator)
4891: vectorBase<VALUE_TYPE>()
4892, ContainerBase(basicAllocator)
4893{
4894 BSLS_ASSERT_SAFE(!Vector_RangeCheck::isInvalidRange(first, last));
4895
4896 typedef typename Vector_RangeIteratorCategory<INPUT_ITER, INPUT_ITER>::type
4897 Tag;
4898
4899 if (is_same<Tag, BloombergLP::bslmf::Nil>::value || first != last) {
4900 // Range-check avoids allocating on an empty sequence.
4901 constructFromRange(first, last, Tag());
4902 }
4903}
4904
4905template <class VALUE_TYPE, class ALLOCATOR>
4906vector<VALUE_TYPE, ALLOCATOR>::vector(const vector& original)
4907: vectorBase<VALUE_TYPE>()
4908, ContainerBase(AllocatorTraits::select_on_container_copy_construction(
4909 original.get_allocator()))
4910{
4911 if (original.size() > 0) {
4912 privateReserveEmpty(original.size());
4913 Proctor proctor(this->d_dataBegin_p,
4914 this->d_capacity,
4915 static_cast<ContainerBase *>(this));
4916
4917 ArrayPrimitives::copyConstruct(this->d_dataBegin_p,
4918 original.begin(),
4919 original.end(),
4920 this->allocatorRef());
4921
4922 proctor.release();
4923 this->d_dataEnd_p += original.size();
4924 }
4925}
4926
4927template <class VALUE_TYPE, class ALLOCATOR>
4928vector<VALUE_TYPE, ALLOCATOR>::
4929vector(const vector& original,
4930 const typename type_identity<ALLOCATOR>::type& basicAllocator)
4931: vectorBase<VALUE_TYPE>()
4932, ContainerBase(basicAllocator)
4933{
4934 if (original.size() > 0) {
4935 privateReserveEmpty(original.size());
4936 Proctor proctor(this->d_dataBegin_p,
4937 this->d_capacity,
4938 static_cast<ContainerBase *>(this));
4939
4940 ArrayPrimitives::copyConstruct(this->d_dataBegin_p,
4941 original.begin(),
4942 original.end(),
4943 this->allocatorRef());
4944
4945 proctor.release();
4946 this->d_dataEnd_p += original.size();
4947 }
4948}
4949
4950template <class VALUE_TYPE, class ALLOCATOR>
4951vector<VALUE_TYPE, ALLOCATOR>::vector(
4952 BloombergLP::bslmf::MovableRef<vector> original)
4954: vectorBase<VALUE_TYPE>()
4955, ContainerBase(MoveUtil::access(original).get_allocator())
4956{
4957 vector& lvalue = original;
4958 ImpBase::adopt(MoveUtil::move(static_cast<ImpBase&>(lvalue)));
4959}
4960
4961template <class VALUE_TYPE, class ALLOCATOR>
4962vector<VALUE_TYPE, ALLOCATOR>::vector(
4963 BloombergLP::bslmf::MovableRef<vector> original,
4964 const typename type_identity<ALLOCATOR>::type& basicAllocator)
4965: vectorBase<VALUE_TYPE>()
4966, ContainerBase(basicAllocator)
4967{
4968 vector& lvalue = original;
4969
4970 if (BSLS_PERFORMANCEHINT_PREDICT_LIKELY(get_allocator() ==
4971 lvalue.get_allocator())) {
4972 ImpBase::adopt(MoveUtil::move(static_cast<ImpBase&>(lvalue)));
4973 }
4974 else {
4975 if (lvalue.size() > 0) {
4976 privateReserveEmpty(lvalue.size());
4977 Proctor proctor(this->d_dataBegin_p,
4978 this->d_capacity,
4979 static_cast<ContainerBase *>(this));
4980
4981 ArrayPrimitives::moveConstruct(this->d_dataBegin_p,
4982 lvalue.begin(),
4983 lvalue.end(),
4984 this->allocatorRef());
4985
4986 proctor.release();
4987 this->d_dataEnd_p += lvalue.size();
4988 }
4989 }
4990}
4991
4992#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
4993template <class VALUE_TYPE, class ALLOCATOR>
4994inline
4995vector<VALUE_TYPE, ALLOCATOR>::vector(
4996 std::initializer_list<VALUE_TYPE> values,
4997 const ALLOCATOR& basicAllocator)
4998: vectorBase<VALUE_TYPE>()
4999, ContainerBase(basicAllocator)
5000{
5001 if (values.begin() != values.end()) {
5002 constructFromRange(values.begin(),
5003 values.end(),
5004 std::random_access_iterator_tag());
5005 }
5006}
5007
5008#endif
5009
5010template <class VALUE_TYPE, class ALLOCATOR>
5011template <class t_RANGE>
5013inline
5014vector<VALUE_TYPE, ALLOCATOR>::vector(
5015 from_range_t ,
5016 BSLS_COMPILERFEATURES_FORWARD_REF(t_RANGE) range,
5017 const ALLOCATOR& basicAllocator)
5018: vectorBase<VALUE_TYPE>()
5019, ContainerBase(basicAllocator)
5020{
5021 privateConstruct(from_range,
5022 BSLS_COMPILERFEATURES_FORWARD(t_RANGE, range),
5023 ranges::begin(range));
5024}
5025
5026template <class VALUE_TYPE, class ALLOCATOR>
5028vector<VALUE_TYPE, ALLOCATOR>::~vector()
5029{
5030 using BloombergLP::bslalg::ArrayDestructionPrimitives;
5031
5032 // suppress buggy warning in GCC 12 and later (DRQS 174259807)
5033#ifdef BSLS_PLATFORM_CMP_GNU
5034#pragma GCC diagnostic push
5035#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
5036#endif
5037 if (this->d_dataBegin_p) {
5038 ArrayDestructionPrimitives::destroy(this->d_dataBegin_p,
5039 this->d_dataEnd_p,
5040 this->allocatorRef());
5041 AllocatorUtil::deallocateObject(this->allocatorRef(),
5042 this->d_dataBegin_p, this->d_capacity);
5043 }
5044#ifdef BSLS_PLATFORM_CMP_GNU
5045#pragma GCC diagnostic pop
5046#endif
5047}
5048
5049// MANIPULATORS
5050template <class VALUE_TYPE, class ALLOCATOR>
5051vector<VALUE_TYPE, ALLOCATOR>&
5052vector<VALUE_TYPE, ALLOCATOR>::operator=(const vector& rhs)
5053{
5054 typedef typename
5055 AllocatorTraits::propagate_on_container_copy_assignment Propagate;
5056
5057 if (BSLS_PERFORMANCEHINT_PREDICT_LIKELY(this != &rhs)) {
5058 if (Propagate::value) {
5059 vector other(rhs, rhs.get_allocator());
5060 Vector_Util::swap(&this->d_dataBegin_p, &other.d_dataBegin_p);
5061 AllocatorUtil::swap(&this->allocatorRef(),
5062 &other.allocatorRef(),
5063 Propagate());
5064 }
5065 else {
5066 clear();
5067 insert(this->begin(), rhs.begin(), rhs.end());
5068 }
5069 }
5070 return *this;
5071}
5072
5073template <class VALUE_TYPE, class ALLOCATOR>
5074vector<VALUE_TYPE, ALLOCATOR>& vector<VALUE_TYPE, ALLOCATOR>::operator=(
5075 BloombergLP::bslmf::MovableRef<vector<VALUE_TYPE, ALLOCATOR> > rhs)
5077 AllocatorTraits::propagate_on_container_move_assignment::value ||
5078 AllocatorTraits::is_always_equal::value)
5079{
5080 typedef typename
5081 AllocatorTraits::propagate_on_container_move_assignment Propagate;
5082
5083 vector& lvalue = rhs;
5084 if (BSLS_PERFORMANCEHINT_PREDICT_LIKELY(this != &lvalue)) {
5085 if (get_allocator() == lvalue.get_allocator()) {
5086 vector other(MoveUtil::move(lvalue));
5087 Vector_Util::swap(&this->d_dataBegin_p, &other.d_dataBegin_p);
5088 }
5089 else if (Propagate::value) {
5090 vector other(MoveUtil::move(lvalue));
5091 AllocatorUtil::swap(&this->allocatorRef(),
5092 &other.allocatorRef(),
5093 Propagate());
5094 Vector_Util::swap(&this->d_dataBegin_p, &other.d_dataBegin_p);
5095 }
5096 else {
5097 vector other(MoveUtil::move(lvalue), this->allocatorRef());
5098 Vector_Util::swap(&this->d_dataBegin_p, &other.d_dataBegin_p);
5099 }
5100 }
5101 return *this;
5102}
5103
5104#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
5105template <class VALUE_TYPE, class ALLOCATOR>
5106inline
5107vector<VALUE_TYPE, ALLOCATOR>&
5108vector<VALUE_TYPE, ALLOCATOR>::operator=(
5109 std::initializer_list<VALUE_TYPE> values)
5110{
5111 this->assign(values.begin(), values.end());
5112 return *this;
5113}
5114
5115template <class VALUE_TYPE, class ALLOCATOR>
5116inline
5117void vector<VALUE_TYPE, ALLOCATOR>::assign(
5118 std::initializer_list<VALUE_TYPE> values)
5119{
5120 assign(values.begin(), values.end());
5121}
5122#endif
5123
5124template <class VALUE_TYPE, class ALLOCATOR>
5125template <class INPUT_ITER>
5126inline
5127void vector<VALUE_TYPE, ALLOCATOR>::assign(INPUT_ITER first, INPUT_ITER last)
5128{
5129 BSLS_ASSERT_SAFE(!Vector_RangeCheck::isInvalidRange(first, last));
5130
5131 clear();
5132 insert(this->begin(), first, last);
5133}
5134
5135template <class VALUE_TYPE, class ALLOCATOR>
5136inline
5137void vector<VALUE_TYPE, ALLOCATOR>::assign(size_type numElements,
5138 const VALUE_TYPE& value)
5139{
5140 clear();
5141 insert(this->begin(), numElements, value);
5142}
5143
5144template <class VALUE_TYPE, class ALLOCATOR>
5145template <class t_RANGE>
5147void vector<VALUE_TYPE, ALLOCATOR>::assign_range(
5148 BSLS_COMPILERFEATURES_FORWARD_REF(t_RANGE) range)
5149{
5150 clear();
5151 append_range(BSLS_COMPILERFEATURES_FORWARD(t_RANGE, range));
5152}
5153
5154 // *** capacity ***
5155
5156template <class VALUE_TYPE, class ALLOCATOR>
5157void vector<VALUE_TYPE, ALLOCATOR>::resize(size_type newSize)
5158{
5159 // This function provides the *strong* exception guarantee (except when
5160 // the move constructor of a non-copy-insertable 'value_type' throws).
5161
5162 // Cannot use copy constructor since the only requirements on 'VALUE_TYPE'
5163 // are 'move-insertable' and 'default-constructible'.
5164
5165 if (newSize <= this->size()) {
5166 BloombergLP::bslalg::ArrayDestructionPrimitives::destroy(
5167 this->d_dataBegin_p + newSize,
5168 this->d_dataEnd_p,
5169 this->allocatorRef());
5170 this->d_dataEnd_p = this->d_dataBegin_p + newSize;
5171 }
5172 else if (0 == this->d_capacity) {
5173 // Because of {DRQS 99966534}, we check for zero capacity here and
5174 // handle it separately rather than falling into the case below.
5175 vector temp(newSize, this->get_allocator());
5176 Vector_Util::swap(&this->d_dataBegin_p, &temp.d_dataBegin_p);
5177 }
5178 else if (newSize > this->d_capacity) {
5179 const size_type maxSize = max_size();
5180 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(newSize > maxSize)) {
5182 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
5183 "vector<...>::resize(n): vector too long");
5184 }
5185
5186 size_type newCapacity = Vector_Util::computeNewCapacity(
5187 newSize, this->d_capacity, maxSize);
5188
5189 vector temp(this->get_allocator());
5190 temp.privateReserveEmpty(newCapacity);
5191
5192 ArrayPrimitives::destructiveMoveAndInsert(temp.d_dataBegin_p,
5193 &this->d_dataEnd_p,
5194 this->d_dataBegin_p,
5195 this->d_dataEnd_p,
5196 this->d_dataEnd_p,
5197 newSize - this->size(),
5198 this->allocatorRef());
5199
5200 temp.d_dataEnd_p += newSize;
5201 Vector_Util::swap(&this->d_dataBegin_p, &temp.d_dataBegin_p);
5202 }
5203 else {
5204 ArrayPrimitives::defaultConstruct(this->d_dataEnd_p,
5205 newSize - this->size(),
5206 this->allocatorRef());
5207 this->d_dataEnd_p = this->d_dataBegin_p + newSize;
5208 }
5209}
5210
5211template <class VALUE_TYPE, class ALLOCATOR>
5212void vector<VALUE_TYPE, ALLOCATOR>::resize(size_type newSize,
5213 const VALUE_TYPE& value)
5214{
5215 // This function provides the *strong* exception guarantee (except when
5216 // the move constructor of a non-copy-insertable 'value_type' throws).
5217
5218 if (newSize <= this->size()) {
5219 BloombergLP::bslalg::ArrayDestructionPrimitives::destroy(
5220 this->d_dataBegin_p + newSize,
5221 this->d_dataEnd_p,
5222 this->allocatorRef());
5223 this->d_dataEnd_p = this->d_dataBegin_p + newSize;
5224 }
5225 else {
5226 insert(this->d_dataEnd_p, newSize - this->size(), value);
5227 }
5228}
5229
5230template <class VALUE_TYPE, class ALLOCATOR>
5231void vector<VALUE_TYPE, ALLOCATOR>::reserve(size_type newCapacity)
5232{
5233 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(newCapacity > max_size())) {
5235 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
5236 "vector<...>::reserve(newCapacity): vector too long");
5237 }
5238 if (0 == this->d_capacity && 0 != newCapacity) {
5239 privateReserveEmpty(newCapacity);
5240 }
5241 else if (this->d_capacity < newCapacity) {
5242 vector temp(this->get_allocator());
5243 temp.privateReserveEmpty(newCapacity);
5244
5245 ArrayPrimitives::destructiveMove(temp.d_dataBegin_p,
5246 this->d_dataBegin_p,
5247 this->d_dataEnd_p,
5248 this->allocatorRef());
5249
5250 temp.d_dataEnd_p += this->size();
5251 this->d_dataEnd_p = this->d_dataBegin_p;
5252 Vector_Util::swap(&this->d_dataBegin_p, &temp.d_dataBegin_p);
5253 }
5254}
5255
5256template <class VALUE_TYPE, class ALLOCATOR>
5257void vector<VALUE_TYPE, ALLOCATOR>::shrink_to_fit()
5258{
5259 if (this->size() < this->d_capacity) {
5260 vector temp(this->get_allocator());
5261 if (this->size() > 0) {
5262 temp.privateReserveEmpty(this->size());
5263 ArrayPrimitives::destructiveMove(temp.d_dataBegin_p,
5264 this->d_dataBegin_p,
5265 this->d_dataEnd_p,
5266 this->allocatorRef());
5267
5268 temp.d_dataEnd_p += this->size();
5269 this->d_dataEnd_p = this->d_dataBegin_p;
5270 }
5271 Vector_Util::swap(&this->d_dataBegin_p, &temp.d_dataBegin_p);
5272 }
5273}
5274
5275 // *** modifiers ***
5276
5277template <class VALUE_TYPE, class ALLOCATOR>
5278template <class t_RANGE>
5280void vector<VALUE_TYPE, ALLOCATOR>::append_range(
5281 BSLS_COMPILERFEATURES_FORWARD_REF(t_RANGE) range)
5282{
5283 privateAppendRange(BSLS_COMPILERFEATURES_FORWARD(t_RANGE, range),
5284 ranges::begin(range));
5285}
5286
5287#if BSLS_COMPILERFEATURES_SIMULATE_VARIADIC_TEMPLATES
5288// {{{ BEGIN GENERATED CODE
5289// Command line: sim_cpp11_features.py bslstl_vector.h
5290#ifndef BSLSTL_VECTOR_VARIADIC_LIMIT
5291#define BSLSTL_VECTOR_VARIADIC_LIMIT 10
5292#endif
5293#ifndef BSLSTL_VECTOR_VARIADIC_LIMIT_E
5294#define BSLSTL_VECTOR_VARIADIC_LIMIT_E BSLSTL_VECTOR_VARIADIC_LIMIT
5295#endif
5296#if BSLSTL_VECTOR_VARIADIC_LIMIT_E >= 0
5297template <class VALUE_TYPE, class ALLOCATOR>
5298inline
5299VALUE_TYPE &
5300vector<VALUE_TYPE, ALLOCATOR>::emplace_back(
5301 )
5302{
5303 if (BSLS_PERFORMANCEHINT_PREDICT_LIKELY(this->d_capacity > this->size())) {
5304 AllocatorTraits::construct(
5305 this->allocatorRef(),
5306 this->d_dataEnd_p);
5307 ++this->d_dataEnd_p;
5308 }
5309 else {
5310 privateEmplaceBackWithAllocation(
5311 );
5312 }
5313 return *(this->d_dataEnd_p - 1);
5314}
5315#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_E >= 0
5316
5317#if BSLSTL_VECTOR_VARIADIC_LIMIT_E >= 1
5318template <class VALUE_TYPE, class ALLOCATOR>
5319template <class Args_01>
5320inline
5321VALUE_TYPE &
5322vector<VALUE_TYPE, ALLOCATOR>::emplace_back(
5323 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01)
5324{
5325 if (BSLS_PERFORMANCEHINT_PREDICT_LIKELY(this->d_capacity > this->size())) {
5326 AllocatorTraits::construct(
5327 this->allocatorRef(),
5328 this->d_dataEnd_p,
5329 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01));
5330 ++this->d_dataEnd_p;
5331 }
5332 else {
5333 privateEmplaceBackWithAllocation(
5334 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01));
5335 }
5336 return *(this->d_dataEnd_p - 1);
5337}
5338#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_E >= 1
5339
5340#if BSLSTL_VECTOR_VARIADIC_LIMIT_E >= 2
5341template <class VALUE_TYPE, class ALLOCATOR>
5342template <class Args_01,
5343 class Args_02>
5344inline
5345VALUE_TYPE &
5346vector<VALUE_TYPE, ALLOCATOR>::emplace_back(
5347 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
5348 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02)
5349{
5350 if (BSLS_PERFORMANCEHINT_PREDICT_LIKELY(this->d_capacity > this->size())) {
5351 AllocatorTraits::construct(
5352 this->allocatorRef(),
5353 this->d_dataEnd_p,
5354 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
5355 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02));
5356 ++this->d_dataEnd_p;
5357 }
5358 else {
5359 privateEmplaceBackWithAllocation(
5360 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
5361 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02));
5362 }
5363 return *(this->d_dataEnd_p - 1);
5364}
5365#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_E >= 2
5366
5367#if BSLSTL_VECTOR_VARIADIC_LIMIT_E >= 3
5368template <class VALUE_TYPE, class ALLOCATOR>
5369template <class Args_01,
5370 class Args_02,
5371 class Args_03>
5372inline
5373VALUE_TYPE &
5374vector<VALUE_TYPE, ALLOCATOR>::emplace_back(
5375 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
5376 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
5377 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03)
5378{
5379 if (BSLS_PERFORMANCEHINT_PREDICT_LIKELY(this->d_capacity > this->size())) {
5380 AllocatorTraits::construct(
5381 this->allocatorRef(),
5382 this->d_dataEnd_p,
5383 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
5384 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
5385 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03));
5386 ++this->d_dataEnd_p;
5387 }
5388 else {
5389 privateEmplaceBackWithAllocation(
5390 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
5391 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
5392 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03));
5393 }
5394 return *(this->d_dataEnd_p - 1);
5395}
5396#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_E >= 3
5397
5398#if BSLSTL_VECTOR_VARIADIC_LIMIT_E >= 4
5399template <class VALUE_TYPE, class ALLOCATOR>
5400template <class Args_01,
5401 class Args_02,
5402 class Args_03,
5403 class Args_04>
5404inline
5405VALUE_TYPE &
5406vector<VALUE_TYPE, ALLOCATOR>::emplace_back(
5407 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
5408 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
5409 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
5410 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04)
5411{
5412 if (BSLS_PERFORMANCEHINT_PREDICT_LIKELY(this->d_capacity > this->size())) {
5413 AllocatorTraits::construct(
5414 this->allocatorRef(),
5415 this->d_dataEnd_p,
5416 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
5417 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
5418 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
5419 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04));
5420 ++this->d_dataEnd_p;
5421 }
5422 else {
5423 privateEmplaceBackWithAllocation(
5424 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
5425 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
5426 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
5427 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04));
5428 }
5429 return *(this->d_dataEnd_p - 1);
5430}
5431#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_E >= 4
5432
5433#if BSLSTL_VECTOR_VARIADIC_LIMIT_E >= 5
5434template <class VALUE_TYPE, class ALLOCATOR>
5435template <class Args_01,
5436 class Args_02,
5437 class Args_03,
5438 class Args_04,
5439 class Args_05>
5440inline
5441VALUE_TYPE &
5442vector<VALUE_TYPE, ALLOCATOR>::emplace_back(
5443 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
5444 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
5445 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
5446 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
5447 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05)
5448{
5449 if (BSLS_PERFORMANCEHINT_PREDICT_LIKELY(this->d_capacity > this->size())) {
5450 AllocatorTraits::construct(
5451 this->allocatorRef(),
5452 this->d_dataEnd_p,
5453 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
5454 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
5455 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
5456 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
5457 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05));
5458 ++this->d_dataEnd_p;
5459 }
5460 else {
5461 privateEmplaceBackWithAllocation(
5462 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
5463 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
5464 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
5465 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
5466 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05));
5467 }
5468 return *(this->d_dataEnd_p - 1);
5469}
5470#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_E >= 5
5471
5472#if BSLSTL_VECTOR_VARIADIC_LIMIT_E >= 6
5473template <class VALUE_TYPE, class ALLOCATOR>
5474template <class Args_01,
5475 class Args_02,
5476 class Args_03,
5477 class Args_04,
5478 class Args_05,
5479 class Args_06>
5480inline
5481VALUE_TYPE &
5482vector<VALUE_TYPE, ALLOCATOR>::emplace_back(
5483 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
5484 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
5485 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
5486 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
5487 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
5488 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06)
5489{
5490 if (BSLS_PERFORMANCEHINT_PREDICT_LIKELY(this->d_capacity > this->size())) {
5491 AllocatorTraits::construct(
5492 this->allocatorRef(),
5493 this->d_dataEnd_p,
5494 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
5495 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
5496 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
5497 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
5498 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05),
5499 BSLS_COMPILERFEATURES_FORWARD(Args_06, arguments_06));
5500 ++this->d_dataEnd_p;
5501 }
5502 else {
5503 privateEmplaceBackWithAllocation(
5504 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
5505 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
5506 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
5507 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
5508 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05),
5509 BSLS_COMPILERFEATURES_FORWARD(Args_06, arguments_06));
5510 }
5511 return *(this->d_dataEnd_p - 1);
5512}
5513#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_E >= 6
5514
5515#if BSLSTL_VECTOR_VARIADIC_LIMIT_E >= 7
5516template <class VALUE_TYPE, class ALLOCATOR>
5517template <class Args_01,
5518 class Args_02,
5519 class Args_03,
5520 class Args_04,
5521 class Args_05,
5522 class Args_06,
5523 class Args_07>
5524inline
5525VALUE_TYPE &
5526vector<VALUE_TYPE, ALLOCATOR>::emplace_back(
5527 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
5528 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
5529 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
5530 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
5531 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
5532 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06,
5533 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) arguments_07)
5534{
5535 if (BSLS_PERFORMANCEHINT_PREDICT_LIKELY(this->d_capacity > this->size())) {
5536 AllocatorTraits::construct(
5537 this->allocatorRef(),
5538 this->d_dataEnd_p,
5539 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
5540 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
5541 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
5542 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
5543 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05),
5544 BSLS_COMPILERFEATURES_FORWARD(Args_06, arguments_06),
5545 BSLS_COMPILERFEATURES_FORWARD(Args_07, arguments_07));
5546 ++this->d_dataEnd_p;
5547 }
5548 else {
5549 privateEmplaceBackWithAllocation(
5550 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
5551 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
5552 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
5553 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
5554 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05),
5555 BSLS_COMPILERFEATURES_FORWARD(Args_06, arguments_06),
5556 BSLS_COMPILERFEATURES_FORWARD(Args_07, arguments_07));
5557 }
5558 return *(this->d_dataEnd_p - 1);
5559}
5560#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_E >= 7
5561
5562#if BSLSTL_VECTOR_VARIADIC_LIMIT_E >= 8
5563template <class VALUE_TYPE, class ALLOCATOR>
5564template <class Args_01,
5565 class Args_02,
5566 class Args_03,
5567 class Args_04,
5568 class Args_05,
5569 class Args_06,
5570 class Args_07,
5571 class Args_08>
5572inline
5573VALUE_TYPE &
5574vector<VALUE_TYPE, ALLOCATOR>::emplace_back(
5575 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
5576 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
5577 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
5578 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
5579 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
5580 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06,
5581 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) arguments_07,
5582 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) arguments_08)
5583{
5584 if (BSLS_PERFORMANCEHINT_PREDICT_LIKELY(this->d_capacity > this->size())) {
5585 AllocatorTraits::construct(
5586 this->allocatorRef(),
5587 this->d_dataEnd_p,
5588 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
5589 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
5590 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
5591 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
5592 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05),
5593 BSLS_COMPILERFEATURES_FORWARD(Args_06, arguments_06),
5594 BSLS_COMPILERFEATURES_FORWARD(Args_07, arguments_07),
5595 BSLS_COMPILERFEATURES_FORWARD(Args_08, arguments_08));
5596 ++this->d_dataEnd_p;
5597 }
5598 else {
5599 privateEmplaceBackWithAllocation(
5600 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
5601 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
5602 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
5603 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
5604 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05),
5605 BSLS_COMPILERFEATURES_FORWARD(Args_06, arguments_06),
5606 BSLS_COMPILERFEATURES_FORWARD(Args_07, arguments_07),
5607 BSLS_COMPILERFEATURES_FORWARD(Args_08, arguments_08));
5608 }
5609 return *(this->d_dataEnd_p - 1);
5610}
5611#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_E >= 8
5612
5613#if BSLSTL_VECTOR_VARIADIC_LIMIT_E >= 9
5614template <class VALUE_TYPE, class ALLOCATOR>
5615template <class Args_01,
5616 class Args_02,
5617 class Args_03,
5618 class Args_04,
5619 class Args_05,
5620 class Args_06,
5621 class Args_07,
5622 class Args_08,
5623 class Args_09>
5624inline
5625VALUE_TYPE &
5626vector<VALUE_TYPE, ALLOCATOR>::emplace_back(
5627 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
5628 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
5629 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
5630 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
5631 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
5632 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06,
5633 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) arguments_07,
5634 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) arguments_08,
5635 BSLS_COMPILERFEATURES_FORWARD_REF(Args_09) arguments_09)
5636{
5637 if (BSLS_PERFORMANCEHINT_PREDICT_LIKELY(this->d_capacity > this->size())) {
5638 AllocatorTraits::construct(
5639 this->allocatorRef(),
5640 this->d_dataEnd_p,
5641 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
5642 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
5643 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
5644 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
5645 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05),
5646 BSLS_COMPILERFEATURES_FORWARD(Args_06, arguments_06),
5647 BSLS_COMPILERFEATURES_FORWARD(Args_07, arguments_07),
5648 BSLS_COMPILERFEATURES_FORWARD(Args_08, arguments_08),
5649 BSLS_COMPILERFEATURES_FORWARD(Args_09, arguments_09));
5650 ++this->d_dataEnd_p;
5651 }
5652 else {
5653 privateEmplaceBackWithAllocation(
5654 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
5655 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
5656 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
5657 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
5658 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05),
5659 BSLS_COMPILERFEATURES_FORWARD(Args_06, arguments_06),
5660 BSLS_COMPILERFEATURES_FORWARD(Args_07, arguments_07),
5661 BSLS_COMPILERFEATURES_FORWARD(Args_08, arguments_08),
5662 BSLS_COMPILERFEATURES_FORWARD(Args_09, arguments_09));
5663 }
5664 return *(this->d_dataEnd_p - 1);
5665}
5666#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_E >= 9
5667
5668#if BSLSTL_VECTOR_VARIADIC_LIMIT_E >= 10
5669template <class VALUE_TYPE, class ALLOCATOR>
5670template <class Args_01,
5671 class Args_02,
5672 class Args_03,
5673 class Args_04,
5674 class Args_05,
5675 class Args_06,
5676 class Args_07,
5677 class Args_08,
5678 class Args_09,
5679 class Args_10>
5680inline
5681VALUE_TYPE &
5682vector<VALUE_TYPE, ALLOCATOR>::emplace_back(
5683 BSLS_COMPILERFEATURES_FORWARD_REF(Args_01) arguments_01,
5684 BSLS_COMPILERFEATURES_FORWARD_REF(Args_02) arguments_02,
5685 BSLS_COMPILERFEATURES_FORWARD_REF(Args_03) arguments_03,
5686 BSLS_COMPILERFEATURES_FORWARD_REF(Args_04) arguments_04,
5687 BSLS_COMPILERFEATURES_FORWARD_REF(Args_05) arguments_05,
5688 BSLS_COMPILERFEATURES_FORWARD_REF(Args_06) arguments_06,
5689 BSLS_COMPILERFEATURES_FORWARD_REF(Args_07) arguments_07,
5690 BSLS_COMPILERFEATURES_FORWARD_REF(Args_08) arguments_08,
5691 BSLS_COMPILERFEATURES_FORWARD_REF(Args_09) arguments_09,
5692 BSLS_COMPILERFEATURES_FORWARD_REF(Args_10) arguments_10)
5693{
5694 if (BSLS_PERFORMANCEHINT_PREDICT_LIKELY(this->d_capacity > this->size())) {
5695 AllocatorTraits::construct(
5696 this->allocatorRef(),
5697 this->d_dataEnd_p,
5698 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
5699 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
5700 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
5701 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
5702 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05),
5703 BSLS_COMPILERFEATURES_FORWARD(Args_06, arguments_06),
5704 BSLS_COMPILERFEATURES_FORWARD(Args_07, arguments_07),
5705 BSLS_COMPILERFEATURES_FORWARD(Args_08, arguments_08),
5706 BSLS_COMPILERFEATURES_FORWARD(Args_09, arguments_09),
5707 BSLS_COMPILERFEATURES_FORWARD(Args_10, arguments_10));
5708 ++this->d_dataEnd_p;
5709 }
5710 else {
5711 privateEmplaceBackWithAllocation(
5712 BSLS_COMPILERFEATURES_FORWARD(Args_01, arguments_01),
5713 BSLS_COMPILERFEATURES_FORWARD(Args_02, arguments_02),
5714 BSLS_COMPILERFEATURES_FORWARD(Args_03, arguments_03),
5715 BSLS_COMPILERFEATURES_FORWARD(Args_04, arguments_04),
5716 BSLS_COMPILERFEATURES_FORWARD(Args_05, arguments_05),
5717 BSLS_COMPILERFEATURES_FORWARD(Args_06, arguments_06),
5718 BSLS_COMPILERFEATURES_FORWARD(Args_07, arguments_07),
5719 BSLS_COMPILERFEATURES_FORWARD(Args_08, arguments_08),
5720 BSLS_COMPILERFEATURES_FORWARD(Args_09, arguments_09),
5721 BSLS_COMPILERFEATURES_FORWARD(Args_10, arguments_10));
5722 }
5723 return *(this->d_dataEnd_p - 1);
5724}
5725#endif // BSLSTL_VECTOR_VARIADIC_LIMIT_E >= 10
5726
5727#else
5728// The generated code below is a workaround for the absence of perfect
5729// forwarding in some compilers.
5730template <class VALUE_TYPE, class ALLOCATOR>
5731template <class... Args>
5732inline
5733VALUE_TYPE &
5734vector<VALUE_TYPE, ALLOCATOR>::emplace_back(
5735 BSLS_COMPILERFEATURES_FORWARD_REF(Args)...arguments)
5736{
5737 if (BSLS_PERFORMANCEHINT_PREDICT_LIKELY(this->d_capacity > this->size())) {
5738 AllocatorTraits::construct(
5739 this->allocatorRef(),
5740 this->d_dataEnd_p,
5741 BSLS_COMPILERFEATURES_FORWARD(Args, arguments)...);
5742 ++this->d_dataEnd_p;
5743 }
5744 else {
5745 privateEmplaceBackWithAllocation(
5746 BSLS_COMPILERFEATURES_FORWARD(Args, arguments)...);
5747 }
5748 return *(this->d_dataEnd_p - 1);
5749}
5750// }}} END GENERATED CODE
5751#endif
5752
5753template <class VALUE_TYPE, class ALLOCATOR>
5754inline
5755void vector<VALUE_TYPE, ALLOCATOR>::push_back(const VALUE_TYPE& value)
5756{
5757 if (BSLS_PERFORMANCEHINT_PREDICT_LIKELY(this->d_capacity > this->size())) {
5758 AllocatorTraits::construct(this->allocatorRef(),
5759 this->d_dataEnd_p,
5760 value);
5761 ++this->d_dataEnd_p;
5762 }
5763 else {
5764 privatePushBackWithAllocation(value);
5765 }
5766}
5767
5768template <class VALUE_TYPE, class ALLOCATOR>
5769inline
5770void vector<VALUE_TYPE, ALLOCATOR>::push_back(
5771 BloombergLP::bslmf::MovableRef<VALUE_TYPE> value)
5772{
5773 VALUE_TYPE& lvalue = value;
5774 if (BSLS_PERFORMANCEHINT_PREDICT_LIKELY(this->d_capacity > this->size())) {
5775 AllocatorTraits::construct(this->allocatorRef(),
5776 this->d_dataEnd_p,
5777 MoveUtil::move(lvalue));
5778 ++this->d_dataEnd_p;
5779 }
5780 else {
5781 privatePushBackWithAllocation(MoveUtil::move(lvalue));
5782 }
5783}
5784
5785template <class VALUE_TYPE, class ALLOCATOR>
5786inline
5787void vector<VALUE_TYPE, ALLOCATOR>::pop_back()
5788{
5789 BSLS_ASSERT_SAFE(!this->empty());
5790
5791 AllocatorTraits::destroy(this->allocatorRef(),
5792 --this->d_dataEnd_p);
5793}
5794
5795template <class VALUE_TYPE, class ALLOCATOR>
5796inline
5797typename vector<VALUE_TYPE, ALLOCATOR>::iterator
5798vector<VALUE_TYPE, ALLOCATOR>::insert(const_iterator position,
5799 const VALUE_TYPE& value)
5800{
5801 BSLS_ASSERT_SAFE(this->begin() <= position);
5802 BSLS_ASSERT_SAFE(position <= this->end());
5803
5804 return insert(position, size_type(1), value);
5805}
5806
5807template <class VALUE_TYPE, class ALLOCATOR>
5808typename vector<VALUE_TYPE, ALLOCATOR>::iterator
5809vector<VALUE_TYPE, ALLOCATOR>::insert(
5810 const_iterator position,
5811 BloombergLP::bslmf::MovableRef<VALUE_TYPE> value)
5812{
5813 BSLS_ASSERT_SAFE(this->begin() <= position);
5814 BSLS_ASSERT_SAFE(position <= this->end());
5815
5816 const size_type maxSize = max_size();
5817 if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(1 > maxSize - this->size())) {
5819 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
5820 "vector<...>::insert(pos,rv): vector too long");
5821 }
5822
5823 VALUE_TYPE& lvalue = value;
5824
5825 const size_type index = position - this->begin();
5826 const iterator& pos = const_cast<const iterator&>(position);
5827 const size_type newSize = this->size() + 1;
5828
5829 if (newSize > this->d_capacity) {
5830 size_type newCapacity = Vector_Util::computeNewCapacity(
5831 newSize,
5832 this->d_capacity,
5833 maxSize);
5834
5835 vector temp(this->get_allocator());
5836 temp.privateReserveEmpty(newCapacity);
5837
5838 ArrayPrimitives::destructiveMoveAndEmplace(temp.d_dataBegin_p,
5839 &this->d_dataEnd_p,
5840 this->d_dataBegin_p,
5841 pos,
5842 this->d_dataEnd_p,
5843 this->allocatorRef(),
5844 MoveUtil::move(lvalue));
5845
5846 temp.d_dataEnd_p += newSize;
5847 Vector_Util::swap(&this->d_dataBegin_p, &temp.d_dataBegin_p);
5848 }
5849 else {
5850 ArrayPrimitives::insert(pos,
5851 this->end(),
5852 MoveUtil::move(lvalue),
5853 this->allocatorRef());
5854 ++this->d_dataEnd_p;
5855 }
5856
5857 return this->begin() + index;
5858}
5859
5860template <class VALUE_TYPE, class ALLOCATOR>
5861typename vector<VALUE_TYPE, ALLOCATOR>::iterator
5862vector<VALUE_TYPE, ALLOCATOR>::insert(const_iterator position,
5863 size_type numElements,
5864 const VALUE_TYPE& value)
5865{
5866 BSLS_ASSERT_SAFE(this->begin() <= position);
5867 BSLS_ASSERT_SAFE(position <= this->end());
5868
5869 const size_type maxSize = max_size();
5871 numElements > maxSize - this->size())) {
5873 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
5874 "vector<...>::insert(pos,n,v): vector too long");
5875 }
5876
5877 const size_type index = position - this->begin();
5878 const iterator& pos = const_cast<const iterator&>(position);
5879 const size_type newSize = this->size() + numElements;
5880
5881 if (newSize > this->d_capacity) {
5882 size_type newCapacity = Vector_Util::computeNewCapacity(
5883 newSize,
5884 this->d_capacity,
5885 maxSize);
5886
5887 vector temp(this->get_allocator());
5888 temp.privateReserveEmpty(newCapacity);
5889
5890 ArrayPrimitives::destructiveMoveAndInsert(temp.d_dataBegin_p,
5891 &this->d_dataEnd_p,
5892 this->d_dataBegin_p,
5893 pos,
5894 this->d_dataEnd_p,
5895 value,
5896 numElements,
5897 this->allocatorRef());
5898
5899 temp.d_dataEnd_p += newSize;
5900 Vector_Util::swap(&this->d_dataBegin_p, &temp.d_dataBegin_p);
5901 }
5902 else {
5903 ArrayPrimitives::insert(pos,
5904 this->end(),
5905 value,
5906 numElements,
5907 this->allocatorRef());
5908 this->d_dataEnd_p += numElements;
5909 }
5910 return this->begin() + index;
5911}
5912
5913#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
5914template <class VALUE_TYPE, class ALLOCATOR>
5915inline
5916typename vector<VALUE_TYPE, ALLOCATOR>::iterator
5917vector<VALUE_TYPE, ALLOCATOR>::insert(
5918 const_iterator position,
5919 std::initializer_list<VALUE_TYPE> values)
5920{
5921 return insert(position, values.begin(), values.end());
5922}
5923#endif
5924
5925template <class VALUE_TYPE, class ALLOCATOR>
5926template <class t_RANGE>
5928typename vector<VALUE_TYPE, ALLOCATOR>::iterator
5929vector<VALUE_TYPE, ALLOCATOR>::insert_range(
5930 const_iterator position,
5931 BSLS_COMPILERFEATURES_FORWARD_REF(t_RANGE) range)
5932{
5933 BSLS_ASSERT_SAFE(this->begin() <= position);
5934 BSLS_ASSERT_SAFE(position <= this->end());
5935
5936 if (position == this->cend()) {
5937 const size_type oldSize = this->size();
5938 append_range(BSLS_COMPILERFEATURES_FORWARD(t_RANGE, range));
5939 return this->begin() + oldSize; // RETURN
5940 }
5941
5942 const size_type index = position - this->begin();
5943 this->privateInsert(position, ranges::begin(range), ranges::end(range));
5944 return this->begin() + index;
5945}
5946
5947template <class VALUE_TYPE, class ALLOCATOR>
5948inline
5949typename vector<VALUE_TYPE, ALLOCATOR>::iterator
5950vector<VALUE_TYPE, ALLOCATOR>::erase(const_iterator position)
5951{
5952 BSLS_ASSERT_SAFE(this->begin() <= position);
5953 BSLS_ASSERT_SAFE(position < this->end());
5954
5955 return erase(position, position + 1);
5956}
5957
5958// This should not be inlined by default due to an XLC 16 compiler bug whereby
5959// optimized code can spuriously core dump. This has been reported to IBM, see
5960// DRQS 169655225 for details.
5961template <class VALUE_TYPE, class ALLOCATOR>
5963typename vector<VALUE_TYPE, ALLOCATOR>::iterator
5964vector<VALUE_TYPE, ALLOCATOR>::erase(const_iterator first, const_iterator last)
5965{
5966 BSLS_ASSERT_SAFE(this->begin() <= first);
5967 BSLS_ASSERT_SAFE(first <= this->end());
5968 BSLS_ASSERT_SAFE(first <= last);
5969 BSLS_ASSERT_SAFE(last <= this->end());
5970
5971 const size_type n = last - first;
5972 ArrayPrimitives::erase(const_cast<VALUE_TYPE *>(first),
5973 const_cast<VALUE_TYPE *>(last),
5974 this->d_dataEnd_p,
5975 this->allocatorRef());
5976 this->d_dataEnd_p -= n;
5977 return const_cast<VALUE_TYPE *>(first);
5978}
5979
5980template <class VALUE_TYPE, class ALLOCATOR>
5981void vector<VALUE_TYPE, ALLOCATOR>::swap(vector<VALUE_TYPE, ALLOCATOR>& other)
5983 AllocatorTraits::propagate_on_container_swap::value ||
5984 AllocatorTraits::is_always_equal::value)
5985{
5986 typedef typename
5987 AllocatorTraits::propagate_on_container_swap Propagate;
5988
5989 if (Propagate::value) {
5990 Vector_Util::swap(&this->d_dataBegin_p, &other.d_dataBegin_p);
5991 AllocatorUtil::swap(&this->allocatorRef(),
5992 &other.allocatorRef(),
5993 Propagate());
5994 }
5995 else {
5997 this->get_allocator() == other.get_allocator())) {
5998 Vector_Util::swap(&this->d_dataBegin_p, &other.d_dataBegin_p);
5999 }
6000 else {
6002
6003 vector toOtherCopy(MoveUtil::move(*this),
6004 other.get_allocator());
6005 vector toThisCopy( MoveUtil::move(other),
6006 this->get_allocator());
6007
6008 Vector_Util::swap(&toOtherCopy.d_dataBegin_p,
6009 &other.d_dataBegin_p);
6010 Vector_Util::swap(&toThisCopy. d_dataBegin_p,
6011 &this->d_dataBegin_p);
6012 }
6013 }
6014}
6015
6016template <class VALUE_TYPE, class ALLOCATOR>
6017inline
6018void vector<VALUE_TYPE, ALLOCATOR>::clear() BSLS_KEYWORD_NOEXCEPT
6019{
6020 if (!this->empty()) {
6021 BloombergLP::bslalg::ArrayDestructionPrimitives::destroy(
6022 this->d_dataBegin_p,
6023 this->d_dataEnd_p,
6024 this->allocatorRef());
6025 this->d_dataEnd_p = this->d_dataBegin_p;
6026 }
6027}
6028
6029// ACCESSORS
6030template <class VALUE_TYPE, class ALLOCATOR>
6031inline
6032typename vector<VALUE_TYPE, ALLOCATOR>::allocator_type
6033vector<VALUE_TYPE, ALLOCATOR>::get_allocator() const BSLS_KEYWORD_NOEXCEPT
6034{
6035 return this->allocatorRef();
6036}
6037
6038 // *** capacity ***
6039
6040template <class VALUE_TYPE, class ALLOCATOR>
6041inline
6042typename vector<VALUE_TYPE, ALLOCATOR>::size_type
6043vector<VALUE_TYPE, ALLOCATOR>::max_size() const BSLS_KEYWORD_NOEXCEPT
6044{
6045 return AllocatorTraits::max_size(this->allocatorRef());
6046}
6047
6048// FREE OPERATORS
6049
6050 // *** relational operators ***
6051
6052template <class VALUE_TYPE, class ALLOCATOR>
6053inline
6054bool operator==(const vector<VALUE_TYPE, ALLOCATOR>& lhs,
6055 const vector<VALUE_TYPE, ALLOCATOR>& rhs)
6056{
6057 return BloombergLP::bslalg::RangeCompare::equal(lhs.begin(),
6058 lhs.end(),
6059 lhs.size(),
6060 rhs.begin(),
6061 rhs.end(),
6062 rhs.size());
6063}
6064
6065#ifndef BSLS_COMPILERFEATURES_SUPPORT_THREE_WAY_COMPARISON
6066template <class VALUE_TYPE, class ALLOCATOR>
6067inline
6068bool operator!=(const vector<VALUE_TYPE, ALLOCATOR>& lhs,
6069 const vector<VALUE_TYPE, ALLOCATOR>& rhs)
6070{
6071 return ! (lhs == rhs);
6072}
6073#endif // BSLS_COMPILERFEATURES_SUPPORT_THREE_WAY_COMPARISON
6074
6075#ifdef BSLALG_SYNTHTHREEWAYUTIL_AVAILABLE
6076
6077template <class VALUE_TYPE, class ALLOCATOR>
6078inline
6079BloombergLP::bslalg::SynthThreeWayUtil::Result<VALUE_TYPE> operator<=>(
6080 const vector<VALUE_TYPE, ALLOCATOR>& lhs,
6081 const vector<VALUE_TYPE, ALLOCATOR>& rhs)
6082{
6083 return lexicographical_compare_three_way(
6084 lhs.begin(),
6085 lhs.end(),
6086 rhs.begin(),
6087 rhs.end(),
6088 BloombergLP::bslalg::SynthThreeWayUtil::compare);
6089}
6090
6091#else
6092
6093template <class VALUE_TYPE, class ALLOCATOR>
6094inline
6095bool operator< (const vector<VALUE_TYPE, ALLOCATOR>& lhs,
6096 const vector<VALUE_TYPE, ALLOCATOR>& rhs)
6097{
6098 return 0 > BloombergLP::bslalg::RangeCompare::lexicographical(lhs.begin(),
6099 lhs.end(),
6100 lhs.size(),
6101 rhs.begin(),
6102 rhs.end(),
6103 rhs.size());
6104}
6105
6106template <class VALUE_TYPE, class ALLOCATOR>
6107inline
6108bool operator> (const vector<VALUE_TYPE, ALLOCATOR>& lhs,
6109 const vector<VALUE_TYPE, ALLOCATOR>& rhs)
6110{
6111 return rhs < lhs;
6112}
6113
6114template <class VALUE_TYPE, class ALLOCATOR>
6115inline
6116bool operator<=(const vector<VALUE_TYPE, ALLOCATOR>& lhs,
6117 const vector<VALUE_TYPE, ALLOCATOR>& rhs)
6118{
6119 return !(rhs < lhs);
6120}
6121
6122template <class VALUE_TYPE, class ALLOCATOR>
6123inline
6124bool operator>=(const vector<VALUE_TYPE, ALLOCATOR>& lhs,
6125 const vector<VALUE_TYPE, ALLOCATOR>& rhs)
6126{
6127 return !(lhs < rhs);
6128}
6129
6130#endif // BSLALG_SYNTHTHREEWAYUTIL_AVAILABLE
6131
6132// FREE FUNCTIONS
6133
6134 // *** specialized algorithms ***
6135
6136template <class VALUE_TYPE, class ALLOCATOR, class BDE_OTHER_TYPE>
6137inline typename vector<VALUE_TYPE, ALLOCATOR>::size_type
6138erase(vector<VALUE_TYPE, ALLOCATOR>& vec, const BDE_OTHER_TYPE& value)
6139{
6140 typename vector<VALUE_TYPE, ALLOCATOR>::size_type oldSize = vec.size();
6141 vec.erase(bsl::remove(vec.begin(), vec.end(), value), vec.end());
6142 return oldSize - vec.size();
6143}
6144
6145template <class VALUE_TYPE, class ALLOCATOR, class PREDICATE>
6146inline typename vector<VALUE_TYPE, ALLOCATOR>::size_type
6147erase_if(vector<VALUE_TYPE, ALLOCATOR>& vec, PREDICATE predicate)
6148{
6149 typename vector<VALUE_TYPE, ALLOCATOR>::size_type oldSize = vec.size();
6150 vec.erase(bsl::remove_if(vec.begin(), vec.end(), predicate), vec.end());
6151 return oldSize - vec.size();
6152}
6153
6154template <class VALUE_TYPE, class ALLOCATOR>
6155inline
6156void swap(vector<VALUE_TYPE, ALLOCATOR>& a,
6157 vector<VALUE_TYPE, ALLOCATOR>& b)
6159 a.swap(b)))
6160{
6161 a.swap(b);
6162}
6163
6164// HASH SPECIALIZATIONS
6165template <class HASHALG, class VALUE_TYPE, class ALLOCATOR>
6166inline
6167void hashAppend(HASHALG& hashAlg, const vector<VALUE_TYPE, ALLOCATOR>& input)
6168{
6169 using ::BloombergLP::bslh::hashAppend;
6170 typedef typename vector<VALUE_TYPE, ALLOCATOR>::const_iterator ci_t;
6171 hashAppend(hashAlg, input.size());
6172 for (ci_t b = input.begin(), e = input.end(); b != e; ++b) {
6173 hashAppend(hashAlg, *b);
6174 }
6175}
6176
6177
6178 // -------------------------------------
6179 // class vector<VALUE_TYPE *, ALLOCATOR>
6180 // -------------------------------------
6181
6182 // *** construct/copy/destroy ***
6183
6184// CREATORS
6185template <class VALUE_TYPE, class ALLOCATOR>
6186inline
6187vector<VALUE_TYPE *, ALLOCATOR>::vector() BSLS_KEYWORD_NOEXCEPT
6188: d_impl()
6189{
6190}
6191
6192template <class VALUE_TYPE, class ALLOCATOR>
6193inline
6194vector<VALUE_TYPE *, ALLOCATOR>::vector(const ALLOCATOR& basicAllocator)
6196: d_impl(ImplAlloc(basicAllocator))
6197{
6198}
6199
6200template <class VALUE_TYPE, class ALLOCATOR>
6201inline
6202vector<VALUE_TYPE *, ALLOCATOR>::vector(size_type initialSize,
6203 const ALLOCATOR& basicAllocator)
6204: d_impl(initialSize, ImplAlloc(basicAllocator))
6205{
6206}
6207
6208template <class VALUE_TYPE, class ALLOCATOR>
6209inline
6210vector<VALUE_TYPE *, ALLOCATOR>::vector(size_type initialSize,
6211 VALUE_TYPE *value,
6212 const ALLOCATOR& basicAllocator)
6213: d_impl(initialSize, (UintPtr) value, ImplAlloc(basicAllocator))
6214{
6215}
6216
6217template <class VALUE_TYPE, class ALLOCATOR>
6218template <class INPUT_ITER>
6219inline
6220vector<VALUE_TYPE *, ALLOCATOR>::vector(INPUT_ITER first,
6221 INPUT_ITER last,
6222 const ALLOCATOR& basicAllocator)
6223: d_impl(typename vector_ForwardIteratorForPtrs<VALUE_TYPE, INPUT_ITER>::type(
6224 first),
6225 typename vector_ForwardIteratorForPtrs<VALUE_TYPE, INPUT_ITER>::type(
6226 last),
6227 basicAllocator)
6228{
6229}
6230
6231template <class VALUE_TYPE, class ALLOCATOR>
6232template <class t_RANGE>
6234inline
6235vector<VALUE_TYPE *, ALLOCATOR>::vector(
6236 from_range_t ,
6237 BSLS_COMPILERFEATURES_FORWARD_REF(t_RANGE) range,
6238 const ALLOCATOR& basicAllocator)
6239: d_impl(from_range,
6240 vector_makeUintPtrRangeAdapter<VALUE_TYPE *>(ranges::begin(range),
6241 ranges::end(range)),
6242 basicAllocator)
6243{
6244}
6245
6246template <class VALUE_TYPE, class ALLOCATOR>
6247inline
6248vector<VALUE_TYPE *, ALLOCATOR>::vector(const vector& original)
6249: d_impl(original.d_impl)
6250{
6251}
6252
6253template <class VALUE_TYPE, class ALLOCATOR>
6254inline
6255vector<VALUE_TYPE *, ALLOCATOR>::vector(
6256 BloombergLP::bslmf::MovableRef<vector> original)
6258: d_impl(MoveUtil::move(MoveUtil::access(original).d_impl))
6259{
6260}
6261
6262template <class VALUE_TYPE, class ALLOCATOR>
6263inline
6264vector<VALUE_TYPE *, ALLOCATOR>::vector(const vector& original,
6265 const typename type_identity<ALLOCATOR>::type& basicAllocator)
6266: d_impl(original.d_impl, ImplAlloc(basicAllocator))
6267{
6268}
6269
6270template <class VALUE_TYPE, class ALLOCATOR>
6271inline
6272vector<VALUE_TYPE *, ALLOCATOR>::vector(
6273 BloombergLP::bslmf::MovableRef<vector> original,
6274 const typename type_identity<ALLOCATOR>::type& basicAllocator)
6275: d_impl(MoveUtil::move(MoveUtil::access(original).d_impl),
6276 ImplAlloc(basicAllocator))
6277{
6278}
6279
6280#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
6281template <class VALUE_TYPE, class ALLOCATOR>
6282inline
6283vector<VALUE_TYPE *, ALLOCATOR>::vector(
6284 std::initializer_list<VALUE_TYPE *> values,
6285 const ALLOCATOR& basicAllocator)
6286: d_impl(typename vector_ForwardIteratorForPtrs<
6287 VALUE_TYPE,
6288 typename std::initializer_list<VALUE_TYPE *>::const_iterator>::
6289 type(values.begin()),
6290 typename vector_ForwardIteratorForPtrs<
6291 VALUE_TYPE,
6292 typename std::initializer_list<VALUE_TYPE *>::const_iterator>::
6293 type(values.end()),
6294 basicAllocator)
6295{
6296}
6297#endif
6298
6299template <class VALUE_TYPE, class ALLOCATOR>
6300inline
6301vector<VALUE_TYPE *, ALLOCATOR>::~vector()
6302{
6303}
6304
6305// MANIPULATORS
6306template <class VALUE_TYPE, class ALLOCATOR>
6307inline
6308vector<VALUE_TYPE *, ALLOCATOR>& vector<VALUE_TYPE *, ALLOCATOR>::operator=(
6309 const vector& rhs)
6310{
6311 d_impl = rhs.d_impl;
6312 return *this;
6313}
6314
6315#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
6316template <class VALUE_TYPE, class ALLOCATOR>
6317inline
6318vector<VALUE_TYPE *, ALLOCATOR>& vector<VALUE_TYPE *, ALLOCATOR>::operator=(
6319 std::initializer_list<VALUE_TYPE *> values)
6320{
6321 assign(values);
6322 return *this;
6323}
6324
6325template <class VALUE_TYPE, class ALLOCATOR>
6326inline
6327void vector<VALUE_TYPE *, ALLOCATOR>::assign(
6328 std::initializer_list<VALUE_TYPE *> values)
6329{
6330 typedef typename std::initializer_list<VALUE_TYPE *>::const_iterator
6331 InitIter;
6332
6333 typedef typename vector_ForwardIteratorForPtrs<VALUE_TYPE, InitIter>::type
6334 Iter;
6335
6336 d_impl.assign(Iter(values.begin()), Iter(values.end()));
6337}
6338#endif
6339
6340template <class VALUE_TYPE, class ALLOCATOR>
6341template <class INPUT_ITER>
6342inline
6343void vector<VALUE_TYPE *, ALLOCATOR>::assign(INPUT_ITER first, INPUT_ITER last)
6344{
6345 typedef typename vector_ForwardIteratorForPtrs<VALUE_TYPE,
6346 INPUT_ITER>::type Iter;
6347
6348 d_impl.assign(Iter(first), Iter(last));
6349}
6350
6351template <class VALUE_TYPE, class ALLOCATOR>
6352inline
6353void vector<VALUE_TYPE *, ALLOCATOR>::assign(size_type numElements,
6354 VALUE_TYPE *value)
6355{
6356 d_impl.assign(numElements, (UintPtr) value);
6357}
6358
6359template <class VALUE_TYPE, class ALLOCATOR>
6360template <class t_RANGE>
6362inline
6363void vector<VALUE_TYPE *, ALLOCATOR>::assign_range(
6364 BSLS_COMPILERFEATURES_FORWARD_REF(t_RANGE) range)
6365{
6366 d_impl.assign_range(
6367 vector_makeUintPtrRangeAdapter<VALUE_TYPE *>(ranges::begin(range),
6368 ranges::end(range)));
6369}
6370
6371 // *** iterators ***
6372
6373template <class VALUE_TYPE, class ALLOCATOR>
6374inline
6375typename vector<VALUE_TYPE *, ALLOCATOR>::iterator
6376vector<VALUE_TYPE *, ALLOCATOR>::begin() BSLS_KEYWORD_NOEXCEPT
6377{
6378 return (iterator) d_impl.begin();
6379}
6380
6381template <class VALUE_TYPE, class ALLOCATOR>
6382inline
6383typename vector<VALUE_TYPE *, ALLOCATOR>::iterator
6384vector<VALUE_TYPE *, ALLOCATOR>::end() BSLS_KEYWORD_NOEXCEPT
6385{
6386 return (iterator) d_impl.end();
6387}
6388
6389template <class VALUE_TYPE, class ALLOCATOR>
6390inline
6391typename vector<VALUE_TYPE *, ALLOCATOR>::reverse_iterator
6392vector<VALUE_TYPE *, ALLOCATOR>::rbegin() BSLS_KEYWORD_NOEXCEPT
6393{
6394 return reverse_iterator((iterator) d_impl.rbegin().base());
6395}
6396
6397template <class VALUE_TYPE, class ALLOCATOR>
6398inline
6399typename vector<VALUE_TYPE *, ALLOCATOR>::reverse_iterator
6400vector<VALUE_TYPE *, ALLOCATOR>::rend() BSLS_KEYWORD_NOEXCEPT
6401{
6402 return reverse_iterator((iterator) d_impl.rend().base());
6403}
6404
6405 // *** capacity ***
6406
6407template <class VALUE_TYPE, class ALLOCATOR>
6408inline
6409typename vector<VALUE_TYPE *, ALLOCATOR>::size_type
6410vector<VALUE_TYPE *, ALLOCATOR>::size() const BSLS_KEYWORD_NOEXCEPT
6411{
6412 return d_impl.size();
6413}
6414
6415template <class VALUE_TYPE, class ALLOCATOR>
6416inline
6417typename vector<VALUE_TYPE *, ALLOCATOR>::size_type
6418vector<VALUE_TYPE *, ALLOCATOR>::capacity() const BSLS_KEYWORD_NOEXCEPT
6419{
6420 return d_impl.capacity();
6421}
6422
6423template <class VALUE_TYPE, class ALLOCATOR>
6424inline
6425bool
6426vector<VALUE_TYPE *, ALLOCATOR>::empty() const BSLS_KEYWORD_NOEXCEPT
6427{
6428 return d_impl.empty();
6429}
6430
6431 // *** element access ***
6432
6433template <class VALUE_TYPE, class ALLOCATOR>
6434inline
6435typename vector<VALUE_TYPE *, ALLOCATOR>::reference
6436vector<VALUE_TYPE *, ALLOCATOR>::operator[](size_type position)
6437{
6438 return (reference) d_impl.operator[](position);
6439}
6440
6441template <class VALUE_TYPE, class ALLOCATOR>
6442inline
6443typename vector<VALUE_TYPE *, ALLOCATOR>::reference
6444vector<VALUE_TYPE *, ALLOCATOR>::at(size_type position)
6445{
6446 return (reference) d_impl.at(position);
6447}
6448
6449template <class VALUE_TYPE, class ALLOCATOR>
6450inline
6451typename vector<VALUE_TYPE *, ALLOCATOR>::reference
6452vector<VALUE_TYPE *, ALLOCATOR>::front()
6453{
6454 return (reference) d_impl.front();
6455}
6456
6457template <class VALUE_TYPE, class ALLOCATOR>
6458inline
6459typename vector<VALUE_TYPE *, ALLOCATOR>::reference
6460vector<VALUE_TYPE *, ALLOCATOR>::back()
6461{
6462 return (reference) d_impl.back();
6463}
6464
6465template <class VALUE_TYPE, class ALLOCATOR>
6466inline
6467VALUE_TYPE **vector<VALUE_TYPE *, ALLOCATOR>::data() BSLS_KEYWORD_NOEXCEPT
6468{
6469 return (VALUE_TYPE **) d_impl.data();
6470}
6471
6472 // *** capacity ***
6473
6474template <class VALUE_TYPE, class ALLOCATOR>
6475inline
6476void vector<VALUE_TYPE *, ALLOCATOR>::resize(size_type newLength)
6477{
6478 d_impl.resize(newLength);
6479}
6480
6481template <class VALUE_TYPE, class ALLOCATOR>
6482inline
6483void vector<VALUE_TYPE *, ALLOCATOR>::resize(size_type newLength,
6484 VALUE_TYPE *value)
6485{
6486 d_impl.resize(newLength, (UintPtr) value);
6487}
6488
6489template <class VALUE_TYPE, class ALLOCATOR>
6490inline
6491void vector<VALUE_TYPE *, ALLOCATOR>::reserve(size_type newCapacity)
6492{
6493 d_impl.reserve(newCapacity);
6494}
6495
6496template <class VALUE_TYPE, class ALLOCATOR>
6497inline
6498void vector<VALUE_TYPE *, ALLOCATOR>::shrink_to_fit()
6499{
6500 d_impl.shrink_to_fit();
6501}
6502
6503
6504 // *** modifiers ***
6505
6506template <class VALUE_TYPE, class ALLOCATOR>
6507template <class t_RANGE>
6509inline
6510void vector<VALUE_TYPE *, ALLOCATOR>::append_range(
6511 BSLS_COMPILERFEATURES_FORWARD_REF(t_RANGE) range)
6512{
6513 d_impl.append_range(
6514 vector_makeUintPtrRangeAdapter<VALUE_TYPE *>(ranges::begin(range),
6515 ranges::end(range)));
6516}
6517
6518template <class VALUE_TYPE, class ALLOCATOR>
6519inline
6520typename vector<VALUE_TYPE *, ALLOCATOR>::reference
6521vector<VALUE_TYPE *, ALLOCATOR>::emplace_back()
6522{
6523 d_impl.emplace_back();
6524 return back();
6525}
6526
6527# if defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES)
6528template <class VALUE_TYPE, class ALLOCATOR>
6529template <class ARG>
6530inline
6531typename vector<VALUE_TYPE *, ALLOCATOR>::reference
6532vector<VALUE_TYPE *, ALLOCATOR>::emplace_back(ARG&& arg)
6533{
6534 VALUE_TYPE *ptr(arg); // Support explicit conversion operators
6535 d_impl.emplace_back(reinterpret_cast<UintPtr>(ptr));
6536 return back();
6537}
6538# else
6539template <class VALUE_TYPE, class ALLOCATOR>
6540inline
6541typename vector<VALUE_TYPE *, ALLOCATOR>::reference
6542vector<VALUE_TYPE *, ALLOCATOR>::emplace_back(VALUE_TYPE *ptr)
6543{
6544 d_impl.emplace_back(reinterpret_cast<UintPtr>(ptr));
6545 return back();
6546}
6547# endif
6548
6549template <class VALUE_TYPE, class ALLOCATOR>
6550inline
6551void vector<VALUE_TYPE *, ALLOCATOR>::push_back(VALUE_TYPE *value)
6552{
6553 d_impl.emplace_back(reinterpret_cast<UintPtr>(value));
6554}
6555
6556template <class VALUE_TYPE, class ALLOCATOR>
6557inline
6558void vector<VALUE_TYPE *, ALLOCATOR>::pop_back()
6559{
6560 d_impl.pop_back();
6561}
6562
6563template <class VALUE_TYPE, class ALLOCATOR>
6564inline
6565typename vector<VALUE_TYPE *, ALLOCATOR>::iterator
6566vector<VALUE_TYPE *, ALLOCATOR>::emplace(const_iterator position)
6567{
6568 return (iterator) d_impl.emplace((const UintPtr*) position);
6569}
6570
6571# if defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES)
6572template <class VALUE_TYPE, class ALLOCATOR>
6573template <class ARG>
6574inline
6575typename vector<VALUE_TYPE *, ALLOCATOR>::iterator
6576vector<VALUE_TYPE *, ALLOCATOR>::emplace(const_iterator position, ARG&& arg)
6577{
6578 VALUE_TYPE *ptr(arg); // Support explicit conversion operators
6579 return (iterator) d_impl.emplace((const UintPtr *)position,
6580 reinterpret_cast<UintPtr>(ptr));
6581}
6582# else
6583template <class VALUE_TYPE, class ALLOCATOR>
6584inline
6585typename vector<VALUE_TYPE *, ALLOCATOR>::iterator
6586vector<VALUE_TYPE *, ALLOCATOR>::emplace(const_iterator position,
6587 VALUE_TYPE *ptr)
6588{
6589 return (iterator) d_impl.emplace((const UintPtr*) position,
6590 reinterpret_cast<UintPtr>(ptr));
6591}
6592# endif
6593
6594template <class VALUE_TYPE, class ALLOCATOR>
6595inline
6596typename vector<VALUE_TYPE *, ALLOCATOR>::iterator
6597vector<VALUE_TYPE *, ALLOCATOR>::insert(const_iterator position,
6598 VALUE_TYPE *value)
6599{
6600 return (iterator) d_impl.emplace((const UintPtr*) position,
6601 reinterpret_cast<UintPtr>(value));
6602}
6603
6604template <class VALUE_TYPE, class ALLOCATOR>
6605inline
6606typename vector<VALUE_TYPE *, ALLOCATOR>::iterator
6607vector<VALUE_TYPE *, ALLOCATOR>::insert(const_iterator position,
6608 size_type numElements,
6609 VALUE_TYPE *value)
6610{
6611 return (iterator) d_impl.insert(
6612 (const UintPtr *)position, numElements, (UintPtr)value);
6613}
6614
6615#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
6616template <class VALUE_TYPE, class ALLOCATOR>
6617inline
6618typename vector<VALUE_TYPE *, ALLOCATOR>::iterator
6619vector<VALUE_TYPE *, ALLOCATOR>::insert(
6620 const_iterator position,
6621 std::initializer_list<VALUE_TYPE *> values)
6622{
6623 typedef typename std::initializer_list<VALUE_TYPE *>::const_iterator
6624 InitIter;
6625
6626 typedef typename vector_ForwardIteratorForPtrs<VALUE_TYPE, InitIter>::type
6627 Iter;
6628
6629 return (iterator) d_impl.insert(
6630 (const UintPtr *)position, Iter(values.begin()), Iter(values.end()));
6631}
6632#endif
6633
6634template <class VALUE_TYPE, class ALLOCATOR>
6635template <class t_RANGE>
6637inline
6638typename vector<VALUE_TYPE *, ALLOCATOR>::iterator
6639vector<VALUE_TYPE *, ALLOCATOR>::insert_range(
6640 const_iterator position,
6641 BSLS_COMPILERFEATURES_FORWARD_REF(t_RANGE) range)
6642{
6643 return (iterator) d_impl.insert_range(
6644 (const UintPtr*) position,
6645 vector_makeUintPtrRangeAdapter<VALUE_TYPE *>(ranges::begin(range),
6646 ranges::end(range)));
6647}
6648
6649template <class VALUE_TYPE, class ALLOCATOR>
6650inline
6651typename vector<VALUE_TYPE *, ALLOCATOR>::iterator
6652vector<VALUE_TYPE *, ALLOCATOR>::erase(const_iterator position)
6653{
6654 return (iterator) d_impl.erase((const UintPtr*) position);
6655}
6656
6657template <class VALUE_TYPE, class ALLOCATOR>
6658inline
6659typename vector<VALUE_TYPE *, ALLOCATOR>::iterator
6660vector<VALUE_TYPE *, ALLOCATOR>::erase(const_iterator first,
6661 const_iterator last)
6662{
6663 return (iterator) d_impl.erase((const UintPtr*) first,
6664 (const UintPtr*) last);
6665}
6666
6667template <class VALUE_TYPE, class ALLOCATOR>
6668inline
6669void vector<VALUE_TYPE *, ALLOCATOR>::swap(
6670 vector<VALUE_TYPE *, ALLOCATOR>& other)
6672 d_impl.swap(other.d_impl)))
6673{
6674 d_impl.swap(other.d_impl);
6675}
6676
6677template <class VALUE_TYPE, class ALLOCATOR>
6678inline
6679void vector<VALUE_TYPE *, ALLOCATOR>::clear() BSLS_KEYWORD_NOEXCEPT
6680{
6681 d_impl.clear();
6682}
6683
6684// ACCESSORS
6685template <class VALUE_TYPE, class ALLOCATOR>
6686inline
6687typename vector<VALUE_TYPE *, ALLOCATOR>::allocator_type
6688vector<VALUE_TYPE *, ALLOCATOR>::get_allocator() const BSLS_KEYWORD_NOEXCEPT
6689{
6690 return ALLOCATOR(d_impl.get_allocator());
6691}
6692
6693template <class VALUE_TYPE, class ALLOCATOR>
6694inline
6695typename vector<VALUE_TYPE *, ALLOCATOR>::size_type
6696vector<VALUE_TYPE *, ALLOCATOR>::max_size() const BSLS_KEYWORD_NOEXCEPT
6697{
6698 return d_impl.max_size();
6699}
6700
6701
6702 // *** iterators ***
6703
6704template <class VALUE_TYPE, class ALLOCATOR>
6705inline
6706typename vector<VALUE_TYPE *, ALLOCATOR>::const_iterator
6707vector<VALUE_TYPE *, ALLOCATOR>::begin() const BSLS_KEYWORD_NOEXCEPT
6708{
6709 return (const_iterator) d_impl.begin();
6710}
6711
6712template <class VALUE_TYPE, class ALLOCATOR>
6713inline
6714typename vector<VALUE_TYPE *, ALLOCATOR>::const_iterator
6715vector<VALUE_TYPE *, ALLOCATOR>::cbegin() const BSLS_KEYWORD_NOEXCEPT
6716{
6717 return (const_iterator) d_impl.cbegin();
6718}
6719
6720template <class VALUE_TYPE, class ALLOCATOR>
6721inline
6722typename vector<VALUE_TYPE *, ALLOCATOR>::const_iterator
6723vector<VALUE_TYPE *, ALLOCATOR>::end() const BSLS_KEYWORD_NOEXCEPT
6724{
6725 return (const_iterator) d_impl.end();
6726}
6727
6728template <class VALUE_TYPE, class ALLOCATOR>
6729inline
6730typename vector<VALUE_TYPE *, ALLOCATOR>::const_iterator
6731vector<VALUE_TYPE *, ALLOCATOR>::cend() const BSLS_KEYWORD_NOEXCEPT
6732{
6733 return (const_iterator) d_impl.cend();
6734}
6735
6736template <class VALUE_TYPE, class ALLOCATOR>
6737inline
6738typename vector<VALUE_TYPE *, ALLOCATOR>::const_reverse_iterator
6739vector<VALUE_TYPE *, ALLOCATOR>::rbegin() const BSLS_KEYWORD_NOEXCEPT
6740{
6741 return const_reverse_iterator((const_iterator) d_impl.rbegin().base());
6742}
6743
6744template <class VALUE_TYPE, class ALLOCATOR>
6745inline
6746typename vector<VALUE_TYPE *, ALLOCATOR>::const_reverse_iterator
6747vector<VALUE_TYPE *, ALLOCATOR>::crbegin() const BSLS_KEYWORD_NOEXCEPT
6748{
6749 return const_reverse_iterator((const_iterator) d_impl.crbegin().base());
6750}
6751
6752template <class VALUE_TYPE, class ALLOCATOR>
6753inline
6754typename vector<VALUE_TYPE *, ALLOCATOR>::const_reverse_iterator
6755vector<VALUE_TYPE *, ALLOCATOR>::rend() const BSLS_KEYWORD_NOEXCEPT
6756{
6757 return const_reverse_iterator((const_iterator) d_impl.rend().base());
6758}
6759
6760template <class VALUE_TYPE, class ALLOCATOR>
6761inline
6762typename vector<VALUE_TYPE *, ALLOCATOR>::const_reverse_iterator
6763vector<VALUE_TYPE *, ALLOCATOR>::crend() const BSLS_KEYWORD_NOEXCEPT
6764{
6765 return const_reverse_iterator((const_iterator) d_impl.crend().base());
6766}
6767
6768
6769 // *** element access ***
6770
6771template <class VALUE_TYPE, class ALLOCATOR>
6772inline
6773typename vector<VALUE_TYPE *, ALLOCATOR>::const_reference
6774vector<VALUE_TYPE *, ALLOCATOR>::operator[](size_type position) const
6775{
6776 return (const_reference) d_impl.operator[](position);
6777}
6778
6779template <class VALUE_TYPE, class ALLOCATOR>
6780inline
6781typename vector<VALUE_TYPE *, ALLOCATOR>::const_reference
6782vector<VALUE_TYPE *, ALLOCATOR>::at(size_type position) const
6783{
6784 return (const_reference) d_impl.at(position);
6785}
6786
6787template <class VALUE_TYPE, class ALLOCATOR>
6788inline
6789typename vector<VALUE_TYPE *, ALLOCATOR>::const_reference
6790vector<VALUE_TYPE *, ALLOCATOR>::front() const
6791{
6792 return (const_reference) d_impl.front();
6793}
6794
6795template <class VALUE_TYPE, class ALLOCATOR>
6796inline
6797typename vector<VALUE_TYPE *, ALLOCATOR>::const_reference
6798vector<VALUE_TYPE *, ALLOCATOR>::back() const
6799{
6800 return (const_reference) d_impl.back();
6801}
6802
6803template <class VALUE_TYPE, class ALLOCATOR>
6804inline
6805VALUE_TYPE *const *vector<VALUE_TYPE *, ALLOCATOR>::data() const
6807{
6808 return (VALUE_TYPE *const *) d_impl.data();
6809}
6810
6811
6812} // close namespace bsl
6813
6814// ============================================================================
6815// TYPE TRAITS
6816// ============================================================================
6817
6818// Type traits for STL *sequence* containers:
6819//: o A sequence container defines STL iterators.
6820//: o A sequence container is bitwise movable if the allocator is bitwise
6821//: movable.
6822//: o A sequence container uses 'bslma' allocators if the (template parameter)
6823//: type 'ALLOCATOR' is convertible from 'bslma::Allocator *'.
6824
6825
6826
6827namespace bslalg {
6828
6829template <class VALUE_TYPE, class ALLOCATOR>
6830struct HasStlIterators<bsl::vector<VALUE_TYPE, ALLOCATOR> > : bsl::true_type
6831{};
6832
6833} // close namespace bslalg
6834
6835namespace bslma {
6836
6837template <class VALUE_TYPE, class ALLOCATOR>
6838struct UsesBslmaAllocator<bsl::vector<VALUE_TYPE, ALLOCATOR> >
6839 : bsl::is_convertible<Allocator *, ALLOCATOR>::type
6840{};
6841
6842} // close namespace bslma
6843
6844namespace bslmf {
6845
6846template <class VALUE_TYPE, class ALLOCATOR>
6847struct IsBitwiseMoveable<bsl::vector<VALUE_TYPE, ALLOCATOR> >
6848 : IsBitwiseMoveable<ALLOCATOR>
6849{};
6850
6851} // close namespace bslmf
6852
6853
6854
6855#ifdef BSLS_COMPILERFEATURES_SUPPORT_EXTERN_TEMPLATE
6856extern template class bsl::vectorBase<bool>;
6857extern template class bsl::vectorBase<char>;
6858extern template class bsl::vectorBase<signed char>;
6859extern template class bsl::vectorBase<unsigned char>;
6860extern template class bsl::vectorBase<short>;
6861extern template class bsl::vectorBase<unsigned short>;
6862extern template class bsl::vectorBase<int>;
6863extern template class bsl::vectorBase<unsigned int>;
6864extern template class bsl::vectorBase<long>;
6865extern template class bsl::vectorBase<unsigned long>;
6866extern template class bsl::vectorBase<long long>;
6867extern template class bsl::vectorBase<unsigned long long>;
6868extern template class bsl::vectorBase<float>;
6869extern template class bsl::vectorBase<double>;
6870extern template class bsl::vectorBase<long double>;
6871extern template class bsl::vectorBase<void *>;
6872extern template class bsl::vectorBase<const char *>;
6873
6874extern template class bsl::vector<bool>;
6875extern template class bsl::vector<char>;
6876extern template class bsl::vector<signed char>;
6877extern template class bsl::vector<unsigned char>;
6878extern template class bsl::vector<short>;
6879extern template class bsl::vector<unsigned short>;
6880extern template class bsl::vector<int>;
6881extern template class bsl::vector<unsigned int>;
6882extern template class bsl::vector<long>;
6883extern template class bsl::vector<unsigned long>;
6884extern template class bsl::vector<long long>;
6885extern template class bsl::vector<unsigned long long>;
6886extern template class bsl::vector<float>;
6887extern template class bsl::vector<double>;
6888extern template class bsl::vector<long double>;
6889extern template class bsl::vector<void *>;
6890extern template class bsl::vector<const char *>;
6891#endif
6892
6893#else // if ! defined(DEFINED_BSLSTL_VECTOR_H)
6894# error Not valid except when included from bslstl_vector.h
6895#endif // ! defined(COMPILING_BSLSTL_VECTOR_H)
6896
6897#endif // ! defined(INCLUDED_BSLSTL_VECTOR_CPP03)
6898
6899// ----------------------------------------------------------------------------
6900// Copyright 2018 Bloomberg Finance L.P.
6901//
6902// Licensed under the Apache License, Version 2.0 (the "License");
6903// you may not use this file except in compliance with the License.
6904// You may obtain a copy of the License at
6905//
6906// http://www.apache.org/licenses/LICENSE-2.0
6907//
6908// Unless required by applicable law or agreed to in writing, software
6909// distributed under the License is distributed on an "AS IS" BASIS,
6910// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6911// See the License for the specific language governing permissions and
6912// limitations under the License.
6913// ----------------------------- END-OF-FILE ----------------------------------
6914
6915/** @} */
6916/** @} */
6917/** @} */
size_type size() const BSLS_KEYWORD_NOEXCEPT
Return the number of elements contained by this deque.
Definition bslstl_deque.h:2241
Definition bslma_bslallocator.h:588
Definition bslstl_vector.h:924
VALUE_TYPE const & const_reference
Definition bslstl_vector.h:942
size_type size() const BSLS_KEYWORD_NOEXCEPT
Return the number of elements in this vector.
Definition bslstl_vector.h:3019
std::size_t d_capacity
Definition bslstl_vector.h:936
VALUE_TYPE * d_dataEnd_p
Definition bslstl_vector.h:935
void adopt(BloombergLP::bslmf::MovableRef< vectorBase > base)
Definition bslstl_vector.h:2847
iterator begin() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_vector.h:2866
reference back()
Definition bslstl_vector.h:2932
size_type capacity() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_vector.h:3027
std::ptrdiff_t difference_type
Definition bslstl_vector.h:946
VALUE_TYPE value_type
Definition bslstl_vector.h:940
const_iterator cend() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_vector.h:2977
const_iterator cbegin() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_vector.h:2961
VALUE_TYPE const * const_iterator
Definition bslstl_vector.h:944
std::size_t size_type
Definition bslstl_vector.h:945
const_reverse_iterator crend() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_vector.h:3009
reverse_iterator rbegin() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_vector.h:2882
vectorBase()
Create an empty base object with no capacity.
Definition bslstl_vector.h:2835
iterator end() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_vector.h:2874
VALUE_TYPE * d_dataBegin_p
Definition bslstl_vector.h:934
bsl::reverse_iterator< const_iterator > const_reverse_iterator
Definition bslstl_vector.h:948
reference at(size_type position)
Definition bslstl_vector.h:2909
VALUE_TYPE & reference
Definition bslstl_vector.h:941
bsl::reverse_iterator< iterator > reverse_iterator
Definition bslstl_vector.h:947
bool empty() const BSLS_KEYWORD_NOEXCEPT
Return true if this vector has size 0, and false otherwise.
Definition bslstl_vector.h:3034
reference front()
Definition bslstl_vector.h:2922
reverse_iterator rend() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_vector.h:2890
const_reverse_iterator crbegin() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_vector.h:2993
VALUE_TYPE * iterator
Definition bslstl_vector.h:943
VALUE_TYPE * data() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_vector.h:2942
vector_UintPtrConversionIterator()
Create an uninitialized proxy iterator.
Definition bslstl_vector.h:2633
Definition bslstl_vector.h:1120
AllocatorTraits::size_type size_type
Definition bslstl_vector.h:1147
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1917
#define BSLS_ASSERT_OPT(X)
Definition bsls_assert.h:2045
#define BSLS_COMPILERFEATURES_FORWARD_REF(T)
Definition bsls_compilerfeatures.h:2343
#define BSLS_COMPILERFEATURES_FORWARD(T, V)
Definition bsls_compilerfeatures.h:2349
#define BSLS_KEYWORD_NOEXCEPT_OPERATOR(...)
Definition bsls_keyword.h:677
#define BSLS_KEYWORD_NOEXCEPT
Definition bsls_keyword.h:674
#define BSLS_KEYWORD_NOEXCEPT_SPECIFICATION(...)
Definition bsls_keyword.h:676
#define BSLS_PERFORMANCEHINT_PREDICT_LIKELY(expr)
Definition bsls_performancehint.h:451
#define BSLS_PERFORMANCEHINT_UNLIKELY_HINT
Definition bsls_performancehint.h:484
#define BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(expr)
Definition bsls_performancehint.h:452
#define BSLS_PLATFORM_AGGRESSIVE_INLINE
Definition bsls_platform.h:737
#define BSLSTL_VECTOR_REQUIRES_CONTAINER_COMPATIBLE_RANGE(R, T)
Definition bslstl_vector.h:691
bool operator!=(const FileCleanerConfiguration &lhs, const FileCleanerConfiguration &rhs)
bool operator==(const FileCleanerConfiguration &lhs, const FileCleanerConfiguration &rhs)
void swap(OptionValue &a, OptionValue &b)
bool operator<(const MetricId &lhs, const MetricId &rhs)
void resize(TYPE *array, int newSize)
bsl::size_t size(const TYPE &array)
Return the number of elements in the specified array.
int reserve(TYPE *array, int numElements)
int assign(LHS_TYPE *lhs, const RHS_TYPE &rhs)
bool operator>=(const Guid &lhs, const Guid &rhs)
FunctionOutputIterator< FUNCTION > & operator++(FunctionOutputIterator< FUNCTION > &iterator)
Do nothing and return specified iterator.
Definition bdlb_functionoutputiterator.h:408
void hashAppend(HASH_ALGORITHM &hashAlgorithm, const BigEndianInt16 &object)
bool operator<=(const Guid &lhs, const Guid &rhs)
bool operator>(const Guid &lhs, const Guid &rhs)
TransformIterator< FUNCTOR, ITERATOR > operator-(const TransformIterator< FUNCTOR, ITERATOR > &iterator, typename TransformIterator< FUNCTOR, ITERATOR >::difference_type offset)
Decimal32 operator*(Decimal32 lhs, Decimal32 rhs)
Definition bdlat_valuetypefunctions.h:939
T::const_iterator cend(const T &container)
Definition bslstl_iterator.h:1709
ALLOCATOR const STRING_VIEW_LIKE_TYPE & rhs
Definition bslstl_string.h:3918
deque< VALUE_TYPE, ALLOCATOR >::size_type erase(deque< VALUE_TYPE, ALLOCATOR > &deq, const BDE_OTHER_TYPE &value)
Definition bslstl_deque.h:4424
T::iterator begin(T &container)
Definition bslstl_iterator.h:1593
const from_range_t from_range
ALLOCATOR & lhs
Definition bslstl_string.h:3917
T::iterator end(T &container)
Definition bslstl_iterator.h:1621
deque< VALUE_TYPE, ALLOCATOR >::size_type erase_if(deque< VALUE_TYPE, ALLOCATOR > &deq, PREDICATE predicate)
Definition bslstl_deque.h:4433
BSLS_KEYWORD_CONSTEXPR CONTAINER::value_type * data(CONTAINER &container)
Definition bslstl_iterator.h:1325
BSLS_KEYWORD_CONSTEXPR bool empty(const CONTAINER &container)
Definition bslstl_iterator.h:1377
vector_UintPtrRangeAdapter< t_VALUE_TYPE, t_ITERATOR, t_SENTINEL > vector_makeUintPtrRangeAdapter(t_ITERATOR begin, t_SENTINEL end)
Factory function for vector_UintPtrRangeAdapter.
Definition bslstl_vector.h:2708
Definition bdlc_flathashmap.h:2218
Definition baljsn_encoder_testtypes.h:76
Definition bdlbb_blob.h:579
Definition bdldfp_decimal.h:5549
bsl::iterator_traits< BSLSTL_ITERATOR >::iterator_category type
Definition bslstl_vector.h:764
bsl::iterator_traits< t_ITERATOR >::iterator_category type
Definition bslstl_vector.h:807
static std::size_t computeNewCapacity(std::size_t newLength, std::size_t capacity, std::size_t maxSize)
static void swap(void *a, void *b)
BloombergLP::bslma::AllocatorTraits_SizeType< ALLOCATOR_TYPE >::type size_type
Definition bslma_allocatortraits.h:1196
static void destroy(ALLOCATOR_TYPE &basicAllocator, ELEMENT_TYPE *elementAddr)
Definition bslma_allocatortraits.h:1549
Definition bslmf_enableif.h:530
Definition bslmf_isconvertible.h:875
Definition bslmf_issame.h:146
ITERATOR type
Definition bslstl_vector.h:841