8#ifndef INCLUDED_BDLCC_DEQUE
9#define INCLUDED_BDLCC_DEQUE
497#include <bdlscm_version.h>
515#include <bsl_algorithm.h>
516#include <bsl_deque.h>
517#include <bsl_vector.h>
518#include <bsl_limits.h>
519#include <bsl_cstddef.h>
520#include <bsl_cstdio.h>
544 template <
class VECTOR>
545 class VectorThrowGuard;
547 template <
class VECTOR>
595 template <
class VECTOR>
596 void removeAllImp(VECTOR *buffer = 0);
607 template <
class VECTOR>
608 void tryPopBackImp(
size_type maxNumItems,
619 template <
class VECTOR>
620 void tryPopFrontImp(
size_type maxNumItems,
667 template <
class INPUT_ITER>
668 Deque(INPUT_ITER begin,
671 template <
class INPUT_ITER>
672 Deque(INPUT_ITER begin,
690 template <
class INPUT_ITER>
691 Deque(INPUT_ITER begin,
695 template <
class INPUT_ITER>
696 Deque(INPUT_ITER begin,
732 template <
class INPUT_ITER>
755 template <
class INPUT_ITER>
806 void removeAll(std::vector<TYPE> *buffer);
807#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR
808 void removeAll(std::pmr::vector<TYPE> *buffer);
911 std::vector<TYPE> *buffer);
912#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR
914 std::pmr::vector<TYPE> *buffer);
938 std::vector<TYPE> *buffer);
939#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR
941 std::pmr::vector<TYPE> *buffer);
964 template <
class INPUT_ITER>
989 template <
class INPUT_ITER>
1025template <
class TYPE>
1035 const MDCIter d_mdBegin;
1036 const MDCIter d_mdEnd;
1037 const bool d_mdWasEmpty;
1072template <
class TYPE>
1073template <
class VECTOR>
1074class Deque<TYPE>::VectorThrowGuard {
1077 typedef typename VECTOR::size_type VSize;
1081 const VSize d_vSize;
1085 VectorThrowGuard(
const VectorThrowGuard&);
1086 VectorThrowGuard& operator=(
const VectorThrowGuard&);
1095 VectorThrowGuard(VECTOR *vector_p);
1099 ~VectorThrowGuard();
1110template <
class TYPE>
1111template <
class VECTOR>
1112struct Deque<TYPE>::IsVector {
1114 static const bool value =
1116#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR
1129template <
class TYPE>
1138 size_type d_startLength;
1195 bool isNull()
const;
1204template <
class TYPE>
1213 size_type d_startLength;
1266 const TYPE& operator[](size_type position)
const;
1270 bool isNull()
const;
1282template <
class TYPE>
1288 this->
load(container);
1294template <
class TYPE>
1302template <
class TYPE>
1308 if (0 != d_container_p) {
1312 container->d_mutex.
lock();
1313 d_container_p = container;
1314 d_startLength = d_container_p->d_monoDeque.
size();
1317template <
class TYPE>
1320 if (0 == d_container_p) {
1324 const size_type sz = d_container_p->d_monoDeque.size();
1325 size_type ii = d_startLength;
1327 d_container_p->d_mutex.unlock();
1331 d_container_p->d_notEmptyCondition.signal();
1332 }
while (++ii < sz);
1335 if (d_container_p->d_highWaterMark < ii) {
1336 ii = d_container_p->d_highWaterMark;
1338 for (; ii > sz; --ii) {
1339 d_container_p->d_notFullCondition.signal();
1347template <
class TYPE>
1353 return &d_container_p->d_monoDeque;
1356template <
class TYPE>
1362 return d_container_p->d_monoDeque;
1365template <
class TYPE>
1371 return d_container_p->d_monoDeque[position];
1374template <
class TYPE>
1378 return 0 == d_container_p;
1387template <
class TYPE>
1393 this->
load(container);
1399template <
class TYPE>
1407template <
class TYPE>
1415 container->d_mutex.
lock();
1416 d_container_p = container;
1417 d_startLength = d_container_p->d_monoDeque.
size();
1420template <
class TYPE>
1430 if (0 == d_container_p) {
1435 "Underlying 'bsl::deque' modified through ConstProcter.");
1443template <
class TYPE>
1449 return &d_container_p->d_monoDeque;
1452template <
class TYPE>
1458 return d_container_p->d_monoDeque;
1461template <
class TYPE>
1467 return d_container_p->d_monoDeque[position];
1470template <
class TYPE>
1474 return 0 == d_container_p;
1482template <
class TYPE>
1485: d_monoDeque_p(monoDeque_p)
1486, d_mdBegin( monoDeque_p->cbegin())
1487, d_mdEnd( monoDeque_p->cend())
1488, d_mdWasEmpty(monoDeque_p->empty())
1493template <
class TYPE>
1497 if (d_monoDeque_p) {
1506 d_monoDeque_p->clear();
1511 const MDCIter newBegin = d_monoDeque_p->cbegin();
1512 const MDCIter newEnd = d_monoDeque_p->cend();
1522 if (newBegin < d_mdBegin) {
1525 d_monoDeque_p->erase(newBegin, d_mdBegin);
1530 if (d_mdEnd < newEnd) {
1531 d_monoDeque_p->erase(d_mdEnd, newEnd);
1541template <
class TYPE>
1553template <
class TYPE>
1554template <
class VECTOR>
1557: d_vector_p(vector_p)
1558, d_vSize(vector_p ? vector_p->size() : 0)
1562template <
class TYPE>
1563template <
class VECTOR>
1568 const VSize newSize = d_vector_p->size();
1576 if (d_vSize < newSize) {
1577 d_vector_p->resize(d_vSize);
1586template <
class TYPE>
1587template <
class VECTOR>
1589void Deque<TYPE>::VectorThrowGuard<VECTOR>::release()
1599template <
class TYPE>
1600template <
class VECTOR>
1602void Deque<TYPE>::removeAllImp(VECTOR *buffer)
1606 Proctor proctor(
this);
1608 VectorThrowGuard<VECTOR> tg(buffer);
1612 buffer->reserve(buffer->size() + size);
1625template <
class TYPE>
1626template <
class VECTOR>
1633 VectorThrowGuard<VECTOR> tg(buffer);
1639 const size_type toMove = bsl::min(size, maxNumItems);
1642 buffer->reserve(buffer->size() + toMove);
1644 const size_type lastMovedIdx = size - toMove;
1645 for (
size_type ii = size; lastMovedIdx < ii--; ) {
1649 d_monoDeque.
erase(d_monoDeque.
end() - toMove, d_monoDeque.
end());
1656template <
class TYPE>
1657template <
class VECTOR>
1666 VectorThrowGuard<VECTOR> tg(buffer);
1671 const size_type toMove = bsl::min(d_monoDeque.
size(), maxNumItems);
1672 const Iterator beginRange = d_monoDeque.
begin();
1673 const Iterator endRange = beginRange + toMove;
1676 buffer->reserve(buffer->size() + toMove);
1678 for (
size_type ii = 0; ii < toMove; ++ii) {
1682 proctor->
erase(beginRange, endRange);
1690template <
class TYPE>
1694 return bsl::numeric_limits<size_type>::max();
1698template <
class TYPE>
1702, d_notEmptyCondition()
1703, d_notFullCondition()
1704, d_monoDeque(basicAllocator)
1706, d_clockType(
bsls::SystemClockType::e_REALTIME)
1710template <
class TYPE>
1715, d_notEmptyCondition(clockType)
1716, d_notFullCondition(clockType)
1717, d_monoDeque(basicAllocator)
1718, d_highWaterMark(maxSizeT())
1719, d_clockType(clockType)
1723template <
class TYPE>
1728, d_notEmptyCondition()
1729, d_notFullCondition()
1730, d_monoDeque(basicAllocator)
1731, d_highWaterMark(highWaterMark)
1732, d_clockType(
bsls::SystemClockType::e_REALTIME)
1737template <
class TYPE>
1743, d_notEmptyCondition(clockType)
1744, d_notFullCondition(clockType)
1745, d_monoDeque(basicAllocator)
1746, d_highWaterMark(highWaterMark)
1747, d_clockType(clockType)
1752template <
class TYPE>
1753template <
class INPUT_ITER>
1759, d_notEmptyCondition()
1760, d_notFullCondition()
1761, d_monoDeque(begin, end, basicAllocator)
1762, d_highWaterMark(maxSizeT())
1763, d_clockType(
bsls::SystemClockType::e_REALTIME)
1767template <
class TYPE>
1768template <
class INPUT_ITER>
1775, d_notEmptyCondition(clockType)
1776, d_notFullCondition(clockType)
1777, d_monoDeque(begin, end, basicAllocator)
1778, d_highWaterMark(maxSizeT())
1779, d_clockType(clockType)
1783template <
class TYPE>
1784template <
class INPUT_ITER>
1788 bsl::size_t highWaterMark,
1791, d_notEmptyCondition()
1792, d_notFullCondition()
1793, d_monoDeque(begin, end, basicAllocator)
1794, d_highWaterMark(highWaterMark)
1795, d_clockType(
bsls::SystemClockType::e_REALTIME)
1800template <
class TYPE>
1801template <
class INPUT_ITER>
1805 bsl::size_t highWaterMark,
1809, d_notEmptyCondition(clockType)
1810, d_notFullCondition(clockType)
1811, d_monoDeque(begin, end, basicAllocator)
1812, d_highWaterMark(highWaterMark)
1813, d_clockType(clockType)
1818template <
class TYPE>
1823, d_notEmptyCondition()
1824, d_notFullCondition()
1825, d_monoDeque(basicAllocator)
1826, d_highWaterMark(maxSizeT())
1827, d_clockType(original.d_clockType)
1834template <
class TYPE>
1841template <
class TYPE>
1848 d_monoDeque.push_back(item);
1851 d_notEmptyCondition.signal();
1854template <
class TYPE>
1864 d_notEmptyCondition.signal();
1867template <
class TYPE>
1868template <
class INPUT_ITER>
1879 const size_type initialSize = d_monoDeque.size();
1880 d_monoDeque.insert(d_monoDeque.end(), begin, end);
1881 growth = d_monoDeque.size() - initialSize;
1886 for (; growth > 0; --growth) {
1887 d_notEmptyCondition.signal();
1891template <
class TYPE>
1898 d_monoDeque.push_front(item);
1901 d_notEmptyCondition.signal();
1904template <
class TYPE>
1914 d_notEmptyCondition.signal();
1917template <
class TYPE>
1918template <
class INPUT_ITER>
1929 const size_type initialSize = d_monoDeque.size();
1930 for (; end != begin; ++begin) {
1931 d_monoDeque.push_front(*begin);
1933 growth = d_monoDeque.size() - initialSize;
1938 for (; growth > 0; --growth) {
1939 d_notEmptyCondition.signal();
1943template <
class TYPE>
1948 while (d_monoDeque.empty()) {
1949 d_notEmptyCondition.wait(&d_mutex);
1952 d_monoDeque.pop_back();
1954 const bool shouldSignal = d_monoDeque.size() < d_highWaterMark;
1958 d_notFullCondition.signal();
1964template <
class TYPE>
1972 while (d_monoDeque.empty()) {
1973 d_notEmptyCondition.wait(&d_mutex);
1976#if defined(BSLMF_MOVABLEREF_USES_RVALUE_REFERENCES)
1979 *item = d_monoDeque.back();
1981 d_monoDeque.pop_back();
1982 shouldSignal = d_monoDeque.size() < d_highWaterMark;
1986 d_notFullCondition.signal();
1990template <
class TYPE>
1995 while (d_monoDeque.empty()) {
1996 d_notEmptyCondition.wait(&d_mutex);
1999 d_monoDeque.pop_front();
2001 const bool shouldSignal = d_monoDeque.size() < d_highWaterMark;
2005 d_notFullCondition.signal();
2011template <
class TYPE>
2018 while (d_monoDeque.empty()) {
2019 d_notEmptyCondition.wait(&d_mutex);
2021#if defined(BSLMF_MOVABLEREF_USES_RVALUE_REFERENCES)
2024 *item = d_monoDeque.front();
2026 d_monoDeque.pop_front();
2028 shouldSignal = d_monoDeque.size() < d_highWaterMark;
2032 d_notFullCondition.signal();
2036template <
class TYPE>
2042 while (d_monoDeque.size() >= d_highWaterMark) {
2043 d_notFullCondition.wait(&d_mutex);
2045 d_monoDeque.push_back(item);
2048 d_notEmptyCondition.signal();
2051template <
class TYPE>
2057 while (d_monoDeque.size() >= d_highWaterMark) {
2058 d_notFullCondition.wait(&d_mutex);
2063 d_notEmptyCondition.signal();
2066template <
class TYPE>
2072 while (d_monoDeque.size() >= d_highWaterMark) {
2073 d_notFullCondition.wait(&d_mutex);
2075 d_monoDeque.push_front(item);
2078 d_notEmptyCondition.signal();
2081template <
class TYPE>
2087 while (d_monoDeque.size() >= d_highWaterMark) {
2088 d_notFullCondition.wait(&d_mutex);
2093 d_notEmptyCondition.signal();
2096template <
class TYPE>
2103template <
class TYPE>
2107 removeAllImp(buffer);
2110template <
class TYPE>
2114 removeAllImp(buffer);
2117#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR
2118template <
class TYPE>
2122 removeAllImp(buffer);
2126template <
class TYPE>
2134 while (d_monoDeque.empty()) {
2135 if (d_notEmptyCondition.timedWait(&d_mutex, timeout)) {
2139#if defined(BSLMF_MOVABLEREF_USES_RVALUE_REFERENCES)
2142 *item = d_monoDeque.back();
2144 d_monoDeque.pop_back();
2146 shouldSignal = d_monoDeque.size() < d_highWaterMark;
2150 d_notFullCondition.signal();
2156template <
class TYPE>
2164 while (d_monoDeque.empty()) {
2165 if (d_notEmptyCondition.timedWait(&d_mutex, timeout)) {
2169#if defined(BSLMF_MOVABLEREF_USES_RVALUE_REFERENCES)
2172 *item = d_monoDeque.front();
2174 d_monoDeque.pop_front();
2176 shouldSignal = d_monoDeque.size() < d_highWaterMark;
2180 d_notFullCondition.signal();
2186template <
class TYPE>
2193 while (d_monoDeque.size() >= d_highWaterMark) {
2194 if (d_notFullCondition.timedWait(&d_mutex, timeout)) {
2198 d_monoDeque.push_back(item);
2201 d_notEmptyCondition.signal();
2206template <
class TYPE>
2213 while (d_monoDeque.size() >= d_highWaterMark) {
2214 if (d_notFullCondition.timedWait(&d_mutex, timeout)) {
2221 d_notEmptyCondition.signal();
2226template <
class TYPE>
2233 while (d_monoDeque.size() >= d_highWaterMark) {
2234 if (d_notFullCondition.timedWait(&d_mutex, timeout)) {
2238 d_monoDeque.push_front(item);
2241 d_notEmptyCondition.signal();
2246template <
class TYPE>
2253 while (d_monoDeque.size() >= d_highWaterMark) {
2254 if (d_notFullCondition.timedWait(&d_mutex, timeout)) {
2261 d_notEmptyCondition.signal();
2266template <
class TYPE>
2273 if (d_monoDeque.empty()) {
2276#if defined(BSLMF_MOVABLEREF_USES_RVALUE_REFERENCES)
2279 *item = d_monoDeque.back();
2281 d_monoDeque.pop_back();
2283 shouldSignal = d_monoDeque.size() < d_highWaterMark;
2287 d_notFullCondition.signal();
2293template <
class TYPE>
2300template <
class TYPE>
2305 tryPopBackImp(maxNumItems, buffer);
2308template <
class TYPE>
2311 std::vector<TYPE> *buffer)
2313 tryPopBackImp(maxNumItems, buffer);
2316#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR
2317template <
class TYPE>
2320 std::pmr::vector<TYPE> *buffer)
2322 tryPopBackImp(maxNumItems, buffer);
2326template <
class TYPE>
2333 if (d_monoDeque.empty()) {
2336#if defined(BSLMF_MOVABLEREF_USES_RVALUE_REFERENCES)
2339 *item = d_monoDeque.front();
2341 d_monoDeque.pop_front();
2343 shouldSignal = d_monoDeque.size() < d_highWaterMark;
2347 d_notFullCondition.signal();
2353template <
class TYPE>
2359template <
class TYPE>
2363 tryPopFrontImp(maxNumItems, buffer);
2366template <
class TYPE>
2368 std::vector<TYPE> *buffer)
2370 tryPopFrontImp(maxNumItems, buffer);
2373#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR
2374template <
class TYPE>
2376 std::pmr::vector<TYPE> *buffer)
2378 tryPopFrontImp(maxNumItems, buffer);
2382template <
class TYPE>
2388 if (d_monoDeque.size() >= d_highWaterMark) {
2392 d_monoDeque.push_back(item);
2395 d_notEmptyCondition.signal();
2400template <
class TYPE>
2406 if (d_monoDeque.size() >= d_highWaterMark) {
2413 d_notEmptyCondition.signal();
2418template <
class TYPE>
2419template <
class INPUT_ITER>
2430 const size_type startLength = d_monoDeque.size();
2433 for (; length < d_highWaterMark && end != begin; ++length, ++begin) {
2434 d_monoDeque.push_back(*begin);
2439 growth = length - startLength;
2442 for (
size_type ii = 0; ii < growth; ++ii) {
2443 d_notEmptyCondition.signal();
2449template <
class TYPE>
2455 if (d_monoDeque.size() >= d_highWaterMark) {
2459 d_monoDeque.push_front(item);
2462 d_notEmptyCondition.signal();
2467template <
class TYPE>
2473 if (d_monoDeque.size() >= d_highWaterMark) {
2480 d_notEmptyCondition.signal();
2485template <
class TYPE>
2486template <
class INPUT_ITER>
2497 const size_type startLength = d_monoDeque.size();
2500 for (; length < d_highWaterMark && end != begin; ++length, ++begin) {
2501 d_monoDeque.push_front(*begin);
2506 growth = length - startLength;
2509 for (
size_type ii = 0; ii < growth; ++ii) {
2510 d_notEmptyCondition.signal();
2517template <
class TYPE>
2521 return d_monoDeque.get_allocator().mechanism();
2524template <
class TYPE>
2531template <
class TYPE>
2540 return d_highWaterMark;
2543template <
class TYPE>
2560 return d_monoDeque.size();
2567template <
class TYPE>
Definition bdlcc_deque.h:1205
bool isNull() const
Definition bdlcc_deque.h:1472
void release()
Definition bdlcc_deque.h:1422
const MonoDeque & operator*() const
Definition bdlcc_deque.h:1454
void load(const Deque< TYPE > *container)
Definition bdlcc_deque.h:1409
const TYPE & operator[](size_type position) const
Definition bdlcc_deque.h:1463
const MonoDeque * operator->() const
Definition bdlcc_deque.h:1445
~ConstProctor()
Definition bdlcc_deque.h:1401
Definition bdlcc_deque.h:1026
void release()
Definition bdlcc_deque.h:1543
~DequeThrowGuard()
Definition bdlcc_deque.h:1495
Definition bdlcc_deque.h:1130
void load(Deque< TYPE > *container)
Definition bdlcc_deque.h:1304
MonoDeque & operator*() const
Definition bdlcc_deque.h:1358
bool isNull() const
Return true if this object is not associated with a Deque object.
Definition bdlcc_deque.h:1376
MonoDeque * operator->() const
Definition bdlcc_deque.h:1349
~Proctor()
Definition bdlcc_deque.h:1296
void release()
Definition bdlcc_deque.h:1318
TYPE & operator[](typename MonoDeque::size_type position) const
Definition bdlcc_deque.h:1367
Definition bdlcc_deque.h:540
int timedPopFront(TYPE *item, const bsls::TimeInterval &timeout)
Definition bdlcc_deque.h:2157
bsl::deque< TYPE > MonoDeque
Definition bdlcc_deque.h:552
int tryPushBack(const TYPE &item)
Definition bdlcc_deque.h:2383
TYPE popBack()
Definition bdlcc_deque.h:1944
~Deque()
Definition bdlcc_deque.h:1836
Deque(bslma::Allocator *basicAllocator=0)
Definition bdlcc_deque.h:1700
bslma::Allocator * allocator() const
Return the allocator used by this container for allocating memory.
Definition bdlcc_deque.h:2519
static size_type maxSizeT()
Definition bdlcc_deque.h:1692
void pushBack(const TYPE &item)
Definition bdlcc_deque.h:2037
int timedPushFront(const TYPE &item, const bsls::TimeInterval &timeout)
Definition bdlcc_deque.h:2227
void forcePushFront(const TYPE &item)
Definition bdlcc_deque.h:1893
int timedPopBack(TYPE *item, const bsls::TimeInterval &timeout)
Definition bdlcc_deque.h:2127
int tryPopBack(TYPE *item)
Definition bdlcc_deque.h:2267
void tryPopFront(size_type maxNumItems, bsl::vector< TYPE > *buffer)
int timedPushBack(const TYPE &item, const bsls::TimeInterval &timeout)
Definition bdlcc_deque.h:2187
size_type length() const
Definition bdlcc_deque.h:2545
void tryPopBack(size_type maxNumItems, std::vector< TYPE > *buffer)
void tryPopBack(size_type maxNumItems, bsl::vector< TYPE > *buffer)
void removeAll()
Definition bdlcc_deque.h:2098
int tryPopFront(TYPE *item)
Definition bdlcc_deque.h:2327
TYPE popFront()
Definition bdlcc_deque.h:1991
void forcePushBack(const TYPE &item)
Definition bdlcc_deque.h:1843
MonoDeque::size_type size_type
Definition bdlcc_deque.h:553
void tryPopFront(size_type maxNumItems, std::vector< TYPE > *buffer)
bsls::SystemClockType::Enum clockType() const
Definition bdlcc_deque.h:2526
void tryPopBack(size_type maxNumItems)
size_type highWaterMark() const
Return the high-water mark value for this container.
Definition bdlcc_deque.h:2533
int tryPushFront(const TYPE &item)
Definition bdlcc_deque.h:2450
void pushFront(const TYPE &item)
Definition bdlcc_deque.h:2067
void tryPopFront(size_type maxNumItems)
iterator end() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_deque.h:1940
size_type size() const BSLS_KEYWORD_NOEXCEPT
Return the number of elements contained by this deque.
Definition bslstl_deque.h:2074
iterator begin() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_deque.h:1932
std::size_t size_type
Definition bslstl_deque.h:606
Definition bslstl_deque.h:772
iterator insert(const_iterator position, const VALUE_TYPE &value)
Definition bslstl_deque.h:3671
ConstIterator const_iterator
Definition bslstl_deque.h:823
iterator erase(const_iterator position)
Definition bslstl_deque.h:3897
Iterator iterator
Definition bslstl_deque.h:822
std::size_t size_type
Definition bslstl_deque.h:824
Definition bslstl_vector.h:1025
Definition bslma_allocator.h:457
Definition bslmf_movableref.h:751
Definition bslmt_condition.h:220
Definition bslmt_lockguard.h:234
T * release()
Definition bslmt_lockguard.h:493
Definition bslmt_mutex.h:315
void lock()
Definition bslmt_mutex.h:392
void unlock()
Definition bslmt_mutex.h:410
Definition bsls_timeinterval.h:301
#define BSLMF_ASSERT(expr)
Definition bslmf_assert.h:229
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1804
#define BSLS_ASSERT_OPT(X)
Definition bsls_assert.h:1856
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
bsl::size_t size(const TYPE &array)
Return the number of elements in the specified array.
Definition bdlcc_boundedqueue.h:270
Definition balxml_encoderoptions.h:68
Definition bdlt_iso8601util.h:691
Definition bslmf_issame.h:146
Definition bslma_usesbslmaallocator.h:343
static MovableRef< t_TYPE > move(t_TYPE &reference) BSLS_KEYWORD_NOEXCEPT
Definition bslmf_movableref.h:1060
Enum
Definition bsls_systemclocktype.h:117