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