11#ifndef INCLUDED_BSLSTL_DEQUE_CPP03
12#define INCLUDED_BSLSTL_DEQUE_CPP03
63#ifdef COMPILING_BSLSTL_DEQUE_H
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>
85template <
class VALUE_TYPE>
86struct Deque_BlockLengthCalcUtil {
116 static void move(
void *dst,
void *src);
120 static void swap(
void *a,
void *b);
137template <
class VALUE_TYPE>
145 typedef BloombergLP::bslalg::DequeImpUtil<VALUE_TYPE,
147 typedef typename Imp::Block Block;
148 typedef typename Imp::BlockPtr BlockPtr;
149 typedef BloombergLP::bslalg::DequeIterator<VALUE_TYPE,
150 BLOCK_LENGTH> IteratorImp;
151 typedef BloombergLP::
152 bslstl::RandomAccessIterator<VALUE_TYPE, IteratorImp>
155 typedef BloombergLP::
156 bslstl::RandomAccessIterator<const VALUE_TYPE, IteratorImp>
337template <class VALUE_TYPE, class ALLOCATOR = allocator<VALUE_TYPE> >
338class deque : public Deque_Base<VALUE_TYPE>
339 , private BloombergLP::
bslalg::ContainerBase<ALLOCATOR> {
346 typedef Deque_Base<VALUE_TYPE> Base;
348 typedef BloombergLP::bslalg::ContainerBase<ALLOCATOR> ContainerBase;
350 typedef BloombergLP::bslalg::DequeImpUtil<VALUE_TYPE,
352 typedef typename Imp::Block Block;
353 typedef typename Imp::BlockPtr BlockPtr;
355 typedef BloombergLP::bslalg::DequeIterator<VALUE_TYPE,
356 BLOCK_LENGTH> IteratorImp;
358 typedef BloombergLP::
359 bslstl::RandomAccessIterator<VALUE_TYPE,
360 IteratorImp> Iterator;
362 typedef BloombergLP::
363 bslstl::RandomAccessIterator<
const VALUE_TYPE,
364 IteratorImp> ConstIterator;
366 typedef Deque_BlockCreator<VALUE_TYPE, ALLOCATOR> BlockCreator;
367 typedef Deque_BlockProctor<VALUE_TYPE, ALLOCATOR> BlockProctor;
368 typedef Deque_ClearGuard<VALUE_TYPE, ALLOCATOR> ClearGuard;
369 typedef Deque_Guard<VALUE_TYPE, ALLOCATOR> Guard;
371 typedef BloombergLP::bslalg::DequePrimitives<VALUE_TYPE,
372 BLOCK_LENGTH> DequePrimitives;
374 typedef BloombergLP::bslma::AllocatorUtil AllocatorUtil;
379 typedef BloombergLP::bslmf::MovableRefUtil MoveUtil;
383 enum RawInit { k_RAW_INIT = 0 };
395 typedef ALLOCATOR allocator_type;
396 typedef typename AllocatorTraits::pointer pointer;
397 typedef typename AllocatorTraits::const_pointer const_pointer;
409 typename Base::const_reference>::value));
426 deque(RawInit,
const allocator_type& allocator);
433 Block *allocateBlock();
439 BlockPtr *allocateBlockPtrs(std::size_t n);
445 void deallocateBlock(Block *p);
452 void deallocateBlockPtrs(BlockPtr *p, std::size_t n);
459 template <
class INPUT_ITERATOR,
class SENTINEL>
460 size_type privateAppend(INPUT_ITERATOR first, SENTINEL last);
468 template <
class INPUT_ITERATOR,
class SENTINEL>
469 size_type privateAppend(INPUT_ITERATOR first,
471 std::input_iterator_tag);
472 template <
class INPUT_ITERATOR,
class SENTINEL>
473 size_type privateAppend(INPUT_ITERATOR first,
475 std::random_access_iterator_tag);
479 void privateAppendDefaultInsertable(
size_type numElements);
483 void privateAppendRaw(
size_type numElements,
const VALUE_TYPE& value);
487 template <
class t_ITERATOR,
class t_SENTINEL>
488 void privateAssign(t_ITERATOR first, t_SENTINEL last);
507 template <
class INTEGER_TYPE>
508 void privateInsertDispatch(
510 INTEGER_TYPE numElements,
512 BloombergLP::bslmf::MatchArithmeticType,
513 BloombergLP::bslmf::Nil);
523 template <
class INPUT_ITERATOR>
525 INPUT_ITERATOR first,
527 BloombergLP::bslmf::MatchAnyType,
528 BloombergLP::bslmf::MatchAnyType);
532 template <
class INPUT_ITERATOR,
class SENTINEL>
534 INPUT_ITERATOR first,
538 template <
class INPUT_ITERATOR,
class SENTINEL>
540 INPUT_ITERATOR first,
542 std::input_iterator_tag);
546 template <
class INPUT_ITERATOR,
class SENTINEL>
548 INPUT_ITERATOR first,
550 std::random_access_iterator_tag);
555 void privateJoinPrepend(deque *other);
560 void privateJoinAppend(deque *other);
567 template <
class INPUT_ITERATOR,
class SENTINEL>
568 size_type privatePrepend(INPUT_ITERATOR first, SENTINEL last);
576 template <
class INPUT_ITERATOR,
class SENTINEL>
577 size_type privatePrepend(INPUT_ITERATOR first,
579 std::input_iterator_tag);
580 template <
class INPUT_ITERATOR,
class SENTINEL>
581 size_type privatePrepend(INPUT_ITERATOR first,
583 std::bidirectional_iterator_tag);
584 template <
class INPUT_ITERATOR,
class SENTINEL>
585 size_type privatePrepend(INPUT_ITERATOR first,
587 std::random_access_iterator_tag);
591 void privatePrependRaw(
size_type numElements,
const VALUE_TYPE& value);
600 void privateSplit(deque *other, IteratorImp pos);
603 template <
class VALUE_TYPE2,
class ALLOCATOR2>
604 friend class Deque_BlockCreator;
606 template <
class VALUE_TYPE2,
class ALLOCATOR2>
607 friend class Deque_BlockProctor;
609 template <
class VALUE_TYPE2,
class ALLOCATOR2>
610 friend class Deque_Guard;
626 explicit deque(
const ALLOCATOR& basicAllocator);
642 const ALLOCATOR& basicAllocator = ALLOCATOR());
658 const VALUE_TYPE& value,
659 const ALLOCATOR& basicAllocator = ALLOCATOR());
683 template <
class INPUT_ITERATOR>
684 deque(INPUT_ITERATOR first,
686 const ALLOCATOR& basicAllocator = ALLOCATOR());
695 template <
class t_RANGE>
699 const ALLOCATOR& basicAllocator =
711 deque(
const deque& original);
721 deque(
const deque& original,
722 const typename type_identity<ALLOCATOR>::type& basicAllocator);
729 deque(BloombergLP::bslmf::MovableRef<deque> original);
743 deque(BloombergLP::bslmf::MovableRef<deque> original,
744 const typename type_identity<ALLOCATOR>::type& basicAllocator);
746#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
758 deque(std::initializer_list<value_type> values,
759 const ALLOCATOR& basicAllocator = ALLOCATOR());
775 deque& operator=(
const deque&
rhs);
791 deque& operator=(BloombergLP::bslmf::MovableRef<deque>
rhs)
793 AllocatorTraits::is_always_equal::value);
795#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
802 deque& operator=(std::initializer_list<value_type> values);
818 template <
class INPUT_ITERATOR>
819 void assign(INPUT_ITERATOR first, INPUT_ITERATOR last);
828#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
834 void assign(std::initializer_list<value_type> values);
842 template <
class t_RANGE>
878 void shrink_to_fit();
887 template <
class t_RANGE>
896 template <
class t_RANGE>
905 void push_front(
const VALUE_TYPE& value);
914 void push_front(BloombergLP::bslmf::MovableRef<value_type> value);
921 void push_back(
const VALUE_TYPE& value);
930 void push_back(BloombergLP::bslmf::MovableRef<value_type> value);
932#if BSLS_COMPILERFEATURES_SIMULATE_VARIADIC_TEMPLATES
935#ifndef BSLSTL_DEQUE_VARIADIC_LIMIT
936#define BSLSTL_DEQUE_VARIADIC_LIMIT 10
938#ifndef BSLSTL_DEQUE_VARIADIC_LIMIT_A
939#define BSLSTL_DEQUE_VARIADIC_LIMIT_A BSLSTL_DEQUE_VARIADIC_LIMIT
941#if BSLSTL_DEQUE_VARIADIC_LIMIT_A >= 0
946#if BSLSTL_DEQUE_VARIADIC_LIMIT_A >= 1
947 template <
class Args_01>
952#if BSLSTL_DEQUE_VARIADIC_LIMIT_A >= 2
953 template <
class Args_01,
960#if BSLSTL_DEQUE_VARIADIC_LIMIT_A >= 3
961 template <
class Args_01,
970#if BSLSTL_DEQUE_VARIADIC_LIMIT_A >= 4
971 template <
class Args_01,
982#if BSLSTL_DEQUE_VARIADIC_LIMIT_A >= 5
983 template <
class Args_01,
996#if BSLSTL_DEQUE_VARIADIC_LIMIT_A >= 6
997 template <
class Args_01,
1012#if BSLSTL_DEQUE_VARIADIC_LIMIT_A >= 7
1013 template <
class Args_01,
1030#if BSLSTL_DEQUE_VARIADIC_LIMIT_A >= 8
1031 template <
class Args_01,
1050#if BSLSTL_DEQUE_VARIADIC_LIMIT_A >= 9
1051 template <
class Args_01,
1072#if BSLSTL_DEQUE_VARIADIC_LIMIT_A >= 10
1073 template <
class Args_01,
1097#if BSLSTL_DEQUE_VARIADIC_LIMIT_A >= 0
1102#if BSLSTL_DEQUE_VARIADIC_LIMIT_A >= 1
1103 template <
class Args_01>
1108#if BSLSTL_DEQUE_VARIADIC_LIMIT_A >= 2
1109 template <
class Args_01,
1116#if BSLSTL_DEQUE_VARIADIC_LIMIT_A >= 3
1117 template <
class Args_01,
1126#if BSLSTL_DEQUE_VARIADIC_LIMIT_A >= 4
1127 template <
class Args_01,
1138#if BSLSTL_DEQUE_VARIADIC_LIMIT_A >= 5
1139 template <
class Args_01,
1152#if BSLSTL_DEQUE_VARIADIC_LIMIT_A >= 6
1153 template <
class Args_01,
1168#if BSLSTL_DEQUE_VARIADIC_LIMIT_A >= 7
1169 template <
class Args_01,
1186#if BSLSTL_DEQUE_VARIADIC_LIMIT_A >= 8
1187 template <
class Args_01,
1206#if BSLSTL_DEQUE_VARIADIC_LIMIT_A >= 9
1207 template <
class Args_01,
1228#if BSLSTL_DEQUE_VARIADIC_LIMIT_A >= 10
1229 template <
class Args_01,
1255 template <
class... Args>
1259 template <
class... Args>
1265#if BSLS_COMPILERFEATURES_SIMULATE_VARIADIC_TEMPLATES
1268#ifndef BSLSTL_DEQUE_VARIADIC_LIMIT
1269#define BSLSTL_DEQUE_VARIADIC_LIMIT 10
1271#ifndef BSLSTL_DEQUE_VARIADIC_LIMIT_B
1272#define BSLSTL_DEQUE_VARIADIC_LIMIT_B BSLSTL_DEQUE_VARIADIC_LIMIT
1274#if BSLSTL_DEQUE_VARIADIC_LIMIT_B >= 0
1278#if BSLSTL_DEQUE_VARIADIC_LIMIT_B >= 1
1279 template <
class Args_01>
1284#if BSLSTL_DEQUE_VARIADIC_LIMIT_B >= 2
1285 template <
class Args_01,
1292#if BSLSTL_DEQUE_VARIADIC_LIMIT_B >= 3
1293 template <
class Args_01,
1302#if BSLSTL_DEQUE_VARIADIC_LIMIT_B >= 4
1303 template <
class Args_01,
1314#if BSLSTL_DEQUE_VARIADIC_LIMIT_B >= 5
1315 template <
class Args_01,
1328#if BSLSTL_DEQUE_VARIADIC_LIMIT_B >= 6
1329 template <
class Args_01,
1344#if BSLSTL_DEQUE_VARIADIC_LIMIT_B >= 7
1345 template <
class Args_01,
1362#if BSLSTL_DEQUE_VARIADIC_LIMIT_B >= 8
1363 template <
class Args_01,
1382#if BSLSTL_DEQUE_VARIADIC_LIMIT_B >= 9
1383 template <
class Args_01,
1404#if BSLSTL_DEQUE_VARIADIC_LIMIT_B >= 10
1405 template <
class Args_01,
1431 template <
class... Args>
1473 BloombergLP::bslmf::MovableRef<value_type> value);
1489 const VALUE_TYPE& value);
1509 template <
class INPUT_ITERATOR>
1511 INPUT_ITERATOR first,
1512 INPUT_ITERATOR last);
1514#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
1528 std::initializer_list<value_type> values);
1536 template <
class t_RANGE>
1577 void swap(deque<VALUE_TYPE, ALLOCATOR>& other)
1579 AllocatorTraits::is_always_equal::value);
1603#ifdef BSLS_COMPILERFEATURES_SUPPORT_CTAD
1615 class = bsl::enable_if_t<
1616 bsl::is_convertible_v<
1619 class = bsl::enable_if_t<bsl::is_convertible_v<ALLOC *, DEFAULT_ALLOCATOR>>
1621deque(SIZE_TYPE, VALUE, ALLOC *) -> deque<VALUE>;
1626 class INPUT_ITERATOR,
1628 typename BloombergLP::bslstl::IteratorUtil::IterVal_t<INPUT_ITERATOR>
1630deque(INPUT_ITERATOR, INPUT_ITERATOR) -> deque<VALUE>;
1637 class INPUT_ITERATOR,
1640 typename BloombergLP::bslstl::IteratorUtil::IterVal_t<INPUT_ITERATOR>,
1641 class = bsl::enable_if_t<bsl::IsStdAllocator_v<ALLOCATOR>>>
1642deque(INPUT_ITERATOR, INPUT_ITERATOR, ALLOCATOR) -> deque<VALUE, ALLOCATOR>;
1649 class INPUT_ITERATOR,
1652 typename BloombergLP::bslstl::IteratorUtil::IterVal_t<INPUT_ITERATOR>,
1654 class = bsl::enable_if_t<bsl::is_convertible_v<ALLOC *, DEFAULT_ALLOCATOR>>
1656deque(INPUT_ITERATOR, INPUT_ITERATOR, ALLOC *)
1667 class = bsl::enable_if_t<bsl::is_convertible_v<ALLOC *, DEFAULT_ALLOCATOR>>
1669deque(std::initializer_list<VALUE>, ALLOC *)
1672#if defined(BSLS_LIBRARYFEATURES_HAS_CPP20_CONCEPTS) \
1673 && defined(BSLS_LIBRARYFEATURES_HAS_CPP20_RANGES)
1676template <ranges::input_range t_RANGE,
1678 allocator<ranges::range_value_t<t_RANGE>>>
1679deque(from_range_t, t_RANGE&&, t_ALLOCATOR = t_ALLOCATOR())
1680-> deque<ranges::range_value_t<t_RANGE>, t_ALLOCATOR>;
1694template <
class VALUE_TYPE,
class ALLOCATOR>
1696 const deque<VALUE_TYPE, ALLOCATOR>&
rhs);
1698#ifndef BSLS_COMPILERFEATURES_SUPPORT_THREE_WAY_COMPARISON
1707template <
class VALUE_TYPE,
class ALLOCATOR>
1709 const deque<VALUE_TYPE, ALLOCATOR>&
rhs);
1712#ifdef BSLALG_SYNTHTHREEWAYUTIL_AVAILABLE
1717template <
class VALUE_TYPE,
class ALLOCATOR>
1718BloombergLP::bslalg::SynthThreeWayUtil::Result<VALUE_TYPE> operator<=>(
1719 const deque<VALUE_TYPE, ALLOCATOR>&
lhs,
1720 const deque<VALUE_TYPE, ALLOCATOR>&
rhs);
1735template <
class VALUE_TYPE,
class ALLOCATOR>
1737 const deque<VALUE_TYPE, ALLOCATOR>&
rhs);
1747template <
class VALUE_TYPE,
class ALLOCATOR>
1749 const deque<VALUE_TYPE, ALLOCATOR>&
rhs);
1759template <
class VALUE_TYPE,
class ALLOCATOR>
1761 const deque<VALUE_TYPE, ALLOCATOR>&
rhs);
1771template <
class VALUE_TYPE,
class ALLOCATOR>
1773 const deque<VALUE_TYPE, ALLOCATOR>&
rhs);
1781template <
class VALUE_TYPE,
class ALLOCATOR,
class BDE_OTHER_TYPE>
1782typename deque<VALUE_TYPE, ALLOCATOR>::size_type
1783erase(deque<VALUE_TYPE, ALLOCATOR>& deq,
const BDE_OTHER_TYPE& value);
1787template <
class VALUE_TYPE,
class ALLOCATOR,
class PREDICATE>
1788typename deque<VALUE_TYPE, ALLOCATOR>::size_type
1789erase_if(deque<VALUE_TYPE, ALLOCATOR>& deq, PREDICATE predicate);
1805template <
class VALUE_TYPE,
class ALLOCATOR>
1806void swap(deque<VALUE_TYPE, ALLOCATOR>& a, deque<VALUE_TYPE, ALLOCATOR>& b)
1821template <
class VALUE_TYPE,
class ALLOCATOR>
1822class Deque_BlockCreator {
1826 BLOCK_LENGTH = Deque_BlockLengthCalcUtil<VALUE_TYPE>::BLOCK_LENGTH
1829 typedef BloombergLP::bslalg::DequeImpUtil<VALUE_TYPE,
1831 typedef typename Imp::Block Block;
1832 typedef typename Imp::BlockPtr BlockPtr;
1833 typedef std::size_t size_type;
1836 deque<VALUE_TYPE, ALLOCATOR> *d_deque_p;
1837 BlockPtr *d_boundary_p;
1841 Deque_BlockCreator(
const Deque_BlockCreator&);
1842 Deque_BlockCreator& operator=(
const Deque_BlockCreator&);
1849 Deque_BlockCreator(deque<VALUE_TYPE, ALLOCATOR> *deque);
1853 ~Deque_BlockCreator();
1860 void insertAtFront(size_type n);
1865 void insertAtBack(size_type n);
1875 BlockPtr *reserveBlockSlots(size_type numNewBlocks,
bool atFront);
1893template <
class VALUE_TYPE,
class ALLOCATOR>
1894class Deque_BlockProctor {
1898 BLOCK_LENGTH = Deque_BlockLengthCalcUtil<VALUE_TYPE>::BLOCK_LENGTH
1901 typedef BloombergLP::bslalg::DequeImpUtil<VALUE_TYPE,
1904 typedef typename Imp::BlockPtr BlockPtr;
1907 deque<VALUE_TYPE, ALLOCATOR> *d_deque_p;
1909 BlockPtr *d_boundary_p;
1919 Deque_BlockProctor(
const Deque_BlockProctor&);
1920 Deque_BlockProctor& operator=(
const Deque_BlockProctor&);
1930 Deque_BlockProctor(deque<VALUE_TYPE, ALLOCATOR> *deque,
bool atFront);
1936 ~Deque_BlockProctor();
1954template <
class VALUE_TYPE,
class ALLOCATOR>
1955class Deque_ClearGuard {
1958 typedef BloombergLP::bslalg::ContainerBase<ALLOCATOR> ContainerBase;
1961 deque<VALUE_TYPE, ALLOCATOR> *d_deque_p;
1965 Deque_ClearGuard(
const Deque_ClearGuard&);
1966 Deque_ClearGuard& operator=(
const Deque_ClearGuard&);
1973 Deque_ClearGuard(deque<VALUE_TYPE, ALLOCATOR> *deque);
1977 ~Deque_ClearGuard();
2002template <
class VALUE_TYPE,
class ALLOCATOR>
2007 BLOCK_LENGTH = Deque_BlockLengthCalcUtil<VALUE_TYPE>::BLOCK_LENGTH
2010 typedef BloombergLP::bslalg::DequeIterator<VALUE_TYPE,
2011 BLOCK_LENGTH> IteratorImp;
2012 typedef BloombergLP::bslalg::DequePrimitives<VALUE_TYPE,
2013 BLOCK_LENGTH> DequePrimitives;
2016 deque<VALUE_TYPE, ALLOCATOR> *d_deque_p;
2017 std::size_t d_count;
2022 Deque_Guard(
const Deque_Guard&);
2023 Deque_Guard& operator=(
const Deque_Guard&);
2031 Deque_Guard(deque<VALUE_TYPE, ALLOCATOR> *deque,
bool isTail);
2077template <class VALUE_TYPE>
2079typename Deque_Base<VALUE_TYPE>::iterator
2085template <
class VALUE_TYPE>
2087typename Deque_Base<VALUE_TYPE>::iterator
2093template <
class VALUE_TYPE>
2095typename Deque_Base<VALUE_TYPE>::reverse_iterator
2098 return reverse_iterator(
end());
2101template <
class VALUE_TYPE>
2103typename Deque_Base<VALUE_TYPE>::reverse_iterator
2106 return reverse_iterator(
begin());
2109template <
class VALUE_TYPE>
2111typename Deque_Base<VALUE_TYPE>::reference
2112Deque_Base<VALUE_TYPE>::operator[](size_type position)
2116 return *(
begin() + position);
2119template <
class VALUE_TYPE>
2120typename Deque_Base<VALUE_TYPE>::reference
2121Deque_Base<VALUE_TYPE>::at(size_type position)
2126 BloombergLP::bslstl::StdExceptUtil::throwOutOfRange(
2127 "deque<...>::at(n): invalid position");
2129 return *(
begin() + position);
2132template <
class VALUE_TYPE>
2134typename Deque_Base<VALUE_TYPE>::reference
2135Deque_Base<VALUE_TYPE>::front()
2142template <
class VALUE_TYPE>
2144typename Deque_Base<VALUE_TYPE>::reference
2145Deque_Base<VALUE_TYPE>::back()
2149 IteratorImp backIterator = d_finish;
2151 return *backIterator;
2155template <
class VALUE_TYPE>
2157typename Deque_Base<VALUE_TYPE>::const_iterator
2163template <
class VALUE_TYPE>
2165typename Deque_Base<VALUE_TYPE>::const_iterator
2171template <
class VALUE_TYPE>
2173typename Deque_Base<VALUE_TYPE>::const_iterator
2179template <
class VALUE_TYPE>
2181typename Deque_Base<VALUE_TYPE>::const_iterator
2187template <
class VALUE_TYPE>
2189typename Deque_Base<VALUE_TYPE>::const_reverse_iterator
2192 return const_reverse_iterator(
end());
2195template <
class VALUE_TYPE>
2197typename Deque_Base<VALUE_TYPE>::const_reverse_iterator
2200 return const_reverse_iterator(
end());
2203template <
class VALUE_TYPE>
2205typename Deque_Base<VALUE_TYPE>::const_reverse_iterator
2208 return const_reverse_iterator(
begin());
2211template <
class VALUE_TYPE>
2213typename Deque_Base<VALUE_TYPE>::const_reverse_iterator
2216 return const_reverse_iterator(
begin());
2219template <
class VALUE_TYPE>
2221typename Deque_Base<VALUE_TYPE>::size_type
2224 return d_finish - d_start;
2227template <
class VALUE_TYPE>
2228typename Deque_Base<VALUE_TYPE>::size_type
2239 if (d_start.blockPtr() > d_blocks_p) {
2242 if (d_finish.blockPtr() < d_blocks_p + d_blocksLength - 1) {
2243 d_blocks_p[d_blocksLength - 1] = 0;
2246 const IteratorImp first(d_blocks_p);
2251 IteratorImp last(d_blocks_p + d_blocksLength - 1);
2252 last += BLOCK_LENGTH - 1;
2257 const size_type frontCapacity = d_finish - first;
2258 const size_type backCapacity = last - d_start;
2263 return frontCapacity < backCapacity ? frontCapacity : backCapacity;
2266template <
class VALUE_TYPE>
2270 return d_start == d_finish;
2273template <
class VALUE_TYPE>
2275typename Deque_Base<VALUE_TYPE>::const_reference
2276Deque_Base<VALUE_TYPE>::operator[](size_type position)
const
2280 return *(
begin() + position);
2283template <
class VALUE_TYPE>
2284typename Deque_Base<VALUE_TYPE>::const_reference
2285Deque_Base<VALUE_TYPE>::at(size_type position)
const
2290 BloombergLP::bslstl::StdExceptUtil::throwOutOfRange(
2291 "const deque<...>::at(n): invalid position");
2293 return *(
begin() + position);
2296template <
class VALUE_TYPE>
2298typename Deque_Base<VALUE_TYPE>::const_reference
2299Deque_Base<VALUE_TYPE>::front()
const
2306template <
class VALUE_TYPE>
2308typename Deque_Base<VALUE_TYPE>::const_reference
2309Deque_Base<VALUE_TYPE>::back()
const
2313 IteratorImp backIterator = d_finish;
2315 return *backIterator;
2323template <
class VALUE_TYPE,
class ALLOCATOR>
2325deque<VALUE_TYPE, ALLOCATOR>::deque(RawInit,
const ALLOCATOR& allocator)
2326: Deque_Base<VALUE_TYPE>()
2327, ContainerBase(allocator)
2329 this->d_blocks_p = 0;
2333template <
class VALUE_TYPE,
class ALLOCATOR>
2335typename deque<VALUE_TYPE, ALLOCATOR>::Block *
2336deque<VALUE_TYPE, ALLOCATOR>::allocateBlock()
2338 return AllocatorUtil::allocateObject<Block>(this->allocatorRef());
2341template <
class VALUE_TYPE,
class ALLOCATOR>
2343typename deque<VALUE_TYPE, ALLOCATOR>::BlockPtr *
2344deque<VALUE_TYPE, ALLOCATOR>::allocateBlockPtrs(std::size_t n)
2346 return AllocatorUtil::allocateObject<BlockPtr>(this->allocatorRef(), n);
2349template <
class VALUE_TYPE,
class ALLOCATOR>
2351void deque<VALUE_TYPE, ALLOCATOR>::deallocateBlock(Block *p)
2353 AllocatorUtil::deallocateObject(this->allocatorRef(), p);
2356template <
class VALUE_TYPE,
class ALLOCATOR>
2359deque<VALUE_TYPE, ALLOCATOR>::deallocateBlockPtrs(BlockPtr *p, std::size_t n)
2361 AllocatorUtil::deallocateObject(this->allocatorRef(), p, n);
2364template <
class VALUE_TYPE,
class ALLOCATOR>
2365template <
class INPUT_ITERATOR,
class SENTINEL>
2367typename deque<VALUE_TYPE, ALLOCATOR>::size_type
2368deque<VALUE_TYPE, ALLOCATOR>::privateAppend(INPUT_ITERATOR first,
2371 if (first == last) {
2374 typedef typename iterator_traits<INPUT_ITERATOR>::iterator_category Tag;
2375 return privateAppend(first, last, Tag());
2378template <
class VALUE_TYPE,
class ALLOCATOR>
2379template <
class INPUT_ITERATOR,
class SENTINEL>
2380typename deque<VALUE_TYPE, ALLOCATOR>::size_type
2381deque<VALUE_TYPE, ALLOCATOR>::privateAppend(
2382 INPUT_ITERATOR first,
2384 std::random_access_iterator_tag)
2386 BlockCreator newBlocks(
this);
2387 Guard guard(
this,
true);
2389 const size_type numElements =
2390 BloombergLP::bslstl::IteratorUtil::insertDistance(first, last);
2392 numElements > max_size() - this->
size())) {
2395 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
2396 "deque<...>::insert(pos,n,v): deque too big");
2399 for ( ; first != last; ++first) {
2400 IteratorImp insertPoint = guard.end();
2408 if (1 == insertPoint.remainingInBlock()) {
2409 newBlocks.insertAtBack(1);
2410 insertPoint = guard.end();
2413 AllocatorTraits::construct(this->allocatorRef(),
2419 this->d_finish += guard.count();
2425template <
class VALUE_TYPE,
class ALLOCATOR>
2426template <
class INPUT_ITERATOR,
class SENTINEL>
2427typename deque<VALUE_TYPE, ALLOCATOR>::size_type
2428deque<VALUE_TYPE, ALLOCATOR>::privateAppend(INPUT_ITERATOR first,
2430 std::input_iterator_tag)
2432 BlockCreator newBlocks(
this);
2433 Guard guard(
this,
true);
2435 size_type numElements = 0;
2436 size_type maxNumElements = max_size() - this->
size();
2437 for ( ; first != last; ++first) {
2440 numElements > maxNumElements)) {
2443 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
2444 "deque<...>::insert(pos,n,v): deque too big");
2446 IteratorImp insertPoint = guard.end();
2454 if (1 == insertPoint.remainingInBlock()) {
2455 newBlocks.insertAtBack(1);
2456 insertPoint = guard.end();
2460 AllocatorTraits::construct(this->allocatorRef(),
2466 this->d_finish += guard.count();
2472template <
class VALUE_TYPE,
class ALLOCATOR>
2473void deque<VALUE_TYPE, ALLOCATOR>::privateAppendDefaultInsertable(
2474 size_type numElements)
2479 size_type numNewBlocks = (this->d_finish.offsetInBlock() + numElements) /
2481 BlockCreator newBlocks(
this);
2482 newBlocks.insertAtBack(numNewBlocks);
2483 DequePrimitives::valueInititalizeN(&this->d_finish,
2486 this->allocatorRef());
2489template <
class VALUE_TYPE,
class ALLOCATOR>
2490void deque<VALUE_TYPE, ALLOCATOR>::privateAppendRaw(
2491 size_type numElements,
2492 const VALUE_TYPE& value)
2497 size_type numNewBlocks = (this->d_finish.offsetInBlock() + numElements) /
2499 BlockCreator newBlocks(
this);
2500 newBlocks.insertAtBack(numNewBlocks);
2502 DequePrimitives::uninitializedFillNBack(&this->d_finish,
2506 this->allocatorRef());
2509template <
class VALUE_TYPE,
class ALLOCATOR>
2510template <
class t_ITERATOR,
class t_SENTINEL>
2511void deque<VALUE_TYPE, ALLOCATOR>::privateAssign(t_ITERATOR first,
2514 typedef typename iterator_traits<t_ITERATOR>::iterator_category Tag;
2523 ClearGuard guard(
this);
2528 for (i = this->d_start; !(i == this->d_finish) && first != last;
2533 if (!(i == this->d_finish)) {
2541 privateAppend(first, last, Tag());
2547template <
class VALUE_TYPE,
class ALLOCATOR>
2548void deque<VALUE_TYPE, ALLOCATOR>::privateInit(size_type numElements)
2550 size_type blocksLength = numElements / BLOCK_LENGTH + 1 +
2551 2 * Imp::BLOCK_ARRAY_PADDING;
2555 this->d_blocks_p = this->allocateBlockPtrs(blocksLength);
2557 this->d_blocksLength = blocksLength;
2562 BlockPtr *firstBlockPtr = &this->d_blocks_p[Imp::BLOCK_ARRAY_PADDING];
2563 *firstBlockPtr = this->allocateBlock();
2573 const int offset =
static_cast<int>(
2574 (BLOCK_LENGTH - 1 - numElements % BLOCK_LENGTH) / 2);
2578 this->d_start = this->d_finish = IteratorImp(
2580 (*firstBlockPtr)->d_data + offset);
2583template <
class VALUE_TYPE,
class ALLOCATOR>
2584template <
class INTEGRAL_TYPE>
2586void deque<VALUE_TYPE, ALLOCATOR>::privateInsertDispatch(
2587 const_iterator position,
2588 INTEGRAL_TYPE numElements,
2589 INTEGRAL_TYPE value,
2590 BloombergLP::bslmf::MatchArithmeticType,
2591 BloombergLP::bslmf::Nil)
2594 static_cast<size_type
>(numElements),
2595 static_cast<VALUE_TYPE
>(value));
2598template <
class VALUE_TYPE,
class ALLOCATOR>
2599template <
class INPUT_ITERATOR>
2600void deque<VALUE_TYPE, ALLOCATOR>::privateInsertDispatch(
2601 const_iterator position,
2602 INPUT_ITERATOR first,
2603 INPUT_ITERATOR last,
2604 BloombergLP::bslmf::MatchAnyType,
2605 BloombergLP::bslmf::MatchAnyType)
2607 typedef typename iterator_traits<INPUT_ITERATOR>::iterator_category Tag;
2609 if (first == last) {
2613 if (position == this->
cbegin()) {
2614 privatePrepend(first, last, Tag());
2618 if (position == this->
cend()) {
2619 privateAppend(first, last, Tag());
2623 privateInsert(position, first, last, Tag());
2626template <
class VALUE_TYPE,
class ALLOCATOR>
2627template <
class INPUT_ITERATOR,
class SENTINEL>
2629void deque<VALUE_TYPE, ALLOCATOR>::privateInsert(const_iterator position,
2630 INPUT_ITERATOR first,
2633 if (first == last) {
2637 typedef typename iterator_traits<INPUT_ITERATOR>::iterator_category Tag;
2638 if (position == this->
cbegin()) {
2639 privatePrepend(first, last, Tag());
2641 else if (position == this->
cend()) {
2642 privateAppend(first, last, Tag());
2645 privateInsert(position, first, last, Tag());
2649template <
class VALUE_TYPE,
class ALLOCATOR>
2650template <
class INPUT_ITERATOR,
class SENTINEL>
2651void deque<VALUE_TYPE, ALLOCATOR>::privateInsert(
2652 const_iterator position,
2653 INPUT_ITERATOR first,
2655 std::input_iterator_tag tag)
2659 iterator pos(position.imp());
2660 const size_type currentSize = this->
size();
2661 const size_type posIdx = pos - this->
begin();
2663 deque temp(k_RAW_INIT, this->get_allocator());
2664 privateSplit(&temp, position.imp());
2666 if (posIdx <= currentSize / 2) {
2668 static_cast<Base *
>(
this),
static_cast<Base *
>(&temp));
2669 privatePrepend(first, last, tag);
2670 privateJoinPrepend(&temp);
2673 privateAppend(first, last, tag);
2674 privateJoinAppend(&temp);
2678template <
class VALUE_TYPE,
class ALLOCATOR>
2679void deque<VALUE_TYPE, ALLOCATOR>::privateSplit(
2680 deque<VALUE_TYPE, ALLOCATOR> *other,
2715 if (pos.blockPtr() == this->d_finish.blockPtr()) {
2719 difference_type numAfter = this->d_finish.valuePtr() - pos.valuePtr();
2720 other->privateInit(numAfter);
2721 BloombergLP::bslalg::ArrayPrimitives::destructiveMove(
2722 other->d_start.valuePtr(),
2724 this->d_finish.valuePtr(),
2725 this->allocatorRef());
2726 other->d_finish += numAfter;
2727 this->d_finish = pos;
2731 if (pos.blockPtr() == this->d_start.blockPtr()) {
2735 difference_type numBefore = pos.valuePtr() - this->d_start.valuePtr();
2736 other->privateInit(numBefore);
2737 BloombergLP::bslalg::ArrayPrimitives::destructiveMove(
2738 other->d_start.valuePtr(),
2739 this->d_start.valuePtr(),
2741 this->allocatorRef());
2742 other->d_finish += numBefore;
2743 this->d_start = pos;
2745 static_cast<Base *
>(
this),
static_cast<Base *
>(other));
2751 difference_type numMoveBlocks = this->d_finish.blockPtr() - pos.blockPtr();
2753 size_type otherBlocksLength = numMoveBlocks + 1 +
2754 2 * Imp::BLOCK_ARRAY_PADDING;
2756 other->d_blocks_p = this->allocateBlockPtrs(otherBlocksLength);
2757 other->d_blocksLength = otherBlocksLength;
2761 Block *newBlock = this->allocateBlock();
2766 std::memcpy(other->d_blocks_p + 1 + Imp::BLOCK_ARRAY_PADDING,
2768 sizeof(BlockPtr) * numMoveBlocks);
2770 other->d_start = IteratorImp(&other->d_blocks_p[
2771 1 + Imp::BLOCK_ARRAY_PADDING]);
2772 other->d_finish = IteratorImp(other->d_start.blockPtr() +
2774 this->d_finish.valuePtr());
2776 BlockPtr *newBlockPtr = pos.blockPtr() + 1;
2777 *newBlockPtr = newBlock;
2778 this->d_finish = IteratorImp(newBlockPtr);
2804 size_type splitOffset = pos.offsetInBlock();
2805 if (splitOffset >= pos.remainingInBlock()) {
2808 value_type *splitValuePtr = newBlock->d_data + splitOffset;
2809 BloombergLP::bslalg::ArrayPrimitives::destructiveMove(
2813 this->allocatorRef());
2819 BloombergLP::bslalg::ArrayPrimitives::destructiveMove(
2823 this->allocatorRef());
2824 *newBlockPtr = *pos.blockPtr();
2825 *pos.blockPtr() = newBlock;
2830 this->d_finish = IteratorImp(&newBlockPtr[-1],
2831 newBlockPtr[-1]->d_data + splitOffset);
2832 other->d_start.previousBlock();
2833 *(other->d_start.blockPtr()) = *newBlockPtr;
2834 other->d_start = IteratorImp(other->d_start.blockPtr(),
2835 other->d_start.blockBegin() + splitOffset);
2838template <
class VALUE_TYPE,
class ALLOCATOR>
2840void deque<VALUE_TYPE, ALLOCATOR>::privateJoinPrepend(
2841 deque<VALUE_TYPE, ALLOCATOR> *other)
2843 privatePrepend(other->begin(),
2845 std::random_access_iterator_tag());
2849 deque<VALUE_TYPE, ALLOCATOR> temp(k_RAW_INIT, other->allocatorRef());
2850 Deque_Util::move(
static_cast<Base *
>(&temp),
static_cast<Base *
>(other));
2853template <
class VALUE_TYPE,
class ALLOCATOR>
2855void deque<VALUE_TYPE, ALLOCATOR>::privateJoinAppend(
2856 deque<VALUE_TYPE, ALLOCATOR> *other)
2858 privateAppend(other->begin(),
2860 std::random_access_iterator_tag());
2864 deque<VALUE_TYPE, ALLOCATOR> temp(k_RAW_INIT, other->allocatorRef());
2865 Deque_Util::move(
static_cast<Base *
>(&temp),
static_cast<Base *
>(other));
2868template <
class VALUE_TYPE,
class ALLOCATOR>
2869template <
class INPUT_ITERATOR,
class SENTINEL>
2870void deque<VALUE_TYPE, ALLOCATOR>::privateInsert(
2871 const_iterator position,
2872 INPUT_ITERATOR first,
2874 std::random_access_iterator_tag tag)
2878 if (position == this->
cbegin()) {
2879 privatePrepend(first, last, tag);
2883 if (position == this->
cend()) {
2884 privateAppend(first, last, tag);
2888 const size_type currentSize = this->
size();
2889 const size_type numElements =
2890 BloombergLP::bslstl::IteratorUtil::insertDistance(first, last);
2892 numElements > max_size() - currentSize)) {
2895 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
2896 "deque<...>::insert(pos,n,v): deque too big");
2899 iterator pos(position.imp());
2900 const size_type posIdx = position - this->
cbegin();
2901 if (posIdx <= currentSize / 2) {
2905 size_type numNewBlocks = (this->d_start.remainingInBlock()
2906 + numElements - 1) / BLOCK_LENGTH;
2907 BlockCreator newBlocks(
this);
2908 newBlocks.insertAtFront(numNewBlocks);
2910 DequePrimitives::insertAndMoveToFront(&this->d_start,
2912 this->d_start + posIdx,
2916 this->allocatorRef());
2921 size_type numNewBlocks = (this->d_finish.offsetInBlock() + numElements)
2923 BlockCreator newBlocks(
this);
2924 newBlocks.insertAtBack(numNewBlocks);
2926 DequePrimitives::insertAndMoveToBack(&this->d_finish,
2928 this->d_start + posIdx,
2932 this->allocatorRef());
2936template <
class VALUE_TYPE,
class ALLOCATOR>
2937void deque<VALUE_TYPE, ALLOCATOR>::privatePrependRaw(
2938 size_type numElements,
2939 const VALUE_TYPE& value)
2944 size_type numNewBlocks = (this->d_start.remainingInBlock() +
2945 numElements - 1) / BLOCK_LENGTH;
2946 BlockCreator newBlocks(
this);
2947 newBlocks.insertAtFront(numNewBlocks);
2949 DequePrimitives::uninitializedFillNFront(&this->d_start,
2953 this->allocatorRef());
2956template <
class VALUE_TYPE,
class ALLOCATOR>
2957template <
class INPUT_ITERATOR,
class SENTINEL>
2959typename deque<VALUE_TYPE, ALLOCATOR>::size_type
2960deque<VALUE_TYPE, ALLOCATOR>::privatePrepend(INPUT_ITERATOR first,
2963 if (first == last) {
2966 typedef typename iterator_traits<INPUT_ITERATOR>::iterator_category Tag;
2967 return privatePrepend(first, last, Tag());
2970template <
class VALUE_TYPE,
class ALLOCATOR>
2971template <
class INPUT_ITERATOR,
class SENTINEL>
2972typename deque<VALUE_TYPE, ALLOCATOR>::size_type
2973deque<VALUE_TYPE, ALLOCATOR>::privatePrepend(INPUT_ITERATOR first,
2975 std::input_iterator_tag tag)
2977 deque temp(k_RAW_INIT, this->get_allocator());
2978 temp.privateInit(this->
size() + 1);
2979 size_type numElements = temp.privateAppend(first, last, tag);
2983 if (numElements > this->
size()) {
2984 Deque_Util::swap((Base *)
this, (Base *)&temp);
2985 privateJoinAppend(&temp);
2988 privateJoinPrepend(&temp);
2994template <
class VALUE_TYPE,
class ALLOCATOR>
2995template <
class INPUT_ITERATOR,
class SENTINEL>
2996typename deque<VALUE_TYPE, ALLOCATOR>::size_type
2997deque<VALUE_TYPE, ALLOCATOR>::privatePrepend(
2998 INPUT_ITERATOR first,
3000 std::bidirectional_iterator_tag)
3003 BlockCreator newBlocks(
this);
3004 Guard guard(
this,
false);
3006 size_type numElements = 0;
3007 size_type maxNumElements = max_size() - this->
size();
3011 numElements > maxNumElements)) {
3014 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
3015 "deque<...>::insert(pos,n,v): deque too big");
3018 IteratorImp insertPoint = guard.begin();
3023 if (insertPoint.valuePtr() == insertPoint.blockBegin()) {
3024 newBlocks.insertAtFront(1);
3025 insertPoint = guard.begin();
3029 AllocatorTraits::construct(this->allocatorRef(),
3033 }
while (first != last);
3035 this->d_start -= guard.count();
3040template <
class VALUE_TYPE,
class ALLOCATOR>
3041template <
class INPUT_ITERATOR,
class SENTINEL>
3042typename deque<VALUE_TYPE, ALLOCATOR>::size_type
3043deque<VALUE_TYPE, ALLOCATOR>::privatePrepend(
3044 INPUT_ITERATOR first,
3046 std::random_access_iterator_tag)
3049 ::canCalculateInsertDistance<INPUT_ITERATOR, SENTINEL>()));
3050 const size_type numElements =
3051 BloombergLP::bslstl::IteratorUtil::insertDistance(first, last);
3053 numElements > max_size() - this->
size())) {
3056 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
3057 "deque<...>::insert(pos,n,v): deque too big");
3060 BlockCreator newBlocks(
this);
3061 Guard guard(
this,
false);
3063#ifdef BSLS_LIBRARYFEATURES_HAS_CPP20_RANGES
3065 if constexpr (std::is_same_v<INPUT_ITERATOR, SENTINEL>) {
3069 end = first + numElements;
3073 INPUT_ITERATOR
end = last;
3076 IteratorImp insertPoint = guard.begin();
3081 if (insertPoint.valuePtr() == insertPoint.blockBegin()) {
3082 newBlocks.insertAtFront(1);
3083 insertPoint = guard.begin();
3087 AllocatorTraits::construct(this->allocatorRef(),
3091 }
while (first != end);
3093 this->d_start -= guard.count();
3099template <
class VALUE_TYPE,
class ALLOCATOR>
3100deque<VALUE_TYPE, ALLOCATOR>::deque()
3101: Deque_Base<VALUE_TYPE>()
3102, ContainerBase(ALLOCATOR())
3104 deque temp(k_RAW_INIT, this->get_allocator());
3105 temp.privateInit(0);
3106 Deque_Util::move(
static_cast<Base *
>(
this),
static_cast<Base *
>(&temp));
3109template <
class VALUE_TYPE,
class ALLOCATOR>
3110deque<VALUE_TYPE, ALLOCATOR>::deque(
const ALLOCATOR& basicAllocator)
3111: Deque_Base<VALUE_TYPE>()
3112, ContainerBase(basicAllocator)
3114 deque temp(k_RAW_INIT, this->get_allocator());
3115 temp.privateInit(0);
3116 Deque_Util::move(
static_cast<Base *
>(
this),
static_cast<Base *
>(&temp));
3119template <
class VALUE_TYPE,
class ALLOCATOR>
3120deque<VALUE_TYPE, ALLOCATOR>::deque(size_type numElements,
3121 const ALLOCATOR& basicAllocator)
3122: Deque_Base<VALUE_TYPE>()
3123, ContainerBase(basicAllocator)
3128 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
3129 "deque<...>::deque(n): deque too big");
3131 deque temp(k_RAW_INIT, this->get_allocator());
3132 temp.privateInit(numElements);
3133 temp.privateAppendDefaultInsertable(numElements);
3134 Deque_Util::move(
static_cast<Base *
>(
this),
static_cast<Base *
>(&temp));
3137template <
class VALUE_TYPE,
class ALLOCATOR>
3138deque<VALUE_TYPE, ALLOCATOR>::deque(size_type numElements,
3139 const VALUE_TYPE& value,
3140 const ALLOCATOR& basicAllocator)
3141: Deque_Base<VALUE_TYPE>()
3142, ContainerBase(basicAllocator)
3147 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
3148 "deque<...>::deque(n,v): deque too big");
3150 deque temp(k_RAW_INIT, this->get_allocator());
3151 temp.privateInit(numElements);
3152 temp.privateAppendRaw(numElements, value);
3153 Deque_Util::move(
static_cast<Base *
>(
this),
static_cast<Base *
>(&temp));
3156template <
class VALUE_TYPE,
class ALLOCATOR>
3157template <
class INPUT_ITERATOR>
3158deque<VALUE_TYPE, ALLOCATOR>::deque(INPUT_ITERATOR first,
3159 INPUT_ITERATOR last,
3160 const ALLOCATOR& basicAllocator)
3161: Deque_Base<VALUE_TYPE>()
3162, ContainerBase(basicAllocator)
3164 deque temp(k_RAW_INIT, this->get_allocator());
3165 temp.privateInit(0);
3166 temp.insert(temp.begin(), first, last);
3167 Deque_Util::move(
static_cast<Base *
>(
this),
static_cast<Base *
>(&temp));
3170template <
class VALUE_TYPE,
class ALLOCATOR>
3171template <
class t_RANGE>
3173deque<VALUE_TYPE, ALLOCATOR>::deque(
3176 const ALLOCATOR& basicAllocator)
3177: Deque_Base<VALUE_TYPE>()
3178, ContainerBase(basicAllocator)
3180 deque temp(k_RAW_INIT, this->get_allocator());
3181 temp.privateInit(0);
3183 Deque_Util::move(
static_cast<Base *
>(
this),
static_cast<Base *
>(&temp));
3186template <
class VALUE_TYPE,
class ALLOCATOR>
3187deque<VALUE_TYPE, ALLOCATOR>::deque(
const deque& original)
3188: Deque_Base<VALUE_TYPE>()
3189, ContainerBase(AllocatorTraits::select_on_container_copy_construction(
3190 original.get_allocator()))
3192 deque temp(k_RAW_INIT, this->get_allocator());
3193 temp.privateInit(original.size());
3194 temp.privateAppend(original.begin(),
3196 std::random_access_iterator_tag());
3197 Deque_Util::move(
static_cast<Base *
>(
this),
static_cast<Base *
>(&temp));
3200template <
class VALUE_TYPE,
class ALLOCATOR>
3201deque<VALUE_TYPE, ALLOCATOR>::deque(
3202 const deque& original,
3203 const typename type_identity<ALLOCATOR>::type& basicAllocator)
3204: Deque_Base<VALUE_TYPE>()
3205, ContainerBase(basicAllocator)
3207 deque temp(k_RAW_INIT, this->get_allocator());
3208 temp.privateInit(original.size());
3209 temp.privateAppend(original.begin(),
3211 std::random_access_iterator_tag());
3212 Deque_Util::move(
static_cast<Base *
>(
this),
static_cast<Base *
>(&temp));
3215template <
class VALUE_TYPE,
class ALLOCATOR>
3216deque<VALUE_TYPE, ALLOCATOR>::deque(
3217 BloombergLP::bslmf::MovableRef<deque> original)
3218: Deque_Base<VALUE_TYPE>()
3219, ContainerBase(MoveUtil::access(original).get_allocator())
3221 deque temp(k_RAW_INIT, this->get_allocator());
3222 temp.privateInit(0);
3223 Deque_Util::move(
static_cast<Base *
>(
this),
static_cast<Base *
>(&temp));
3225 deque& lvalue = original;
3226 Deque_Util::swap(
static_cast<Base *
>(
this),
static_cast<Base *
>(&lvalue));
3229template <
class VALUE_TYPE,
class ALLOCATOR>
3230deque<VALUE_TYPE, ALLOCATOR>::deque(
3231 BloombergLP::bslmf::MovableRef<deque> original,
3232 const typename type_identity<ALLOCATOR>::type& basicAllocator)
3233: Deque_Base<VALUE_TYPE>()
3234, ContainerBase(basicAllocator)
3236 deque temp(k_RAW_INIT, this->get_allocator());
3237 temp.privateInit(0);
3239 deque& lvalue = original;
3242 get_allocator() == lvalue.get_allocator())) {
3243 Deque_Util::move(
static_cast<Base *
>(
this),
3244 static_cast<Base *
>(&temp));
3245 Deque_Util::swap(
static_cast<Base *
>(
this),
3246 static_cast<Base *
>(&lvalue));
3249 const size_type
size = lvalue.size();
3251 for (size_type pos = 0; pos <
size; ++pos) {
3252 temp.push_back(MoveUtil::move(lvalue[pos]));
3254 Deque_Util::move(
static_cast<Base *
>(
this),
3255 static_cast<Base *
>(&temp));
3259#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
3260template <
class VALUE_TYPE,
class ALLOCATOR>
3262deque<VALUE_TYPE, ALLOCATOR>::deque(
3263 std::initializer_list<value_type> values,
3264 const ALLOCATOR& basicAllocator)
3265: deque(values.
begin(), values.
end(), basicAllocator)
3270template <
class VALUE_TYPE,
class ALLOCATOR>
3271deque<VALUE_TYPE, ALLOCATOR>::~deque()
3273 if (0 == this->d_blocks_p) {
3279 if (0 != this->d_start.blockPtr()) {
3284 this->deallocateBlock(*this->d_start.blockPtr());
3288 this->deallocateBlockPtrs(this->d_blocks_p, this->d_blocksLength);
3292template <
class VALUE_TYPE,
class ALLOCATOR>
3293deque<VALUE_TYPE, ALLOCATOR>&
3294deque<VALUE_TYPE, ALLOCATOR>::operator=(
const deque<VALUE_TYPE,ALLOCATOR>& rhs)
3297 AllocatorTraits::propagate_on_container_copy_assignment Propagate;
3300 if (Propagate::value && get_allocator() !=
rhs.get_allocator()) {
3301 deque other(rhs,
rhs.get_allocator());
3303 Deque_Util::swap(
static_cast<Base *
>(
this),
3304 static_cast<Base *
>(&other));
3305 AllocatorUtil::swap(&this->allocatorRef(), &other.allocatorRef(),
3309 size_type origSize = this->size();
3310 size_type rhsSize =
rhs.size();
3313 if (origSize > rhsSize) {
3323 privateAppend(
rhs.begin() + minSize,
3325 std::random_access_iterator_tag());
3330 IteratorImp from =
rhs.d_start;
3331 IteratorImp to = this->d_start;
3332 for (size_type i = 0; i < minSize; ++i) {
3343template <
class VALUE_TYPE,
class ALLOCATOR>
3344deque<VALUE_TYPE, ALLOCATOR>&
3345deque<VALUE_TYPE, ALLOCATOR>::operator=(
3346 BloombergLP::bslmf::MovableRef<deque> rhs)
3348 AllocatorTraits::is_always_equal::value)
3350 deque& lvalue =
rhs;
3353 AllocatorTraits::propagate_on_container_move_assignment Propagate;
3355 if (get_allocator() == lvalue.get_allocator()) {
3356 Deque_Util::swap(
static_cast<Base *
>(
this),
3357 static_cast<Base *
>(&lvalue));
3359 else if (Propagate::value) {
3360 deque other(MoveUtil::move(lvalue));
3361 Deque_Util::swap(
static_cast<Base *
>(
this),
3362 static_cast<Base *
>(&other));
3363 AllocatorUtil::swap(&this->allocatorRef(), &other.allocatorRef(),
3367 deque other(MoveUtil::move(lvalue), get_allocator());
3368 Deque_Util::swap(
static_cast<Base *
>(
this),
3369 static_cast<Base *
>(&other));
3375#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
3376template <
class VALUE_TYPE,
class ALLOCATOR>
3378deque<VALUE_TYPE, ALLOCATOR>&
3379deque<VALUE_TYPE, ALLOCATOR>::operator=(
3380 std::initializer_list<value_type> values)
3382 assign(values.begin(), values.end());
3387template <
class VALUE_TYPE,
class ALLOCATOR>
3388template <
class INPUT_ITERATOR>
3389void deque<VALUE_TYPE, ALLOCATOR>::assign(INPUT_ITERATOR first,
3390 INPUT_ITERATOR last)
3392 privateAssign(first, last);
3395template <
class VALUE_TYPE,
class ALLOCATOR>
3396void deque<VALUE_TYPE, ALLOCATOR>::assign(size_type numElements,
3397 const VALUE_TYPE& value)
3402 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
3403 "deque<...>::assign(n,v): deque too big");
3413 ClearGuard guard(
this);
3415 size_type origSize = this->size();
3418 if (numElements < origSize) {
3419 minSize = numElements;
3420 erase(this->
begin() + numElements, this->end());
3424 privateAppendRaw(numElements - origSize, value);
3427 IteratorImp to = this->d_start;
3428 for (size_type i = 0; i < minSize; ++i) {
3436#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
3437template <
class VALUE_TYPE,
class ALLOCATOR>
3439void deque<VALUE_TYPE, ALLOCATOR>::assign(
3440 std::initializer_list<value_type> values)
3442 assign(values.begin(), values.end());
3446template <
class VALUE_TYPE,
class ALLOCATOR>
3447template <
class t_RANGE>
3449void deque<VALUE_TYPE, ALLOCATOR>::assign_range(
3452 privateAssign(ranges::begin(range), ranges::end(range));
3455template <
class VALUE_TYPE,
class ALLOCATOR>
3456void deque<VALUE_TYPE, ALLOCATOR>::reserve(size_type numElements)
3462 max_size() - (BLOCK_LENGTH - 1))) {
3465 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
3466 "deque<...>::reserve(n): deque too big");
3476 if (this->d_start.blockPtr() > this->d_blocks_p) {
3477 this->d_blocks_p[0] = 0;
3479 if (this->d_finish.blockPtr() < this->d_blocks_p + this->d_blocksLength-1){
3480 this->d_blocks_p[this->d_blocksLength - 1] = 0;
3483 const IteratorImp first(this->d_blocks_p);
3484 IteratorImp last( this->d_blocks_p + this->d_blocksLength - 1);
3485 last += BLOCK_LENGTH - 1;
3487 const size_type frontRoom = this->d_start - first;
3488 const size_type backRoom = last - this->d_finish;
3490 size_type numFrontBlocks = numElements > frontRoom
3491 ? (numElements - frontRoom + BLOCK_LENGTH - 1) /
3494 size_type numBackBlocks = numElements > backRoom
3495 ? (numElements - backRoom + BLOCK_LENGTH - 1) /
3499 if (0 == numFrontBlocks && 0 == numBackBlocks) {
3505 size_type existingSpace = last - first;
3507 (max_size() - existingSpace) / BLOCK_LENGTH
3508 || (existingSpace += numFrontBlocks * BLOCK_LENGTH,
3510 (max_size() - existingSpace) / BLOCK_LENGTH))) {
3513 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
3514 "deque<...>::reserve(n): deque too big");
3520 BlockCreator newBlocks(
this);
3521 newBlocks.reserveBlockSlots(numFrontBlocks,
true);
3522 newBlocks.reserveBlockSlots(numBackBlocks,
false);
3525template <
class VALUE_TYPE,
class ALLOCATOR>
3526void deque<VALUE_TYPE, ALLOCATOR>::resize(size_type newSize)
3531 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
3532 "deque<...>::resize(n): deque too big");
3535 size_type origSize = this->size();
3537 if (newSize <= origSize) {
3542 IteratorImp oldEnd = this->d_finish;
3543 IteratorImp newEnd = this->d_start + newSize;
3544 DequePrimitives::destruct(newEnd, oldEnd, this->allocatorRef());
3546 for (; oldEnd.blockPtr() != newEnd.blockPtr();
3547 oldEnd.previousBlock()) {
3548 this->deallocateBlock(*oldEnd.blockPtr());
3550 this->d_finish = newEnd;
3553 privateAppendDefaultInsertable(newSize - origSize);
3557template <
class VALUE_TYPE,
class ALLOCATOR>
3558void deque<VALUE_TYPE, ALLOCATOR>::resize(size_type newSize,
3559 const VALUE_TYPE& value)
3564 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
3565 "deque<...>::resize(n,v): deque too big");
3568 size_type origSize = this->size();
3570 if (newSize <= origSize) {
3574 privateAppendRaw(newSize - origSize, value);
3578template <
class VALUE_TYPE,
class ALLOCATOR>
3579void deque<VALUE_TYPE, ALLOCATOR>::shrink_to_fit()
3585 const size_type newBlocksLength =
3586 this->d_finish.blockPtr() - this->d_start.blockPtr() + 1;
3588 if (newBlocksLength == this->d_blocksLength) {
3592 const size_type offsetStart = this->d_start.offsetInBlock();
3593 const size_type offsetFinish = this->d_finish.offsetInBlock();
3595 BlockPtr *newBlocks = this->allocateBlockPtrs(newBlocksLength);
3597 std::memmove(newBlocks,
3598 this->d_start.blockPtr(),
3599 newBlocksLength *
sizeof(BlockPtr));
3601 this->deallocateBlockPtrs(this->d_blocks_p, this->d_blocksLength);
3603 this->d_blocks_p = newBlocks;
3604 this->d_blocksLength = newBlocksLength;
3606 this->d_start.setBlock(newBlocks);
3607 this->d_start += offsetStart;
3609 this->d_finish.setBlock(newBlocks + newBlocksLength - 1);
3610 this->d_finish += offsetFinish;
3613template <
class VALUE_TYPE,
class ALLOCATOR>
3614template <
class t_RANGE>
3616void deque<VALUE_TYPE, ALLOCATOR>::append_range(
3619 privateAppend(ranges::begin(range), ranges::end(range));
3622template <
class VALUE_TYPE,
class ALLOCATOR>
3623template <
class t_RANGE>
3625void deque<VALUE_TYPE, ALLOCATOR>::prepend_range(
3628 privatePrepend(ranges::begin(range), ranges::end(range));
3631template <
class VALUE_TYPE,
class ALLOCATOR>
3632void deque<VALUE_TYPE, ALLOCATOR>::push_front(
const VALUE_TYPE& value)
3637 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
3638 "deque<...>::push_front(v): deque too big");
3642 0 == this->d_start.offsetInBlock())) {
3645 BlockCreator newBlocks(
this);
3646 newBlocks.insertAtFront(1);
3648 AllocatorTraits::construct(
3649 this->allocatorRef(), (this->d_start - 1).valuePtr(), value);
3657 AllocatorTraits::construct(
3658 this->allocatorRef(), this->d_start.valuePtr() - 1, value);
3659 this->d_start.valuePtrDecrement();
3663template <
class VALUE_TYPE,
class ALLOCATOR>
3664void deque<VALUE_TYPE, ALLOCATOR>::push_front(
3665 BloombergLP::bslmf::MovableRef<value_type> value)
3670 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
3671 "deque<...>::push_front(v): deque too big");
3674 VALUE_TYPE& lvalue = value;
3677 0 == this->d_start.offsetInBlock())) {
3680 BlockCreator newBlocks(
this);
3681 newBlocks.insertAtFront(1);
3683 AllocatorTraits::construct(this->allocatorRef(),
3684 (this->d_start - 1).valuePtr(),
3685 MoveUtil::move(lvalue));
3692 AllocatorTraits::construct(this->allocatorRef(),
3693 this->d_start.valuePtr() - 1,
3694 MoveUtil::move(lvalue));
3695 this->d_start.valuePtrDecrement();
3699template <
class VALUE_TYPE,
class ALLOCATOR>
3700void deque<VALUE_TYPE, ALLOCATOR>::push_back(
const VALUE_TYPE& value)
3705 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
3706 "deque<...>::push_back(v): deque too big");
3710 1 < this->d_finish.remainingInBlock())) {
3711 AllocatorTraits::construct(
3712 this->allocatorRef(), this->d_finish.valuePtr(), value);
3713 this->d_finish.valuePtrIncrement();
3718 BlockCreator newBlocks(
this);
3719 newBlocks.insertAtBack(1);
3721 AllocatorTraits::construct(
3722 this->allocatorRef(), this->d_finish.valuePtr(), value);
3723 this->d_finish.nextBlock();
3727template <
class VALUE_TYPE,
class ALLOCATOR>
3728void deque<VALUE_TYPE, ALLOCATOR>::push_back(
3729 BloombergLP::bslmf::MovableRef<value_type> value)
3734 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
3735 "deque<...>::push_back(v): deque too big");
3738 VALUE_TYPE& lvalue = value;
3741 1 < this->d_finish.remainingInBlock())) {
3742 AllocatorTraits::construct(this->allocatorRef(),
3743 this->d_finish.valuePtr(),
3744 MoveUtil::move(lvalue));
3745 this->d_finish.valuePtrIncrement();
3750 BlockCreator newBlocks(
this);
3751 newBlocks.insertAtBack(1);
3753 AllocatorTraits::construct(this->allocatorRef(),
3754 this->d_finish.valuePtr(),
3755 MoveUtil::move(lvalue));
3756 this->d_finish.nextBlock();
3760#if BSLS_COMPILERFEATURES_SIMULATE_VARIADIC_TEMPLATES
3763#ifndef BSLSTL_DEQUE_VARIADIC_LIMIT
3764#define BSLSTL_DEQUE_VARIADIC_LIMIT 10
3766#ifndef BSLSTL_DEQUE_VARIADIC_LIMIT_C
3767#define BSLSTL_DEQUE_VARIADIC_LIMIT_C BSLSTL_DEQUE_VARIADIC_LIMIT
3769#if BSLSTL_DEQUE_VARIADIC_LIMIT_C >= 0
3770template <
class VALUE_TYPE,
class ALLOCATOR>
3771typename deque<VALUE_TYPE, ALLOCATOR>::reference
3772deque<VALUE_TYPE, ALLOCATOR>::emplace_front(
3778 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
3779 "deque<...>::emplace_front(args): deque too big");
3783 0 == this->d_start.offsetInBlock())) {
3786 BlockCreator newBlocks(
this);
3787 newBlocks.insertAtFront(1);
3789 AllocatorTraits::construct(
3790 this->allocatorRef(),
3791 (this->d_start - 1).valuePtr());
3796 AllocatorTraits::construct(
3797 this->allocatorRef(),
3798 this->d_start.valuePtr() - 1);
3799 this->d_start.valuePtrDecrement();
3801 return *(this->d_start);
3805#if BSLSTL_DEQUE_VARIADIC_LIMIT_C >= 1
3806template <
class VALUE_TYPE,
class ALLOCATOR>
3807template <
class Args_01>
3808typename deque<VALUE_TYPE, ALLOCATOR>::reference
3809deque<VALUE_TYPE, ALLOCATOR>::emplace_front(
3815 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
3816 "deque<...>::emplace_front(args): deque too big");
3820 0 == this->d_start.offsetInBlock())) {
3823 BlockCreator newBlocks(
this);
3824 newBlocks.insertAtFront(1);
3826 AllocatorTraits::construct(
3827 this->allocatorRef(),
3828 (this->d_start - 1).valuePtr(),
3834 AllocatorTraits::construct(
3835 this->allocatorRef(),
3836 this->d_start.valuePtr() - 1,
3838 this->d_start.valuePtrDecrement();
3840 return *(this->d_start);
3844#if BSLSTL_DEQUE_VARIADIC_LIMIT_C >= 2
3845template <
class VALUE_TYPE,
class ALLOCATOR>
3846template <
class Args_01,
3848typename deque<VALUE_TYPE, ALLOCATOR>::reference
3849deque<VALUE_TYPE, ALLOCATOR>::emplace_front(
3856 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
3857 "deque<...>::emplace_front(args): deque too big");
3861 0 == this->d_start.offsetInBlock())) {
3864 BlockCreator newBlocks(
this);
3865 newBlocks.insertAtFront(1);
3867 AllocatorTraits::construct(
3868 this->allocatorRef(),
3869 (this->d_start - 1).valuePtr(),
3876 AllocatorTraits::construct(
3877 this->allocatorRef(),
3878 this->d_start.valuePtr() - 1,
3881 this->d_start.valuePtrDecrement();
3883 return *(this->d_start);
3887#if BSLSTL_DEQUE_VARIADIC_LIMIT_C >= 3
3888template <
class VALUE_TYPE,
class ALLOCATOR>
3889template <
class Args_01,
3892typename deque<VALUE_TYPE, ALLOCATOR>::reference
3893deque<VALUE_TYPE, ALLOCATOR>::emplace_front(
3901 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
3902 "deque<...>::emplace_front(args): deque too big");
3906 0 == this->d_start.offsetInBlock())) {
3909 BlockCreator newBlocks(
this);
3910 newBlocks.insertAtFront(1);
3912 AllocatorTraits::construct(
3913 this->allocatorRef(),
3914 (this->d_start - 1).valuePtr(),
3922 AllocatorTraits::construct(
3923 this->allocatorRef(),
3924 this->d_start.valuePtr() - 1,
3928 this->d_start.valuePtrDecrement();
3930 return *(this->d_start);
3934#if BSLSTL_DEQUE_VARIADIC_LIMIT_C >= 4
3935template <
class VALUE_TYPE,
class ALLOCATOR>
3936template <
class Args_01,
3940typename deque<VALUE_TYPE, ALLOCATOR>::reference
3941deque<VALUE_TYPE, ALLOCATOR>::emplace_front(
3950 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
3951 "deque<...>::emplace_front(args): deque too big");
3955 0 == this->d_start.offsetInBlock())) {
3958 BlockCreator newBlocks(
this);
3959 newBlocks.insertAtFront(1);
3961 AllocatorTraits::construct(
3962 this->allocatorRef(),
3963 (this->d_start - 1).valuePtr(),
3972 AllocatorTraits::construct(
3973 this->allocatorRef(),
3974 this->d_start.valuePtr() - 1,
3979 this->d_start.valuePtrDecrement();
3981 return *(this->d_start);
3985#if BSLSTL_DEQUE_VARIADIC_LIMIT_C >= 5
3986template <
class VALUE_TYPE,
class ALLOCATOR>
3987template <
class Args_01,
3992typename deque<VALUE_TYPE, ALLOCATOR>::reference
3993deque<VALUE_TYPE, ALLOCATOR>::emplace_front(
4003 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4004 "deque<...>::emplace_front(args): deque too big");
4008 0 == this->d_start.offsetInBlock())) {
4011 BlockCreator newBlocks(
this);
4012 newBlocks.insertAtFront(1);
4014 AllocatorTraits::construct(
4015 this->allocatorRef(),
4016 (this->d_start - 1).valuePtr(),
4026 AllocatorTraits::construct(
4027 this->allocatorRef(),
4028 this->d_start.valuePtr() - 1,
4034 this->d_start.valuePtrDecrement();
4036 return *(this->d_start);
4040#if BSLSTL_DEQUE_VARIADIC_LIMIT_C >= 6
4041template <
class VALUE_TYPE,
class ALLOCATOR>
4042template <
class Args_01,
4048typename deque<VALUE_TYPE, ALLOCATOR>::reference
4049deque<VALUE_TYPE, ALLOCATOR>::emplace_front(
4060 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4061 "deque<...>::emplace_front(args): deque too big");
4065 0 == this->d_start.offsetInBlock())) {
4068 BlockCreator newBlocks(
this);
4069 newBlocks.insertAtFront(1);
4071 AllocatorTraits::construct(
4072 this->allocatorRef(),
4073 (this->d_start - 1).valuePtr(),
4084 AllocatorTraits::construct(
4085 this->allocatorRef(),
4086 this->d_start.valuePtr() - 1,
4093 this->d_start.valuePtrDecrement();
4095 return *(this->d_start);
4099#if BSLSTL_DEQUE_VARIADIC_LIMIT_C >= 7
4100template <
class VALUE_TYPE,
class ALLOCATOR>
4101template <
class Args_01,
4108typename deque<VALUE_TYPE, ALLOCATOR>::reference
4109deque<VALUE_TYPE, ALLOCATOR>::emplace_front(
4121 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4122 "deque<...>::emplace_front(args): deque too big");
4126 0 == this->d_start.offsetInBlock())) {
4129 BlockCreator newBlocks(
this);
4130 newBlocks.insertAtFront(1);
4132 AllocatorTraits::construct(
4133 this->allocatorRef(),
4134 (this->d_start - 1).valuePtr(),
4146 AllocatorTraits::construct(
4147 this->allocatorRef(),
4148 this->d_start.valuePtr() - 1,
4156 this->d_start.valuePtrDecrement();
4158 return *(this->d_start);
4162#if BSLSTL_DEQUE_VARIADIC_LIMIT_C >= 8
4163template <
class VALUE_TYPE,
class ALLOCATOR>
4164template <
class Args_01,
4172typename deque<VALUE_TYPE, ALLOCATOR>::reference
4173deque<VALUE_TYPE, ALLOCATOR>::emplace_front(
4186 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4187 "deque<...>::emplace_front(args): deque too big");
4191 0 == this->d_start.offsetInBlock())) {
4194 BlockCreator newBlocks(
this);
4195 newBlocks.insertAtFront(1);
4197 AllocatorTraits::construct(
4198 this->allocatorRef(),
4199 (this->d_start - 1).valuePtr(),
4212 AllocatorTraits::construct(
4213 this->allocatorRef(),
4214 this->d_start.valuePtr() - 1,
4223 this->d_start.valuePtrDecrement();
4225 return *(this->d_start);
4229#if BSLSTL_DEQUE_VARIADIC_LIMIT_C >= 9
4230template <
class VALUE_TYPE,
class ALLOCATOR>
4231template <
class Args_01,
4240typename deque<VALUE_TYPE, ALLOCATOR>::reference
4241deque<VALUE_TYPE, ALLOCATOR>::emplace_front(
4255 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4256 "deque<...>::emplace_front(args): deque too big");
4260 0 == this->d_start.offsetInBlock())) {
4263 BlockCreator newBlocks(
this);
4264 newBlocks.insertAtFront(1);
4266 AllocatorTraits::construct(
4267 this->allocatorRef(),
4268 (this->d_start - 1).valuePtr(),
4282 AllocatorTraits::construct(
4283 this->allocatorRef(),
4284 this->d_start.valuePtr() - 1,
4294 this->d_start.valuePtrDecrement();
4296 return *(this->d_start);
4300#if BSLSTL_DEQUE_VARIADIC_LIMIT_C >= 10
4301template <
class VALUE_TYPE,
class ALLOCATOR>
4302template <
class Args_01,
4312typename deque<VALUE_TYPE, ALLOCATOR>::reference
4313deque<VALUE_TYPE, ALLOCATOR>::emplace_front(
4328 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4329 "deque<...>::emplace_front(args): deque too big");
4333 0 == this->d_start.offsetInBlock())) {
4336 BlockCreator newBlocks(
this);
4337 newBlocks.insertAtFront(1);
4339 AllocatorTraits::construct(
4340 this->allocatorRef(),
4341 (this->d_start - 1).valuePtr(),
4356 AllocatorTraits::construct(
4357 this->allocatorRef(),
4358 this->d_start.valuePtr() - 1,
4369 this->d_start.valuePtrDecrement();
4371 return *(this->d_start);
4376#if BSLSTL_DEQUE_VARIADIC_LIMIT_C >= 0
4377template <
class VALUE_TYPE,
class ALLOCATOR>
4378typename deque<VALUE_TYPE, ALLOCATOR>::reference
4379deque<VALUE_TYPE, ALLOCATOR>::emplace_back(
4385 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4386 "deque<...>::emplace_back(args): deque too big");
4390 1 < this->d_finish.remainingInBlock())) {
4391 AllocatorTraits::construct(
4392 this->allocatorRef(),
4393 this->d_finish.valuePtr());
4394 this->d_finish.valuePtrIncrement();
4399 BlockCreator newBlocks(
this);
4400 newBlocks.insertAtBack(1);
4402 AllocatorTraits::construct(
4403 this->allocatorRef(),
4404 this->d_finish.valuePtr());
4405 this->d_finish.nextBlock();
4407 return *(this->d_finish - 1);
4411#if BSLSTL_DEQUE_VARIADIC_LIMIT_C >= 1
4412template <
class VALUE_TYPE,
class ALLOCATOR>
4413template <
class Args_01>
4414typename deque<VALUE_TYPE, ALLOCATOR>::reference
4415deque<VALUE_TYPE, ALLOCATOR>::emplace_back(
4421 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4422 "deque<...>::emplace_back(args): deque too big");
4426 1 < this->d_finish.remainingInBlock())) {
4427 AllocatorTraits::construct(
4428 this->allocatorRef(),
4429 this->d_finish.valuePtr(),
4431 this->d_finish.valuePtrIncrement();
4436 BlockCreator newBlocks(
this);
4437 newBlocks.insertAtBack(1);
4439 AllocatorTraits::construct(
4440 this->allocatorRef(),
4441 this->d_finish.valuePtr(),
4443 this->d_finish.nextBlock();
4445 return *(this->d_finish - 1);
4449#if BSLSTL_DEQUE_VARIADIC_LIMIT_C >= 2
4450template <
class VALUE_TYPE,
class ALLOCATOR>
4451template <
class Args_01,
4453typename deque<VALUE_TYPE, ALLOCATOR>::reference
4454deque<VALUE_TYPE, ALLOCATOR>::emplace_back(
4461 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4462 "deque<...>::emplace_back(args): deque too big");
4466 1 < this->d_finish.remainingInBlock())) {
4467 AllocatorTraits::construct(
4468 this->allocatorRef(),
4469 this->d_finish.valuePtr(),
4472 this->d_finish.valuePtrIncrement();
4477 BlockCreator newBlocks(
this);
4478 newBlocks.insertAtBack(1);
4480 AllocatorTraits::construct(
4481 this->allocatorRef(),
4482 this->d_finish.valuePtr(),
4485 this->d_finish.nextBlock();
4487 return *(this->d_finish - 1);
4491#if BSLSTL_DEQUE_VARIADIC_LIMIT_C >= 3
4492template <
class VALUE_TYPE,
class ALLOCATOR>
4493template <
class Args_01,
4496typename deque<VALUE_TYPE, ALLOCATOR>::reference
4497deque<VALUE_TYPE, ALLOCATOR>::emplace_back(
4505 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4506 "deque<...>::emplace_back(args): deque too big");
4510 1 < this->d_finish.remainingInBlock())) {
4511 AllocatorTraits::construct(
4512 this->allocatorRef(),
4513 this->d_finish.valuePtr(),
4517 this->d_finish.valuePtrIncrement();
4522 BlockCreator newBlocks(
this);
4523 newBlocks.insertAtBack(1);
4525 AllocatorTraits::construct(
4526 this->allocatorRef(),
4527 this->d_finish.valuePtr(),
4531 this->d_finish.nextBlock();
4533 return *(this->d_finish - 1);
4537#if BSLSTL_DEQUE_VARIADIC_LIMIT_C >= 4
4538template <
class VALUE_TYPE,
class ALLOCATOR>
4539template <
class Args_01,
4543typename deque<VALUE_TYPE, ALLOCATOR>::reference
4544deque<VALUE_TYPE, ALLOCATOR>::emplace_back(
4553 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4554 "deque<...>::emplace_back(args): deque too big");
4558 1 < this->d_finish.remainingInBlock())) {
4559 AllocatorTraits::construct(
4560 this->allocatorRef(),
4561 this->d_finish.valuePtr(),
4566 this->d_finish.valuePtrIncrement();
4571 BlockCreator newBlocks(
this);
4572 newBlocks.insertAtBack(1);
4574 AllocatorTraits::construct(
4575 this->allocatorRef(),
4576 this->d_finish.valuePtr(),
4581 this->d_finish.nextBlock();
4583 return *(this->d_finish - 1);
4587#if BSLSTL_DEQUE_VARIADIC_LIMIT_C >= 5
4588template <
class VALUE_TYPE,
class ALLOCATOR>
4589template <
class Args_01,
4594typename deque<VALUE_TYPE, ALLOCATOR>::reference
4595deque<VALUE_TYPE, ALLOCATOR>::emplace_back(
4605 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4606 "deque<...>::emplace_back(args): deque too big");
4610 1 < this->d_finish.remainingInBlock())) {
4611 AllocatorTraits::construct(
4612 this->allocatorRef(),
4613 this->d_finish.valuePtr(),
4619 this->d_finish.valuePtrIncrement();
4624 BlockCreator newBlocks(
this);
4625 newBlocks.insertAtBack(1);
4627 AllocatorTraits::construct(
4628 this->allocatorRef(),
4629 this->d_finish.valuePtr(),
4635 this->d_finish.nextBlock();
4637 return *(this->d_finish - 1);
4641#if BSLSTL_DEQUE_VARIADIC_LIMIT_C >= 6
4642template <
class VALUE_TYPE,
class ALLOCATOR>
4643template <
class Args_01,
4649typename deque<VALUE_TYPE, ALLOCATOR>::reference
4650deque<VALUE_TYPE, ALLOCATOR>::emplace_back(
4661 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4662 "deque<...>::emplace_back(args): deque too big");
4666 1 < this->d_finish.remainingInBlock())) {
4667 AllocatorTraits::construct(
4668 this->allocatorRef(),
4669 this->d_finish.valuePtr(),
4676 this->d_finish.valuePtrIncrement();
4681 BlockCreator newBlocks(
this);
4682 newBlocks.insertAtBack(1);
4684 AllocatorTraits::construct(
4685 this->allocatorRef(),
4686 this->d_finish.valuePtr(),
4693 this->d_finish.nextBlock();
4695 return *(this->d_finish - 1);
4699#if BSLSTL_DEQUE_VARIADIC_LIMIT_C >= 7
4700template <
class VALUE_TYPE,
class ALLOCATOR>
4701template <
class Args_01,
4708typename deque<VALUE_TYPE, ALLOCATOR>::reference
4709deque<VALUE_TYPE, ALLOCATOR>::emplace_back(
4721 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4722 "deque<...>::emplace_back(args): deque too big");
4726 1 < this->d_finish.remainingInBlock())) {
4727 AllocatorTraits::construct(
4728 this->allocatorRef(),
4729 this->d_finish.valuePtr(),
4737 this->d_finish.valuePtrIncrement();
4742 BlockCreator newBlocks(
this);
4743 newBlocks.insertAtBack(1);
4745 AllocatorTraits::construct(
4746 this->allocatorRef(),
4747 this->d_finish.valuePtr(),
4755 this->d_finish.nextBlock();
4757 return *(this->d_finish - 1);
4761#if BSLSTL_DEQUE_VARIADIC_LIMIT_C >= 8
4762template <
class VALUE_TYPE,
class ALLOCATOR>
4763template <
class Args_01,
4771typename deque<VALUE_TYPE, ALLOCATOR>::reference
4772deque<VALUE_TYPE, ALLOCATOR>::emplace_back(
4785 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4786 "deque<...>::emplace_back(args): deque too big");
4790 1 < this->d_finish.remainingInBlock())) {
4791 AllocatorTraits::construct(
4792 this->allocatorRef(),
4793 this->d_finish.valuePtr(),
4802 this->d_finish.valuePtrIncrement();
4807 BlockCreator newBlocks(
this);
4808 newBlocks.insertAtBack(1);
4810 AllocatorTraits::construct(
4811 this->allocatorRef(),
4812 this->d_finish.valuePtr(),
4821 this->d_finish.nextBlock();
4823 return *(this->d_finish - 1);
4827#if BSLSTL_DEQUE_VARIADIC_LIMIT_C >= 9
4828template <
class VALUE_TYPE,
class ALLOCATOR>
4829template <
class Args_01,
4838typename deque<VALUE_TYPE, ALLOCATOR>::reference
4839deque<VALUE_TYPE, ALLOCATOR>::emplace_back(
4853 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4854 "deque<...>::emplace_back(args): deque too big");
4858 1 < this->d_finish.remainingInBlock())) {
4859 AllocatorTraits::construct(
4860 this->allocatorRef(),
4861 this->d_finish.valuePtr(),
4871 this->d_finish.valuePtrIncrement();
4876 BlockCreator newBlocks(
this);
4877 newBlocks.insertAtBack(1);
4879 AllocatorTraits::construct(
4880 this->allocatorRef(),
4881 this->d_finish.valuePtr(),
4891 this->d_finish.nextBlock();
4893 return *(this->d_finish - 1);
4897#if BSLSTL_DEQUE_VARIADIC_LIMIT_C >= 10
4898template <
class VALUE_TYPE,
class ALLOCATOR>
4899template <
class Args_01,
4909typename deque<VALUE_TYPE, ALLOCATOR>::reference
4910deque<VALUE_TYPE, ALLOCATOR>::emplace_back(
4925 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4926 "deque<...>::emplace_back(args): deque too big");
4930 1 < this->d_finish.remainingInBlock())) {
4931 AllocatorTraits::construct(
4932 this->allocatorRef(),
4933 this->d_finish.valuePtr(),
4944 this->d_finish.valuePtrIncrement();
4949 BlockCreator newBlocks(
this);
4950 newBlocks.insertAtBack(1);
4952 AllocatorTraits::construct(
4953 this->allocatorRef(),
4954 this->d_finish.valuePtr(),
4965 this->d_finish.nextBlock();
4967 return *(this->d_finish - 1);
4974template <
class VALUE_TYPE,
class ALLOCATOR>
4975template <
class... Args>
4976typename deque<VALUE_TYPE, ALLOCATOR>::reference
4977deque<VALUE_TYPE, ALLOCATOR>::emplace_front(
4983 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
4984 "deque<...>::emplace_front(args): deque too big");
4988 0 == this->d_start.offsetInBlock())) {
4991 BlockCreator newBlocks(
this);
4992 newBlocks.insertAtFront(1);
4994 AllocatorTraits::construct(
4995 this->allocatorRef(),
4996 (this->d_start - 1).valuePtr(),
5002 AllocatorTraits::construct(
5003 this->allocatorRef(),
5004 this->d_start.valuePtr() - 1,
5006 this->d_start.valuePtrDecrement();
5008 return *(this->d_start);
5011template <
class VALUE_TYPE,
class ALLOCATOR>
5012template <
class... Args>
5013typename deque<VALUE_TYPE, ALLOCATOR>::reference
5014deque<VALUE_TYPE, ALLOCATOR>::emplace_back(
5020 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
5021 "deque<...>::emplace_back(args): deque too big");
5025 1 < this->d_finish.remainingInBlock())) {
5026 AllocatorTraits::construct(
5027 this->allocatorRef(),
5028 this->d_finish.valuePtr(),
5030 this->d_finish.valuePtrIncrement();
5035 BlockCreator newBlocks(
this);
5036 newBlocks.insertAtBack(1);
5038 AllocatorTraits::construct(
5039 this->allocatorRef(),
5040 this->d_finish.valuePtr(),
5042 this->d_finish.nextBlock();
5044 return *(this->d_finish - 1);
5049#if BSLS_COMPILERFEATURES_SIMULATE_VARIADIC_TEMPLATES
5052#ifndef BSLSTL_DEQUE_VARIADIC_LIMIT
5053#define BSLSTL_DEQUE_VARIADIC_LIMIT 10
5055#ifndef BSLSTL_DEQUE_VARIADIC_LIMIT_D
5056#define BSLSTL_DEQUE_VARIADIC_LIMIT_D BSLSTL_DEQUE_VARIADIC_LIMIT
5058#if BSLSTL_DEQUE_VARIADIC_LIMIT_D >= 0
5059template <
class VALUE_TYPE,
class ALLOCATOR>
5060typename deque<VALUE_TYPE, ALLOCATOR>::iterator
5061deque<VALUE_TYPE, ALLOCATOR>::emplace(const_iterator position)
5066 if (position == this->
cbegin()) {
5068 return this->
begin();
5071 if (position == this->
cend()) {
5073 return iterator(this->d_finish - 1);
5077 const size_type currentSize = this->size();
5081 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
5082 "deque<...>::emplace(args): deque too big");
5085 iterator pos(position.imp());
5086 const size_type posIdx = position - this->
cbegin();
5087 if (posIdx <= currentSize / 2) {
5088 BlockCreator newBlocks(
this);
5089 if (this->d_start.remainingInBlock() == BLOCK_LENGTH) {
5090 newBlocks.insertAtFront(1);
5093 BlockProctor proctor(
this,
true);
5094 DequePrimitives::emplaceAndMoveToFront(
5097 this->d_start + posIdx,
5098 this->allocatorRef());
5102 BlockCreator newBlocks(
this);
5103 if (this->d_finish.offsetInBlock() == BLOCK_LENGTH - 1) {
5104 newBlocks.insertAtBack(1);
5107 BlockProctor proctor(
this,
false);
5108 DequePrimitives::emplaceAndMoveToBack(
5111 this->d_start + posIdx,
5112 this->allocatorRef());
5115 return this->
begin() + posIdx;
5119#if BSLSTL_DEQUE_VARIADIC_LIMIT_D >= 1
5120template <
class VALUE_TYPE,
class ALLOCATOR>
5121template <
class Args_01>
5122typename deque<VALUE_TYPE, ALLOCATOR>::iterator
5123deque<VALUE_TYPE, ALLOCATOR>::emplace(const_iterator position,
5129 if (position == this->
cbegin()) {
5131 return this->
begin();
5134 if (position == this->
cend()) {
5136 return iterator(this->d_finish - 1);
5140 const size_type currentSize = this->size();
5144 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
5145 "deque<...>::emplace(args): deque too big");
5148 iterator pos(position.imp());
5149 const size_type posIdx = position - this->
cbegin();
5150 if (posIdx <= currentSize / 2) {
5151 BlockCreator newBlocks(
this);
5152 if (this->d_start.remainingInBlock() == BLOCK_LENGTH) {
5153 newBlocks.insertAtFront(1);
5156 BlockProctor proctor(
this,
true);
5157 DequePrimitives::emplaceAndMoveToFront(
5160 this->d_start + posIdx,
5161 this->allocatorRef(),
5166 BlockCreator newBlocks(
this);
5167 if (this->d_finish.offsetInBlock() == BLOCK_LENGTH - 1) {
5168 newBlocks.insertAtBack(1);
5171 BlockProctor proctor(
this,
false);
5172 DequePrimitives::emplaceAndMoveToBack(
5175 this->d_start + posIdx,
5176 this->allocatorRef(),
5180 return this->
begin() + posIdx;
5184#if BSLSTL_DEQUE_VARIADIC_LIMIT_D >= 2
5185template <
class VALUE_TYPE,
class ALLOCATOR>
5186template <
class Args_01,
5188typename deque<VALUE_TYPE, ALLOCATOR>::iterator
5189deque<VALUE_TYPE, ALLOCATOR>::emplace(const_iterator position,
5196 if (position == this->
cbegin()) {
5199 return this->
begin();
5202 if (position == this->
cend()) {
5205 return iterator(this->d_finish - 1);
5209 const size_type currentSize = this->size();
5213 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
5214 "deque<...>::emplace(args): deque too big");
5217 iterator pos(position.imp());
5218 const size_type posIdx = position - this->
cbegin();
5219 if (posIdx <= currentSize / 2) {
5220 BlockCreator newBlocks(
this);
5221 if (this->d_start.remainingInBlock() == BLOCK_LENGTH) {
5222 newBlocks.insertAtFront(1);
5225 BlockProctor proctor(
this,
true);
5226 DequePrimitives::emplaceAndMoveToFront(
5229 this->d_start + posIdx,
5230 this->allocatorRef(),
5236 BlockCreator newBlocks(
this);
5237 if (this->d_finish.offsetInBlock() == BLOCK_LENGTH - 1) {
5238 newBlocks.insertAtBack(1);
5241 BlockProctor proctor(
this,
false);
5242 DequePrimitives::emplaceAndMoveToBack(
5245 this->d_start + posIdx,
5246 this->allocatorRef(),
5251 return this->
begin() + posIdx;
5255#if BSLSTL_DEQUE_VARIADIC_LIMIT_D >= 3
5256template <
class VALUE_TYPE,
class ALLOCATOR>
5257template <
class Args_01,
5260typename deque<VALUE_TYPE, ALLOCATOR>::iterator
5261deque<VALUE_TYPE, ALLOCATOR>::emplace(const_iterator position,
5269 if (position == this->
cbegin()) {
5273 return this->
begin();
5276 if (position == this->
cend()) {
5280 return iterator(this->d_finish - 1);
5284 const size_type currentSize = this->size();
5288 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
5289 "deque<...>::emplace(args): deque too big");
5292 iterator pos(position.imp());
5293 const size_type posIdx = position - this->
cbegin();
5294 if (posIdx <= currentSize / 2) {
5295 BlockCreator newBlocks(
this);
5296 if (this->d_start.remainingInBlock() == BLOCK_LENGTH) {
5297 newBlocks.insertAtFront(1);
5300 BlockProctor proctor(
this,
true);
5301 DequePrimitives::emplaceAndMoveToFront(
5304 this->d_start + posIdx,
5305 this->allocatorRef(),
5312 BlockCreator newBlocks(
this);
5313 if (this->d_finish.offsetInBlock() == BLOCK_LENGTH - 1) {
5314 newBlocks.insertAtBack(1);
5317 BlockProctor proctor(
this,
false);
5318 DequePrimitives::emplaceAndMoveToBack(
5321 this->d_start + posIdx,
5322 this->allocatorRef(),
5328 return this->
begin() + posIdx;
5332#if BSLSTL_DEQUE_VARIADIC_LIMIT_D >= 4
5333template <
class VALUE_TYPE,
class ALLOCATOR>
5334template <
class Args_01,
5338typename deque<VALUE_TYPE, ALLOCATOR>::iterator
5339deque<VALUE_TYPE, ALLOCATOR>::emplace(const_iterator position,
5348 if (position == this->
cbegin()) {
5353 return this->
begin();
5356 if (position == this->
cend()) {
5361 return iterator(this->d_finish - 1);
5365 const size_type currentSize = this->size();
5369 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
5370 "deque<...>::emplace(args): deque too big");
5373 iterator pos(position.imp());
5374 const size_type posIdx = position - this->
cbegin();
5375 if (posIdx <= currentSize / 2) {
5376 BlockCreator newBlocks(
this);
5377 if (this->d_start.remainingInBlock() == BLOCK_LENGTH) {
5378 newBlocks.insertAtFront(1);
5381 BlockProctor proctor(
this,
true);
5382 DequePrimitives::emplaceAndMoveToFront(
5385 this->d_start + posIdx,
5386 this->allocatorRef(),
5394 BlockCreator newBlocks(
this);
5395 if (this->d_finish.offsetInBlock() == BLOCK_LENGTH - 1) {
5396 newBlocks.insertAtBack(1);
5399 BlockProctor proctor(
this,
false);
5400 DequePrimitives::emplaceAndMoveToBack(
5403 this->d_start + posIdx,
5404 this->allocatorRef(),
5411 return this->
begin() + posIdx;
5415#if BSLSTL_DEQUE_VARIADIC_LIMIT_D >= 5
5416template <
class VALUE_TYPE,
class ALLOCATOR>
5417template <
class Args_01,
5422typename deque<VALUE_TYPE, ALLOCATOR>::iterator
5423deque<VALUE_TYPE, ALLOCATOR>::emplace(const_iterator position,
5433 if (position == this->
cbegin()) {
5439 return this->
begin();
5442 if (position == this->
cend()) {
5448 return iterator(this->d_finish - 1);
5452 const size_type currentSize = this->size();
5456 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
5457 "deque<...>::emplace(args): deque too big");
5460 iterator pos(position.imp());
5461 const size_type posIdx = position - this->
cbegin();
5462 if (posIdx <= currentSize / 2) {
5463 BlockCreator newBlocks(
this);
5464 if (this->d_start.remainingInBlock() == BLOCK_LENGTH) {
5465 newBlocks.insertAtFront(1);
5468 BlockProctor proctor(
this,
true);
5469 DequePrimitives::emplaceAndMoveToFront(
5472 this->d_start + posIdx,
5473 this->allocatorRef(),
5482 BlockCreator newBlocks(
this);
5483 if (this->d_finish.offsetInBlock() == BLOCK_LENGTH - 1) {
5484 newBlocks.insertAtBack(1);
5487 BlockProctor proctor(
this,
false);
5488 DequePrimitives::emplaceAndMoveToBack(
5491 this->d_start + posIdx,
5492 this->allocatorRef(),
5500 return this->
begin() + posIdx;
5504#if BSLSTL_DEQUE_VARIADIC_LIMIT_D >= 6
5505template <
class VALUE_TYPE,
class ALLOCATOR>
5506template <
class Args_01,
5512typename deque<VALUE_TYPE, ALLOCATOR>::iterator
5513deque<VALUE_TYPE, ALLOCATOR>::emplace(const_iterator position,
5524 if (position == this->
cbegin()) {
5531 return this->
begin();
5534 if (position == this->
cend()) {
5541 return iterator(this->d_finish - 1);
5545 const size_type currentSize = this->size();
5549 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
5550 "deque<...>::emplace(args): deque too big");
5553 iterator pos(position.imp());
5554 const size_type posIdx = position - this->
cbegin();
5555 if (posIdx <= currentSize / 2) {
5556 BlockCreator newBlocks(
this);
5557 if (this->d_start.remainingInBlock() == BLOCK_LENGTH) {
5558 newBlocks.insertAtFront(1);
5561 BlockProctor proctor(
this,
true);
5562 DequePrimitives::emplaceAndMoveToFront(
5565 this->d_start + posIdx,
5566 this->allocatorRef(),
5576 BlockCreator newBlocks(
this);
5577 if (this->d_finish.offsetInBlock() == BLOCK_LENGTH - 1) {
5578 newBlocks.insertAtBack(1);
5581 BlockProctor proctor(
this,
false);
5582 DequePrimitives::emplaceAndMoveToBack(
5585 this->d_start + posIdx,
5586 this->allocatorRef(),
5595 return this->
begin() + posIdx;
5599#if BSLSTL_DEQUE_VARIADIC_LIMIT_D >= 7
5600template <
class VALUE_TYPE,
class ALLOCATOR>
5601template <
class Args_01,
5608typename deque<VALUE_TYPE, ALLOCATOR>::iterator
5609deque<VALUE_TYPE, ALLOCATOR>::emplace(const_iterator position,
5621 if (position == this->
cbegin()) {
5629 return this->
begin();
5632 if (position == this->
cend()) {
5640 return iterator(this->d_finish - 1);
5644 const size_type currentSize = this->size();
5648 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
5649 "deque<...>::emplace(args): deque too big");
5652 iterator pos(position.imp());
5653 const size_type posIdx = position - this->
cbegin();
5654 if (posIdx <= currentSize / 2) {
5655 BlockCreator newBlocks(
this);
5656 if (this->d_start.remainingInBlock() == BLOCK_LENGTH) {
5657 newBlocks.insertAtFront(1);
5660 BlockProctor proctor(
this,
true);
5661 DequePrimitives::emplaceAndMoveToFront(
5664 this->d_start + posIdx,
5665 this->allocatorRef(),
5676 BlockCreator newBlocks(
this);
5677 if (this->d_finish.offsetInBlock() == BLOCK_LENGTH - 1) {
5678 newBlocks.insertAtBack(1);
5681 BlockProctor proctor(
this,
false);
5682 DequePrimitives::emplaceAndMoveToBack(
5685 this->d_start + posIdx,
5686 this->allocatorRef(),
5696 return this->
begin() + posIdx;
5700#if BSLSTL_DEQUE_VARIADIC_LIMIT_D >= 8
5701template <
class VALUE_TYPE,
class ALLOCATOR>
5702template <
class Args_01,
5710typename deque<VALUE_TYPE, ALLOCATOR>::iterator
5711deque<VALUE_TYPE, ALLOCATOR>::emplace(const_iterator position,
5724 if (position == this->
cbegin()) {
5733 return this->
begin();
5736 if (position == this->
cend()) {
5745 return iterator(this->d_finish - 1);
5749 const size_type currentSize = this->size();
5753 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
5754 "deque<...>::emplace(args): deque too big");
5757 iterator pos(position.imp());
5758 const size_type posIdx = position - this->
cbegin();
5759 if (posIdx <= currentSize / 2) {
5760 BlockCreator newBlocks(
this);
5761 if (this->d_start.remainingInBlock() == BLOCK_LENGTH) {
5762 newBlocks.insertAtFront(1);
5765 BlockProctor proctor(
this,
true);
5766 DequePrimitives::emplaceAndMoveToFront(
5769 this->d_start + posIdx,
5770 this->allocatorRef(),
5782 BlockCreator newBlocks(
this);
5783 if (this->d_finish.offsetInBlock() == BLOCK_LENGTH - 1) {
5784 newBlocks.insertAtBack(1);
5787 BlockProctor proctor(
this,
false);
5788 DequePrimitives::emplaceAndMoveToBack(
5791 this->d_start + posIdx,
5792 this->allocatorRef(),
5803 return this->
begin() + posIdx;
5807#if BSLSTL_DEQUE_VARIADIC_LIMIT_D >= 9
5808template <
class VALUE_TYPE,
class ALLOCATOR>
5809template <
class Args_01,
5818typename deque<VALUE_TYPE, ALLOCATOR>::iterator
5819deque<VALUE_TYPE, ALLOCATOR>::emplace(const_iterator position,
5833 if (position == this->
cbegin()) {
5843 return this->
begin();
5846 if (position == this->
cend()) {
5856 return iterator(this->d_finish - 1);
5860 const size_type currentSize = this->size();
5864 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
5865 "deque<...>::emplace(args): deque too big");
5868 iterator pos(position.imp());
5869 const size_type posIdx = position - this->
cbegin();
5870 if (posIdx <= currentSize / 2) {
5871 BlockCreator newBlocks(
this);
5872 if (this->d_start.remainingInBlock() == BLOCK_LENGTH) {
5873 newBlocks.insertAtFront(1);
5876 BlockProctor proctor(
this,
true);
5877 DequePrimitives::emplaceAndMoveToFront(
5880 this->d_start + posIdx,
5881 this->allocatorRef(),
5894 BlockCreator newBlocks(
this);
5895 if (this->d_finish.offsetInBlock() == BLOCK_LENGTH - 1) {
5896 newBlocks.insertAtBack(1);
5899 BlockProctor proctor(
this,
false);
5900 DequePrimitives::emplaceAndMoveToBack(
5903 this->d_start + posIdx,
5904 this->allocatorRef(),
5916 return this->
begin() + posIdx;
5920#if BSLSTL_DEQUE_VARIADIC_LIMIT_D >= 10
5921template <
class VALUE_TYPE,
class ALLOCATOR>
5922template <
class Args_01,
5932typename deque<VALUE_TYPE, ALLOCATOR>::iterator
5933deque<VALUE_TYPE, ALLOCATOR>::emplace(const_iterator position,
5948 if (position == this->
cbegin()) {
5959 return this->
begin();
5962 if (position == this->
cend()) {
5973 return iterator(this->d_finish - 1);
5977 const size_type currentSize = this->size();
5981 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
5982 "deque<...>::emplace(args): deque too big");
5985 iterator pos(position.imp());
5986 const size_type posIdx = position - this->
cbegin();
5987 if (posIdx <= currentSize / 2) {
5988 BlockCreator newBlocks(
this);
5989 if (this->d_start.remainingInBlock() == BLOCK_LENGTH) {
5990 newBlocks.insertAtFront(1);
5993 BlockProctor proctor(
this,
true);
5994 DequePrimitives::emplaceAndMoveToFront(
5997 this->d_start + posIdx,
5998 this->allocatorRef(),
6012 BlockCreator newBlocks(
this);
6013 if (this->d_finish.offsetInBlock() == BLOCK_LENGTH - 1) {
6014 newBlocks.insertAtBack(1);
6017 BlockProctor proctor(
this,
false);
6018 DequePrimitives::emplaceAndMoveToBack(
6021 this->d_start + posIdx,
6022 this->allocatorRef(),
6035 return this->
begin() + posIdx;
6042template <
class VALUE_TYPE,
class ALLOCATOR>
6043template <
class... Args>
6044typename deque<VALUE_TYPE, ALLOCATOR>::iterator
6045deque<VALUE_TYPE, ALLOCATOR>::emplace(const_iterator position,
6051 if (position == this->
cbegin()) {
6053 return this->
begin();
6056 if (position == this->
cend()) {
6058 return iterator(this->d_finish - 1);
6062 const size_type currentSize = this->size();
6066 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
6067 "deque<...>::emplace(args): deque too big");
6070 iterator pos(position.imp());
6071 const size_type posIdx = position - this->
cbegin();
6072 if (posIdx <= currentSize / 2) {
6073 BlockCreator newBlocks(
this);
6074 if (this->d_start.remainingInBlock() == BLOCK_LENGTH) {
6075 newBlocks.insertAtFront(1);
6078 BlockProctor proctor(
this,
true);
6079 DequePrimitives::emplaceAndMoveToFront(
6082 this->d_start + posIdx,
6083 this->allocatorRef(),
6088 BlockCreator newBlocks(
this);
6089 if (this->d_finish.offsetInBlock() == BLOCK_LENGTH - 1) {
6090 newBlocks.insertAtBack(1);
6093 BlockProctor proctor(
this,
false);
6094 DequePrimitives::emplaceAndMoveToBack(
6097 this->d_start + posIdx,
6098 this->allocatorRef(),
6102 return this->
begin() + posIdx;
6107template <
class VALUE_TYPE,
class ALLOCATOR>
6108void deque<VALUE_TYPE, ALLOCATOR>::pop_front()
6112 BloombergLP::bslma::DestructionUtil::destroy(this->d_start.valuePtr());
6114 if (1 == this->d_start.remainingInBlock()) {
6115 this->deallocateBlock(*this->d_start.blockPtr());
6116 this->d_start.nextBlock();
6120 this->d_start.valuePtrIncrement();
6123template <
class VALUE_TYPE,
class ALLOCATOR>
6124void deque<VALUE_TYPE, ALLOCATOR>::pop_back()
6128 if (0 == this->d_finish.offsetInBlock()) {
6130 BloombergLP::bslma::DestructionUtil::destroy(
6131 this->d_finish.valuePtr());
6132 this->deallocateBlock(this->d_finish.blockPtr()[1]);
6136 this->d_finish.valuePtrDecrement();
6137 BloombergLP::bslma::DestructionUtil::destroy(this->d_finish.valuePtr());
6140template <
class VALUE_TYPE,
class ALLOCATOR>
6141typename deque<VALUE_TYPE, ALLOCATOR>::iterator
6142deque<VALUE_TYPE, ALLOCATOR>::insert(const_iterator position,
6143 const VALUE_TYPE& value)
6148 if (position == this->
cbegin()) {
6150 return this->
begin();
6153 if (position == this->
cend()) {
6155 return iterator(this->d_finish - 1);
6161 const size_type currentSize = this->size();
6165 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
6166 "deque<...>::insert(pos,n,v): deque too big");
6169 iterator pos(position.imp());
6170 const size_type posIdx = position - this->
cbegin();
6171 if (posIdx <= currentSize / 2) {
6172 BlockCreator newBlocks(
this);
6173 if (this->d_start.remainingInBlock() == BLOCK_LENGTH) {
6174 newBlocks.insertAtFront(1);
6176 DequePrimitives::insertAndMoveToFront(&this->d_start,
6178 this->d_start + posIdx,
6181 this->allocatorRef());
6184 BlockCreator newBlocks(
this);
6185 if (this->d_finish.offsetInBlock() == BLOCK_LENGTH - 1) {
6186 newBlocks.insertAtBack(1);
6188 DequePrimitives::insertAndMoveToBack(&this->d_finish,
6190 this->d_start + posIdx,
6193 this->allocatorRef());
6195 return this->
begin() + posIdx;
6198template <
class VALUE_TYPE,
class ALLOCATOR>
6199typename deque<VALUE_TYPE, ALLOCATOR>::iterator
6200deque<VALUE_TYPE, ALLOCATOR>::insert(
6201 const_iterator position,
6202 BloombergLP::bslmf::MovableRef<VALUE_TYPE> value)
6207 VALUE_TYPE& lvalue = value;
6209 if (position == this->
cbegin()) {
6210 push_front(MoveUtil::move(lvalue));
6211 return this->
begin();
6214 if (position == this->
cend()) {
6215 push_back(MoveUtil::move(lvalue));
6216 return iterator(this->d_finish - 1);
6222 const size_type currentSize = this->size();
6226 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
6227 "deque<...>::insert(pos,n,v): deque too big");
6230 iterator pos(position.imp());
6231 const size_type posIdx = position - this->
cbegin();
6232 if (posIdx <= currentSize / 2) {
6233 BlockCreator newBlocks(
this);
6234 if (this->d_start.remainingInBlock() == BLOCK_LENGTH) {
6235 newBlocks.insertAtFront(1);
6237 DequePrimitives::moveInsertAndMoveToFront(&this->d_start,
6239 this->d_start + posIdx,
6240 MoveUtil::move(lvalue),
6241 this->allocatorRef());
6244 BlockCreator newBlocks(
this);
6245 if (this->d_finish.offsetInBlock() == BLOCK_LENGTH - 1) {
6246 newBlocks.insertAtBack(1);
6248 DequePrimitives::moveInsertAndMoveToBack(&this->d_finish,
6250 this->d_start + posIdx,
6251 MoveUtil::move(lvalue),
6252 this->allocatorRef());
6254 return this->
begin() + posIdx;
6257template <
class VALUE_TYPE,
class ALLOCATOR>
6258typename deque<VALUE_TYPE, ALLOCATOR>::iterator
6259deque<VALUE_TYPE, ALLOCATOR>::insert(const_iterator position,
6260 size_type numElements,
6261 const VALUE_TYPE& value)
6266 const size_type posIdx = position - this->
cbegin();
6268 if (0 == numElements) {
6269 return this->
begin() + posIdx;
6272 const size_type currentSize = this->size();
6274 numElements > max_size() - currentSize)) {
6277 BloombergLP::bslstl::StdExceptUtil::throwLengthError(
6278 "deque<...>::insert(pos,n,v): deque too big");
6281 if (position == this->
cbegin()) {
6282 privatePrependRaw(numElements, value);
6284 return this->
begin();
6287 if (position == this->
cend()) {
6288 privateAppendRaw(numElements, value);
6290 return this->
begin() + posIdx;
6293 if (posIdx <= currentSize / 2) {
6297 size_type numNewBlocks = (this->d_start.remainingInBlock()
6298 + numElements - 1) / BLOCK_LENGTH;
6299 BlockCreator newBlocks(
this);
6300 newBlocks.insertAtFront(numNewBlocks);
6302 DequePrimitives::insertAndMoveToFront(&this->d_start,
6304 this->d_start + posIdx,
6307 this->allocatorRef());
6313 size_type numNewBlocks = (this->d_finish.offsetInBlock() + numElements)
6315 BlockCreator newBlocks(
this);
6316 newBlocks.insertAtBack(numNewBlocks);
6318 DequePrimitives::insertAndMoveToBack(&this->d_finish,
6320 this->d_start + posIdx,
6323 this->allocatorRef());
6326 return this->
begin() + posIdx;
6329template <
class VALUE_TYPE,
class ALLOCATOR>
6330template <
class INPUT_ITERATOR>
6332typename deque<VALUE_TYPE, ALLOCATOR>::iterator
6333deque<VALUE_TYPE, ALLOCATOR>::insert(const_iterator position,
6334 INPUT_ITERATOR first,
6335 INPUT_ITERATOR last)
6340 const size_type posIdx = position - this->
cbegin();
6342 privateInsertDispatch(position,
6346 BloombergLP::bslmf::Nil());
6348 return this->
begin() + posIdx;
6351#if defined(BSLS_COMPILERFEATURES_SUPPORT_GENERALIZED_INITIALIZERS)
6352template <
class VALUE_TYPE,
class ALLOCATOR>
6354typename deque<VALUE_TYPE, ALLOCATOR>::iterator
6355deque<VALUE_TYPE, ALLOCATOR>::insert(
6356 const_iterator position,
6357 std::initializer_list<value_type> values)
6362 return insert(position, values.begin(), values.end());
6366template <
class VALUE_TYPE,
class ALLOCATOR>
6367template <
class t_RANGE>
6369typename deque<VALUE_TYPE, ALLOCATOR>::iterator
6370deque<VALUE_TYPE, ALLOCATOR>::insert_range(
6371 const_iterator position,
6374 const size_type posIdx = position - this->
cbegin();
6375 privateInsert(position, ranges::begin(range), ranges::end(range));
6376 return this->
begin() + posIdx;
6379template <
class VALUE_TYPE,
class ALLOCATOR>
6380typename deque<VALUE_TYPE, ALLOCATOR>::iterator
6381deque<VALUE_TYPE, ALLOCATOR>::erase(const_iterator position)
6386 if (position == const_iterator(this->d_start)) {
6388 return this->
begin();
6391 if (position + 1 == const_iterator(this->d_finish)) {
6396 return erase(position, position + 1);
6399template <
class VALUE_TYPE,
class ALLOCATOR>
6400typename deque<VALUE_TYPE, ALLOCATOR>::iterator
6401deque<VALUE_TYPE, ALLOCATOR>::erase(const_iterator first, const_iterator last)
6408 iterator first_imp = this->
begin() + (first - this->
cbegin());
6409 iterator last_imp = this->
begin() + (last - this->
cbegin());
6410 iterator oldStart = this->
begin();
6411 iterator oldFinish = this->end();
6412 iterator result = iterator(DequePrimitives::erase(&this->d_start,
6418 this->allocatorRef()));
6422 for ( ; oldStart.imp().blockPtr() != this->d_start.blockPtr();
6423 oldStart.imp().nextBlock()) {
6424 this->deallocateBlock(oldStart.imp().blockPtr()[0]);
6426 for ( ; oldFinish.imp().blockPtr() != this->d_finish.blockPtr();
6427 oldFinish.imp().previousBlock()) {
6428 this->deallocateBlock(oldFinish.imp().blockPtr()[0]);
6433template <
class VALUE_TYPE,
class ALLOCATOR>
6434void deque<VALUE_TYPE, ALLOCATOR>::swap(deque<VALUE_TYPE, ALLOCATOR>& other)
6436 AllocatorTraits::is_always_equal::value)
6439 AllocatorTraits::propagate_on_container_swap Propagate;
6440 if (Propagate::value) {
6441 Deque_Util::swap(
static_cast<Base *
>(
this),
6442 static_cast<Base *
>(&other));
6443 AllocatorUtil::swap(&this->allocatorRef(), &other.allocatorRef(),
6448 this->get_allocator() == other.get_allocator())) {
6449 Deque_Util::swap(
static_cast<Base *
>(
this),
6450 static_cast<Base *
>(&other));
6455 deque toOtherCopy(MoveUtil::move(*
this), other.get_allocator());
6456 deque toThisCopy( MoveUtil::move(other), this->get_allocator());
6458 Deque_Util::swap(
static_cast<Base *
>(&toThisCopy),
6459 static_cast<Base *
>(
this));
6460 Deque_Util::swap(
static_cast<Base *
>(&toOtherCopy),
6461 static_cast<Base *
>(&other));
6466template <
class VALUE_TYPE,
class ALLOCATOR>
6469 DequePrimitives::destruct(this->d_start,
6471 this->allocatorRef());
6475 BlockPtr *startBlock = this->d_start.blockPtr();
6476 BlockPtr *finishBlock = this->d_finish.blockPtr();
6477 for ( ; startBlock != finishBlock; ++startBlock) {
6478 this->deallocateBlock(*startBlock);
6483 size_type blockOffset = this->d_blocksLength / 2;
6484 int offset = BLOCK_LENGTH / 2;
6485 BlockPtr *blockPtr = this->d_blocks_p + blockOffset;
6487 *blockPtr = *finishBlock;
6489 this->d_start = this->d_finish = IteratorImp(blockPtr,
6490 (*blockPtr)->d_data + offset);
6494template <
class VALUE_TYPE,
class ALLOCATOR>
6496typename deque<VALUE_TYPE, ALLOCATOR>::allocator_type
6499 return this->allocatorRef();
6502template <
class VALUE_TYPE,
class ALLOCATOR>
6504typename deque<VALUE_TYPE, ALLOCATOR>::size_type
6507 return AllocatorTraits::max_size(this->get_allocator());
6511template <
class VALUE_TYPE,
class ALLOCATOR>
6512bool operator==(
const deque<VALUE_TYPE, ALLOCATOR>& lhs,
6513 const deque<VALUE_TYPE, ALLOCATOR>& rhs)
6515 if (
lhs.size() !=
rhs.size()) {
6520 BLOCK_LENGTH = Deque_BlockLengthCalcUtil<VALUE_TYPE>::BLOCK_LENGTH
6523 typedef BloombergLP::bslalg::DequeIterator<VALUE_TYPE,
6524 BLOCK_LENGTH> Iterator;
6526 Iterator lhsBegin =
lhs.begin().imp();
6527 Iterator lhsEnd =
lhs.end().imp();
6528 Iterator rhsBegin =
rhs.begin().imp();
6530 for (; !(lhsBegin == lhsEnd); ++lhsBegin, ++rhsBegin) {
6531 if (!(*lhsBegin == *rhsBegin)) {
6538#ifndef BSLS_COMPILERFEATURES_SUPPORT_THREE_WAY_COMPARISON
6540template <
class VALUE_TYPE,
class ALLOCATOR>
6542bool operator!=(
const deque<VALUE_TYPE, ALLOCATOR>& lhs,
6543 const deque<VALUE_TYPE, ALLOCATOR>& rhs)
6550#ifdef BSLALG_SYNTHTHREEWAYUTIL_AVAILABLE
6552template <
class VALUE_TYPE,
class ALLOCATOR>
6554BloombergLP::bslalg::SynthThreeWayUtil::Result<VALUE_TYPE> operator<=>(
6555 const deque<VALUE_TYPE, ALLOCATOR>& lhs,
6556 const deque<VALUE_TYPE, ALLOCATOR>& rhs)
6558 return bsl::lexicographical_compare_three_way(
6563 BloombergLP::bslalg::SynthThreeWayUtil::compare);
6568template <
class VALUE_TYPE,
class ALLOCATOR>
6570bool operator<(
const deque<VALUE_TYPE, ALLOCATOR>& lhs,
6571 const deque<VALUE_TYPE, ALLOCATOR>& rhs)
6573 return 0 > BloombergLP::bslalg::RangeCompare::lexicographical(
lhs.begin(),
6581template <
class VALUE_TYPE,
class ALLOCATOR>
6583bool operator>(
const deque<VALUE_TYPE, ALLOCATOR>& lhs,
6584 const deque<VALUE_TYPE, ALLOCATOR>& rhs)
6589template <
class VALUE_TYPE,
class ALLOCATOR>
6591bool operator<=(
const deque<VALUE_TYPE, ALLOCATOR>& lhs,
6592 const deque<VALUE_TYPE, ALLOCATOR>& rhs)
6597template <
class VALUE_TYPE,
class ALLOCATOR>
6599bool operator>=(
const deque<VALUE_TYPE, ALLOCATOR>& lhs,
6600 const deque<VALUE_TYPE, ALLOCATOR>& rhs)
6608template <
class VALUE_TYPE,
class ALLOCATOR,
class BDE_OTHER_TYPE>
6609inline typename deque<VALUE_TYPE, ALLOCATOR>::size_type
6610erase(deque<VALUE_TYPE, ALLOCATOR>& deq,
const BDE_OTHER_TYPE& value)
6612 typename deque<VALUE_TYPE, ALLOCATOR>::size_type oldSize = deq.
size();
6613 deq.erase(bsl::remove(deq.begin(), deq.end(), value), deq.end());
6614 return oldSize - deq.size();
6617template <
class VALUE_TYPE,
class ALLOCATOR,
class PREDICATE>
6618inline typename deque<VALUE_TYPE, ALLOCATOR>::size_type
6619erase_if(deque<VALUE_TYPE, ALLOCATOR>& deq, PREDICATE predicate)
6621 typename deque<VALUE_TYPE, ALLOCATOR>::size_type oldSize = deq.
size();
6622 deq.erase(bsl::remove_if(deq.begin(), deq.end(), predicate), deq.end());
6623 return oldSize - deq.size();
6626template <
class VALUE_TYPE,
class ALLOCATOR>
6628void swap(deque<VALUE_TYPE, ALLOCATOR>& a, deque<VALUE_TYPE, ALLOCATOR>& b)
6640template <
class VALUE_TYPE,
class ALLOCATOR>
6642Deque_BlockCreator<VALUE_TYPE, ALLOCATOR>::Deque_BlockCreator(
6643 deque<VALUE_TYPE, ALLOCATOR> *deque)
6649template <
class VALUE_TYPE,
class ALLOCATOR>
6650Deque_BlockCreator<VALUE_TYPE, ALLOCATOR>::~Deque_BlockCreator()
6652 if (0 != d_boundary_p) {
6653 BlockPtr *delFirst, *delLast;
6654 if (d_boundary_p <= d_deque_p->d_start.blockPtr()) {
6655 delFirst = d_boundary_p;
6656 delLast = d_deque_p->d_start.blockPtr();
6659 delFirst = d_deque_p->d_finish.blockPtr() + 1;
6660 delLast = d_boundary_p;
6663 for (; delFirst != delLast; ++delFirst) {
6665 d_deque_p->deallocateBlock(*delFirst);
6671template <
class VALUE_TYPE,
class ALLOCATOR>
6672void Deque_BlockCreator<VALUE_TYPE, ALLOCATOR>::insertAtFront(size_type n)
6674 d_boundary_p = reserveBlockSlots(n,
true);
6675 for ( ; n > 0; --n) {
6676 d_boundary_p[-1] = d_deque_p->allocateBlock();
6682template <
class VALUE_TYPE,
class ALLOCATOR>
6683void Deque_BlockCreator<VALUE_TYPE, ALLOCATOR>::insertAtBack(size_type n)
6685 d_boundary_p = reserveBlockSlots(n,
false);
6686 for ( ; n > 0; --n) {
6687 *d_boundary_p = d_deque_p->allocateBlock();
6692template <
class VALUE_TYPE,
class ALLOCATOR>
6693typename Deque_BlockCreator<VALUE_TYPE, ALLOCATOR>::BlockPtr *
6694Deque_BlockCreator<VALUE_TYPE, ALLOCATOR>::reserveBlockSlots(
6695 size_type numNewBlocks,
6698 BlockPtr *blocks = d_deque_p->d_blocks_p;
6699 size_type blocksLength = d_deque_p->d_blocksLength;
6701 BlockPtr *firstSlot = d_deque_p->d_start.blockPtr();
6702 BlockPtr *lastSlot = d_deque_p->d_finish.blockPtr() + 1;
6706 firstSlot = d_boundary_p;
6708 if (size_type(firstSlot - blocks) >= numNewBlocks) {
6716 lastSlot = d_boundary_p;
6718 if (size_type(blocks + blocksLength - lastSlot) >= numNewBlocks) {
6725 BlockPtr *newBlocks = blocks;
6726 size_type newBlocksLength = blocksLength;
6727 size_type numUsedBlocks = lastSlot - firstSlot;
6728 size_type blockOffsetStart = d_deque_p->d_start.blockPtr() - firstSlot;
6729 size_type numCommittedBlocks = (d_deque_p->d_finish.blockPtr() -
6730 d_deque_p->d_start.blockPtr() + 1);
6731 size_type newNumUsedBlocks = numUsedBlocks + numNewBlocks;
6733 if (newNumUsedBlocks > blocksLength) {
6734 const size_type newThreshold = newNumUsedBlocks +
6735 2 * Imp::BLOCK_ARRAY_PADDING;
6736 while (newThreshold > newBlocksLength) {
6742 newBlocksLength *= 2;
6744 newBlocks = d_deque_p->allocateBlockPtrs(newBlocksLength);
6749 BlockPtr *newFirstSlot = newBlocks +
6750 (newBlocksLength - newNumUsedBlocks) / 2;
6753 newFirstSlot += numNewBlocks;
6759 const size_type offsetStart = d_deque_p->d_start.offsetInBlock();
6760 const size_type offsetFinish = d_deque_p->d_finish.offsetInBlock();
6764 std::memmove(newFirstSlot, firstSlot, numUsedBlocks *
sizeof(BlockPtr));
6766 if (newBlocks != blocks) {
6770 d_deque_p->deallocateBlockPtrs(blocks, d_deque_p->d_blocksLength);
6772 d_deque_p->d_blocks_p = newBlocks;
6773 d_deque_p->d_blocksLength = newBlocksLength;
6778 d_deque_p->d_start.setBlock(newFirstSlot + blockOffsetStart);
6779 d_deque_p->d_start += offsetStart;
6780 d_deque_p->d_finish.setBlock(newFirstSlot + blockOffsetStart +
6781 numCommittedBlocks - 1);
6782 d_deque_p->d_finish += offsetFinish;
6784 BlockPtr *ret = newFirstSlot;
6786 ret += numUsedBlocks;
6792template <
class VALUE_TYPE,
class ALLOCATOR>
6794void Deque_BlockCreator<VALUE_TYPE, ALLOCATOR>::release()
6804template <
class VALUE_TYPE,
class ALLOCATOR>
6805Deque_BlockProctor<VALUE_TYPE, ALLOCATOR>::Deque_BlockProctor(
6806 deque<VALUE_TYPE, ALLOCATOR> *deque,
6809, d_boundary_p(atFront
6810 ? d_deque_p->d_start.blockPtr()
6811 : d_deque_p->d_finish.blockPtr())
6816template <
class VALUE_TYPE,
class ALLOCATOR>
6817Deque_BlockProctor<VALUE_TYPE, ALLOCATOR>::~Deque_BlockProctor()
6819 if (0 != d_deque_p) {
6820 BlockPtr *delFirst, *delLast;
6822 if (d_atFront && d_boundary_p < d_deque_p->d_start.blockPtr()) {
6826 delFirst = d_boundary_p;
6827 delLast = d_deque_p->d_start.blockPtr();
6829 else if (!d_atFront && d_boundary_p > d_deque_p->d_finish.blockPtr()) {
6833 delFirst = d_deque_p->d_finish.blockPtr() + 1;
6834 delLast = d_boundary_p + 1;
6840 for (; delFirst != delLast; ++delFirst) {
6843 d_deque_p->deallocateBlock(*delFirst);
6849template <
class VALUE_TYPE,
class ALLOCATOR>
6851void Deque_BlockProctor<VALUE_TYPE, ALLOCATOR>::release()
6861template <
class VALUE_TYPE,
class ALLOCATOR>
6863Deque_ClearGuard<VALUE_TYPE, ALLOCATOR>::Deque_ClearGuard(
6864 deque<VALUE_TYPE, ALLOCATOR> *deque)
6869template <
class VALUE_TYPE,
class ALLOCATOR>
6871Deque_ClearGuard<VALUE_TYPE, ALLOCATOR>::~Deque_ClearGuard()
6879template <
class VALUE_TYPE,
class ALLOCATOR>
6881void Deque_ClearGuard<VALUE_TYPE, ALLOCATOR>::release()
6891template <
class VALUE_TYPE,
class ALLOCATOR>
6893Deque_Guard<VALUE_TYPE, ALLOCATOR>::Deque_Guard(
6894 deque<VALUE_TYPE, ALLOCATOR> *deque,
6902template <
class VALUE_TYPE,
class ALLOCATOR>
6903Deque_Guard<VALUE_TYPE, ALLOCATOR>::~Deque_Guard()
6912 begin = d_deque_p->d_finish;
6916 end = d_deque_p->d_start;
6920 DequePrimitives::destruct(begin, end, d_deque_p->get_allocator());
6924template <
class VALUE_TYPE,
class ALLOCATOR>
6926std::size_t Deque_Guard<VALUE_TYPE, ALLOCATOR>::operator++()
6931template <
class VALUE_TYPE,
class ALLOCATOR>
6933std::size_t Deque_Guard<VALUE_TYPE, ALLOCATOR>::operator--()
6938template <
class VALUE_TYPE,
class ALLOCATOR>
6940void Deque_Guard<VALUE_TYPE, ALLOCATOR>::release()
6946template <
class VALUE_TYPE,
class ALLOCATOR>
6954template <
class VALUE_TYPE,
class ALLOCATOR>
6956typename Deque_Guard<VALUE_TYPE, ALLOCATOR>::IteratorImp
6959 return d_deque_p->d_start - d_count;
6962template <
class VALUE_TYPE,
class ALLOCATOR>
6964typename Deque_Guard<VALUE_TYPE, ALLOCATOR>::IteratorImp
6967 return d_deque_p->d_finish + d_count;
6987template <
class VALUE_TYPE,
class ALLOCATOR>
6996template <
class VALUE_TYPE,
class ALLOCATOR>
6997struct IsBitwiseMoveable<
bsl::deque<VALUE_TYPE, ALLOCATOR> >
6998 : IsBitwiseMoveable<ALLOCATOR>
7006template <
class VALUE_TYPE,
class ALLOCATOR>
7007struct UsesBslmaAllocator<
bsl::deque<VALUE_TYPE, ALLOCATOR> >
7017# error Not valid except when included from bslstl_deque.h
IteratorImp d_finish
Definition bslstl_deque.h:659
const_reverse_iterator crend() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_deque.h:2233
iterator end() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_deque.h:2107
reference back()
Definition bslstl_deque.h:2164
reverse_iterator rbegin() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_deque.h:2115
size_type size() const BSLS_KEYWORD_NOEXCEPT
Return the number of elements contained by this deque.
Definition bslstl_deque.h:2241
const_iterator cbegin() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_deque.h:2185
bsl::reverse_iterator< Iterator > reverse_iterator
Definition bslstl_deque.h:651
std::size_t d_blocksLength
Definition bslstl_deque.h:657
reverse_iterator rend() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_deque.h:2123
bsl::reverse_iterator< ConstIterator > const_reverse_iterator
Definition bslstl_deque.h:652
reference front()
Definition bslstl_deque.h:2154
BlockPtr * d_blocks_p
Definition bslstl_deque.h:656
Iterator iterator
Definition bslstl_deque.h:638
ConstIterator const_iterator
Definition bslstl_deque.h:639
VALUE_TYPE value_type
Definition bslstl_deque.h:642
iterator begin() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_deque.h:2099
const VALUE_TYPE & const_reference
Definition bslstl_deque.h:637
size_type capacity() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_deque.h:2248
std::size_t size_type
Definition bslstl_deque.h:640
reference at(size_type position)
Definition bslstl_deque.h:2140
const_iterator cend() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_deque.h:2201
bool empty() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_deque.h:2287
const_reverse_iterator crbegin() const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_deque.h:2217
VALUE_TYPE & reference
Definition bslstl_deque.h:636
IteratorImp d_start
Definition bslstl_deque.h:658
std::ptrdiff_t difference_type
Definition bslstl_deque.h:641
Definition bslma_bslallocator.h:588
#define BSLMF_ASSERT(expr)
Definition bslmf_assert.h:231
static const t_TYPE value
Definition bslmf_integralconstant.h:267
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1976
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1917
#define BSLS_ASSERT_OPT(X)
Definition bsls_assert.h:2045
#define BSLS_COMPILERFEATURES_FORWARD_REF(T)
Definition bsls_compilerfeatures.h:2343
#define BSLS_COMPILERFEATURES_FORWARD(T, V)
Definition bsls_compilerfeatures.h:2349
#define BSLS_KEYWORD_NOEXCEPT_OPERATOR(...)
Definition bsls_keyword.h:677
#define BSLS_KEYWORD_NOEXCEPT
Definition bsls_keyword.h:674
#define BSLS_KEYWORD_NOEXCEPT_SPECIFICATION(...)
Definition bsls_keyword.h:676
#define BSLS_UTIL_ADDRESSOF(OBJ)
Definition bsls_util.h:296
#define BSLSTL_DEQUE_REQUIRES_CONTAINER_COMPATIBLE_RANGE(R, T)
Definition bslstl_deque.h:524
bool operator!=(const FileCleanerConfiguration &lhs, const FileCleanerConfiguration &rhs)
bool operator==(const FileCleanerConfiguration &lhs, const FileCleanerConfiguration &rhs)
void swap(OptionValue &a, OptionValue &b)
bool operator<(const MetricId &lhs, const MetricId &rhs)
void resize(TYPE *array, int newSize)
bsl::size_t size(const TYPE &array)
Return the number of elements in the specified array.
int reserve(TYPE *array, int numElements)
int assign(LHS_TYPE *lhs, const RHS_TYPE &rhs)
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:408
bool operator<=(const Guid &lhs, const Guid &rhs)
bool operator>(const Guid &lhs, const Guid &rhs)
Definition bdlat_valuetypefunctions.h:939
T::const_iterator cend(const T &container)
Definition bslstl_iterator.h:1709
ALLOCATOR const STRING_VIEW_LIKE_TYPE & rhs
Definition bslstl_string.h:3918
deque< VALUE_TYPE, ALLOCATOR >::size_type erase(deque< VALUE_TYPE, ALLOCATOR > &deq, const BDE_OTHER_TYPE &value)
Definition bslstl_deque.h:4424
T::iterator begin(T &container)
Definition bslstl_iterator.h:1593
T::const_iterator cbegin(const T &container)
Definition bslstl_iterator.h:1651
ALLOCATOR & lhs
Definition bslstl_string.h:3917
T::iterator end(T &container)
Definition bslstl_iterator.h:1621
deque< VALUE_TYPE, ALLOCATOR >::size_type erase_if(deque< VALUE_TYPE, ALLOCATOR > &deq, PREDICATE predicate)
Definition bslstl_deque.h:4433
BSLS_KEYWORD_CONSTEXPR bool empty(const CONTAINER &container)
Definition bslstl_iterator.h:1377
Definition bdlc_flathashmap.h:2218
Definition baljsn_encoder_testtypes.h:76
Definition bdlbb_blob.h:579
@ DEFAULT_BLOCK_SIZE
Definition bslstl_deque.h:565
@ BLOCK_LENGTH
Definition bslstl_deque.h:567
static void swap(void *a, void *b)
static void move(void *dst, void *src)
Definition bslma_allocatortraits.h:1089
BloombergLP::bslma::AllocatorTraits_SizeType< ALLOCATOR_TYPE >::type size_type
Definition bslma_allocatortraits.h:1196
Definition bslmf_isconvertible.h:875