BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bslstl_queue.h
Go to the documentation of this file.
1/// @file bslstl_queue.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslstl_queue.h -*-C++-*-
8#ifndef INCLUDED_BSLSTL_QUEUE
9#define INCLUDED_BSLSTL_QUEUE
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslstl_queue bslstl_queue
15/// @brief Provide container adapter class template `queue`.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslstl
19/// @{
20/// @addtogroup bslstl_queue
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslstl_queue-purpose"> Purpose</a>
25/// * <a href="#bslstl_queue-classes"> Classes </a>
26/// * <a href="#bslstl_queue-canonical-header"> Canonical Header </a>
27/// * <a href="#bslstl_queue-description"> Description </a>
28/// * <a href="#bslstl_queue-requirements-on-container"> Requirements on CONTAINER </a>
29/// * <a href="#bslstl_queue-required-types"> Required Types </a>
30/// * <a href="#bslstl_queue-required-methods-free-operators-and-free-functions"> Required Methods, Free Operators, and Free Functions </a>
31/// * <a href="#bslstl_queue-requirements-on-value"> Requirements on VALUE </a>
32/// * <a href="#bslstl_queue-value-and-container-value_type"> VALUE and CONTAINER::value_type </a>
33/// * <a href="#bslstl_queue-memory-allocation"> Memory Allocation </a>
34/// * <a href="#bslstl_queue-usage"> Usage </a>
35/// * <a href="#bslstl_queue-example-1-messages-queue"> Example 1: Messages Queue </a>
36///
37/// # Purpose {#bslstl_queue-purpose}
38/// Provide container adapter class template `queue`.
39///
40/// # Classes {#bslstl_queue-classes}
41///
42/// - bsl::queue: class template of a first-in-first-out data structure
43///
44/// # Canonical Header {#bslstl_queue-canonical-header}
45/// bsl_queue.h
46///
47/// @see bslstl_priorityqueue, bslstl_stack
48///
49/// # Description {#bslstl_queue-description}
50/// This component defines a class template, `bsl::queue`, holding
51/// a container (of a parameterized type `CONTAINER` containing elements of
52/// another parameterized type `VALUE`), and adapting it to provide a
53/// first-in-first-out queue data structure.
54///
55/// An instantiation of `queue` is an allocator-aware, value-semantic type whose
56/// salient attributes are its size (number of elements held) and the sequence
57/// of values (of held elements) in the order that they were pushed into the
58/// `queue`. If `queue` is instantiated with a parameterized type `VALUE` that
59/// is not itself value-semantic, then it will not retain all of its
60/// value-semantic qualities.
61///
62/// A queue meets the requirements of a container adaptor as described in the
63/// C++ standard [queue]. The `queue` implemented here adheres to the C++11
64/// standard when compiled with a C++11 compiler, and makes the best
65/// approximation when compiled with a C++03 compiler. In particular, for C++03
66/// we emulate move semantics, but limit forwarding (in `emplace`) to `const`
67/// lvalues, and make no effort to emulate `noexcept` or initializer-lists.
68///
69/// ## Requirements on CONTAINER {#bslstl_queue-requirements-on-container}
70///
71///
72/// The `bsl::queue` adapter can accept for its (optional) `CONTAINER` template
73/// parameter `bsl::deque` (the default), `bsl::vector`, or other container
74/// classes that support the following types and methods.
75///
76/// ### Required Types {#bslstl_queue-required-types}
77///
78///
79/// * `value_type`
80/// * `reference`
81/// * @ref const_reference
82/// * `size_type`
83/// * `allocator_type` (if any `queue` constructor taking an allocator is used)
84///
85/// ### Required Methods, Free Operators, and Free Functions {#bslstl_queue-required-methods-free-operators-and-free-functions}
86///
87///
88/// * `void push_back(const value_type&)` (and variant taking rvalue reference)
89/// * `void pop_front()`
90/// * `reference front()`
91/// * `reference back()`
92/// * `bool empty() const`
93/// * `size_type size() const`
94/// * `const_reference front() const`
95/// * `const_reference back() const`
96/// * @ref emplace_back
97/// * copy-assignment and move-assignment operators
98/// * free `==`, `!=`, `<`, `>`, `<=`, `>=` operators
99/// * free `swap` function (found via ADL with `std::swap` in the lookup set)
100///
101/// ## Requirements on VALUE {#bslstl_queue-requirements-on-value}
102///
103///
104/// The following term is used to more precisely specify the requirements on
105/// template parameter types in function-level documentation:
106///
107/// * *equality-comparable*
108/// > The type provides an equality-comparison operator that defines an
109/// > equivalence relationship and is both reflexive and transitive.
110///
111/// ### VALUE and CONTAINER::value_type {#bslstl_queue-value-and-container-value_type}
112///
113///
114/// When the `CONTAINER` template parameter is omitted the `VALUE` template
115/// parameter specifies the `value_type` of `bsl::vector`, the default container
116/// type. The `VALUE` template has no other role.
117///
118/// For C++17 and later, the behavior is undefined unless:
119/// @code
120/// true == bsl::is_same<VALUE, typename CONTAINER::value_type>::value
121/// @endcode
122/// Prior to C++17, `CONTAINER::value_type` determines the contained value type
123/// and `VALUE` is simply ignored. The resulting code may work with instances
124/// of `VALUE` (e.g., `VALUE` is convertible to `CONTAINER::value_type`) or not
125/// (compiler errors).
126///
127/// ## Memory Allocation {#bslstl_queue-memory-allocation}
128///
129///
130/// The type supplied as `ALLOCATOR` template parameter in some of `queue`
131/// constructors determines how the held container (of parameterized
132/// `CONTAINER`) will allocate memory. A `queue` supports allocators meeting
133/// the requirements of the C++11 standard [allocator.requirements] as long as
134/// the held container does. In addition it supports scoped-allocators derived
135/// from the `bslma::Allocator` memory allocation protocol. Clients intending
136/// to use `bslma` style allocators should use `bsl::allocator` as the
137/// `ALLOCATOR` template parameter, providing a C++11 standard-compatible
138/// adapter for a `bslma::Allocator` object.
139///
140/// ## Usage {#bslstl_queue-usage}
141///
142///
143/// In this section we show intended use of this component.
144///
145/// ### Example 1: Messages Queue {#bslstl_queue-example-1-messages-queue}
146///
147///
148/// In this example, we will use the `bsl::queue` container adapter to implement
149/// a message processor in a server program that receives and displays messages
150/// from clients.
151///
152/// Suppose we want to write a server program that has two threads: one thread
153/// (receiving thread) receives messages from clients, passing them to a message
154/// processor; the other thread (processing thread) runs the message processor,
155/// printing the messages to the console in the same order as they were
156/// received. To accomplish this task, we can use `bsl::queue` in the message
157/// processor to buffer received, but as yet unprinted, messages. The message
158/// processor pushes newly received messages onto the queue in the receiving
159/// thread, and pops them off the queue in the processing thread.
160///
161/// First, we define a `Message` type:
162/// @code
163/// struct Message {
164/// int d_msgId; // message identifier given by client
165/// const char *d_msg_p; // message content (C-style string, not owned)
166/// };
167/// @endcode
168/// Then, we define the class `MessageProcessor`, which provides methods to
169/// receive and process messages:
170/// @code
171/// /// This class receives and processes messages from clients.
172/// class MessageProcessor {
173/// @endcode
174/// Here, we define a private data member of `bsl::queue<Message>` type, which
175/// is an instantiation of `bsl::queue` that uses `Message` for its `VALUE`
176/// (template parameter) type and (by default) `bsl::deque<Message>` for its
177/// `CONTAINER` (template parameter) type:
178/// @code
179/// // DATA
180/// bsl::queue<Message> d_msgQueue; // queue holding received but
181/// // unprocessed messages
182/// // ...
183///
184/// public:
185/// // CREATORS
186///
187/// /// Create a message processor object. Optionally specify a
188/// /// `basicAllocator` used to supply memory. If `basicAllocator` is 0,
189/// /// the currently installed default allocator is used.
190/// explicit MessageProcessor(bslma::Allocator *basicAllocator = 0);
191///
192/// // MANIPULATORS
193///
194/// /// Enqueue the specified `message` onto this message processor.
195/// void receiveMessage(const Message &message);
196///
197/// /// Dequeue all messages currently contained by this processor,
198/// /// and print them to the console if the specified `verbose` flag
199/// /// is not 0.
200/// void processMessages(int verbose);
201/// };
202/// @endcode
203/// Next, we implement the `MessageProcessor` constructor:
204/// @code
205/// MessageProcessor::MessageProcessor(bslma::Allocator *basicAllocator)
206/// : d_msgQueue(basicAllocator)
207/// {
208/// }
209/// @endcode
210/// Notice that we pass to the contained `d_msgQueue` object the
211/// `bslma::Allocator*` supplied to the `MessageProcessor` at construction.
212///
213/// Now, we implement the `receiveMessage` method, which pushes the given
214/// message onto the queue object:
215/// @code
216/// void MessageProcessor::receiveMessage(const Message &message)
217/// {
218/// // ... (some synchronization)
219///
220/// d_msgQueue.push(message);
221///
222/// // ...
223/// }
224/// @endcode
225/// Finally, we implement the `processMessages` method, which pops all messages
226/// off the queue object:
227/// @code
228/// void MessageProcessor::processMessages(int verbose)
229/// {
230/// // ... (some synchronization)
231///
232/// while (!d_msgQueue.empty()) {
233/// const Message& message = d_msgQueue.front();
234/// if (verbose) {
235/// printf("Msg %d: %s\n", message.d_msgId, message.d_msg_p);
236/// }
237/// d_msgQueue.pop();
238/// }
239///
240/// // ...
241/// }
242/// @endcode
243/// Note that the sequence of messages popped from the queue will be in exactly
244/// the same order in which they were pushed, due to the first-in-first-out
245/// property of the queue.
246/// @}
247/** @} */
248/** @} */
249
250/** @addtogroup bsl
251 * @{
252 */
253/** @addtogroup bslstl
254 * @{
255 */
256/** @addtogroup bslstl_queue
257 * @{
258 */
259
260#include <bslscm_version.h>
261
262#include <bslstl_compare.h>
263#include <bslstl_deque.h>
264#include <bslstl_iterator.h>
265#include <bslstl_iteratorutil.h>
266#include <bslstl_ranges.h>
267
268#include <bslalg_swaputil.h>
269
270#include <bslma_isstdallocator.h>
272
273#include <bslmf_assert.h>
275#include <bslmf_enableif.h>
276#include <bslmf_isconvertible.h>
277#include <bslmf_issame.h>
278#include <bslmf_movableref.h>
280#include <bslmf_usesallocator.h>
281#include <bslmf_util.h> // 'forward(V)'
282
284#include <bsls_libraryfeatures.h>
285#include <bsls_keyword.h>
286#include <bsls_platform.h>
287#include <bsls_util.h> // 'forward<T>(V)'
288
289#if defined(BSLS_LIBRARYFEATURES_HAS_CPP20_CONCEPTS) \
290 && defined(BSLS_LIBRARYFEATURES_HAS_CPP20_RANGES)
291# define BSLSTL_QUEUE_REQUIRES_CONTAINER_COMPATIBLE_RANGE(R, T) \
292 requires ::BloombergLP::bslmf::ContainerCompatibleRange<R, T>
293#else
294# define BSLSTL_QUEUE_REQUIRES_CONTAINER_COMPATIBLE_RANGE(R, T)
295#endif
296
297#if BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
298// clang-format off
299// Include version that can be compiled with C++03
300// Generated on Mon Jan 13 08:31:39 2025
301// Command line: sim_cpp11_features.pl bslstl_queue.h
302
303# define COMPILING_BSLSTL_QUEUE_H
304# include <bslstl_queue_cpp03.h>
305# undef COMPILING_BSLSTL_QUEUE_H
306
307// clang-format on
308#else
309
310namespace bsl {
311
312 // ===========
313 // class queue
314 // ===========
315
316/// This class is a value-semantic class template, having a container of the
317/// parameterized `CONTAINER` type that holds elements of the parameterized
318/// `VALUE` type, to provide a first-in-first-out queue data structure. The
319/// container object held by a `queue` class object is referenced as `c` in
320/// the following function-level documentation.
321///
322/// See @ref bslstl_queue
323template <class VALUE, class CONTAINER = deque<VALUE> >
324class queue {
325
326#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY
327 // STATIC CHECK: Type mismatch is UB per C++17
329#endif
330
331 // FRIENDS
332 template <class VALUE2, class CONTAINER2>
335
336 template <class VALUE2, class CONTAINER2>
339
340 template <class VALUE2, class CONTAINER2>
343
344 template <class VALUE2, class CONTAINER2>
347
348 template <class VALUE2, class CONTAINER2>
351
352 template <class VALUE2, class CONTAINER2>
355
356#if defined BSLS_COMPILERFEATURES_SUPPORT_THREE_WAY_COMPARISON \
357 && defined BSLS_LIBRARYFEATURES_HAS_CPP20_CONCEPTS
358 template <class VALUE2, three_way_comparable CONTAINER2>
359 friend compare_three_way_result_t<CONTAINER2>
360 operator<=>(const queue<VALUE2, CONTAINER2>&,
362#endif
363
364 // PRIVATE TYPES
365
366 /// This `typedef` is a convenient alias for the utility associated with
367 /// movable references.
368 typedef BloombergLP::bslmf::MovableRefUtil MoveUtil;
369
370 // PRIVATE MANIPULATORS
371
372 /// Push onto the back of this queue the elements of the specified
373 /// `[first, last)` range.
374 template <class INPUT_ITER, class SENTINEL>
375 void privatePushRange(INPUT_ITER first, SENTINEL last);
376
377 public:
378 // PUBLIC TYPES
379 typedef typename CONTAINER::value_type value_type;
380 typedef typename CONTAINER::reference reference;
381 typedef typename CONTAINER::const_reference const_reference;
382 typedef typename CONTAINER::size_type size_type;
383 typedef CONTAINER container_type;
384
385 protected:
386 // PROTECTED DATA
387 CONTAINER c; // Contains the elements of this queue.
388 // 'protected' and named ('c') per the C++11 standard.
389
390 public:
391 // TRAITS
393 queue,
394 BloombergLP::bslma::UsesBslmaAllocator,
395 BloombergLP::bslma::UsesBslmaAllocator<container_type>::value);
396
397 // CREATORS
398
399 /// Create an empty queue having a container of the parameterized
400 /// `CONTAINER` type.
401 explicit queue();
402
403 /// Create a queue having the value of the specified `original`.
404 queue(const queue& original);
405
406 /// Create a queue having the value of the specified `original`. The
407 /// allocator associated with `original` (if any) is propagated for use
408 /// in the new queue. `original` is left in valid but unspecified
409 /// state.
410 queue(BloombergLP::bslmf::MovableRef<queue> container);
411
412 /// Create a queue having the specified `container` that holds elements
413 /// of the parameterized `VALUE` type.
414 explicit queue(const CONTAINER& container);
415
416 /// Create a queue having the same sequence of values as the specified
417 /// `container`. The allocator associated with `container` (if any) is
418 /// propagated for use in the new queue. `container` is left in valid
419 /// but unspecified state.
420 explicit queue(BloombergLP::bslmf::MovableRef<CONTAINER> container);
421
422 /// Create an empty queue. This queue object uses the specified `basicAllocator` to supply memory.
423 ///
424 /// \note Note that the `ALLOCATOR`
425 /// parameter type has to be convertible to the allocator of the
426 /// `CONTAINER` parameter type, `CONTAINER::allocator_type`; otherwise,
427 /// this constructor is disabled.
428 template <class ALLOCATOR>
429 explicit
430 queue(const ALLOCATOR& basicAllocator,
432 ALLOCATOR>::type * = 0);
433
434 /// Create a queue having the same sequence of values as the specified
435 /// `container`. The queue object uses the specified `basicAllocator` to obtain memory.
436 ///
437 /// \note Note that the `ALLOCATOR` parameter type has to
438 /// be convertible to the allocator of the `CONTAINER` parameter type,
439 /// `CONTAINER::allocator_type`; otherwise, this constructor is
440 /// disabled.
441 template <class ALLOCATOR>
442 queue(const CONTAINER& container,
443 const ALLOCATOR& basicAllocator,
445 ALLOCATOR>::type * = 0);
446
447 /// Create a queue having the value of the specified `original` that
448 /// will use the specified `basicAllocator` to supply memory.
449 ///
450 /// \note Note that the `ALLOCATOR` parameter type has to be convertible to the
451 /// allocator of the `CONTAINER` parameter type,
452 /// `CONTAINER::allocator_type`. Otherwise this constructor is
453 /// disabled.
454 template <class ALLOCATOR>
455 queue(const queue& original,
456 const ALLOCATOR& basicAllocator,
458 ALLOCATOR>::type * = 0);
459
460 /// Create a queue whose underlying container has the value of the
461 /// specified `container` (on entry) and uses `basicAllocator` to supply
462 /// memory. The allocated-extended move constructor of `CONTAINER` is
463 /// used to create the new queue. `container` is left in a valid but unspecified state.
464 ///
465 /// \note Note that a `bslma::Allocator *` can be supplied
466 /// for `basicAllocator` if the (template parameter) `ALLOCATOR` is
467 /// `bsl::allocator` (the default). Also note that this method assumes
468 /// that `CONTAINER` has a move constructor. Also note that if
469 /// `CONTAINER::allocator_type` does not exist, this constructor is
470 /// disabled.
471 template <class ALLOCATOR>
472 queue(BloombergLP::bslmf::MovableRef<CONTAINER> container,
473 const ALLOCATOR& basicAllocator,
475 ALLOCATOR>::type * = 0);
476
477 /// Create a queue having the value of the specified `original` (on
478 /// entry), that uses `basicAllocator` to supply memory. The
479 /// allocator-extended move constructor of `CONTAINER` is used to create
480 /// the new queue. `original` is left in a valid but unspecified state.
481 ///
482 /// \note Note that a `bslma::Allocator *` can be supplied for
483 /// `basicAllocator` if the (template parameter) `ALLOCATOR` is
484 /// `bsl::allocator` (the default). Also note that this method assumes
485 /// that `CONTAINER` has a move constructor. Also note that if
486 /// `CONTAINER::allocator_type` does not exist, this constructor is
487 /// disabled.
488 template <class ALLOCATOR>
489 queue(BloombergLP::bslmf::MovableRef<queue> original,
490 const ALLOCATOR& basicAllocator,
492 ALLOCATOR>::type * = 0);
493
494 /// Create a queue passing the specified `first` and `last` to the
495 /// constructor of the underlying container. Optionally specify an
496 /// `allocator` used to supply memory. If `allocator` is not specified, a
497 /// default-constructed object of the (template parameter) type `ALLOCATOR`
498 /// is used.
499 template <class INPUT_ITER>
500 queue(INPUT_ITER first, INPUT_ITER last);
501 template <class INPUT_ITER, class ALLOCATOR>
502 queue(INPUT_ITER first,
503 INPUT_ITER last,
504 const ALLOCATOR& allocator,
506 ALLOCATOR>::type * = 0);
507
508 /// Create a queue from the elements of the specifed `range`. Optionally
509 /// specify an `allocator` used to supply memory. If `allocator` is not
510 /// specified, a default-constructed object of the (template parameter) type `t_ALLOCATOR` is used.
511 ///
512 /// \note Note that `range` must meet the
513 /// requirements of an input range and the values from `range` must have a
514 /// type matching or convertible to (template parameter) `VALUE`.
515 template <class t_RANGE>
518 template <class t_RANGE, class t_ALLOCATOR>
522 const t_ALLOCATOR& allocator,
523 typename enable_if<bsl::uses_allocator<CONTAINER,t_ALLOCATOR>::value,
524 t_ALLOCATOR>::type * = 0);
525
526 // MANIPULATORS
527
528 /// Assign to this queue the value of the specified `rhs`, and return a
529 /// reference providing modifiable access to this queue.
530 queue& operator=(const queue& rhs);
531
532 /// Assign to this queue the value as the specified `rhs` and return a
533 /// reference providing modifiable access to this queue. The
534 /// move-assignment operator of `CONTAINER` is used to set the value of
535 /// this queue. `rhs` is left in a valid but unspecified state, and if
536 /// an exception is thrown, `*this` is left in a valid but unspecified
537 /// state.
538 queue& operator=(BloombergLP::bslmf::MovableRef<queue> rhs);
539
540#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
541 /// Push onto this queue a newly created `value_type` object constructed
542 /// by forwarding `get_allocator()` (if required) and the specified
543 /// (variable number of) `args` to the corresponding constructor of
544 /// `value_type`. Return a reference providing modifiable access to the
545 /// inserted element.
546 template <class... Args>
547 reference emplace(Args&&... args);
548#endif
549
550 /// Push onto the back of this queue a `value_type` object having the
551 /// specified `value`.
552 void push(const value_type& value);
553
554 /// Push onto the back of this queue a `value_type` object having the
555 /// value of the specified `value` (on entry) by moving the
556 /// contents of `value` to the new object on this queue. `value` is
557 /// left in a valid but unspecified state.
558 void push(BloombergLP::bslmf::MovableRef<value_type> value);
559
560 /// Push onto the back of this queue the elements of the specified `range`.
561 ///
562 /// \note Note that `range` must meet the requirements of an input range and the
563 /// values from `range` must have a type matching or convertible to
564 /// (template parameter) `VALUE`.
565 template <class t_RANGE>
568
569 /// Remove the front (the earliest pushed) element from this `queue`
570 /// object.
571 void pop();
572
573 /// Efficiently exchange the value of this object with the value of the
574 /// specified `other` object. In effect, performs
575 /// `using bsl::swap; swap(c, other.c);`.
577 bsl::is_nothrow_swappable<CONTAINER>::value);
578
579 /// Return a reference providing modifiable access to the front (the
580 /// earliest pushed) element from this `queue` object.
582
583 /// Return a reference providing modifiable access to the back (the
584 /// latest pushed) element of this `queue` object.
586
587 // ACCESSORS
588
589 /// Return `true` if this `queue` object contains no elements, and
590 /// `false` otherwise. In effect, performs `return c.empty();`.
591 bool empty() const;
592
593 /// Return the number of elements in this queue. In effect, performs
594 /// `return c.size();`.
596
597 /// Return the immutable front (the earliest pushed) element from this
598 /// `queue` object. In effect, performs `c.front()`.
600
601 /// Return the immutable back (the latest pushed) element from this
602 /// `queue` object. In effect, performs `c.back()`.
604};
605
606#ifdef BSLS_COMPILERFEATURES_SUPPORT_CTAD
607// CLASS TEMPLATE DEDUCTION GUIDES
608
609/// Deduce the template parameters `VALUE` and `CONTAINER` from the
610/// parameters supplied to the constructor of `queue`. This deduction guide
611/// does not participate if the parameter meets the requirements for a
612/// standard allocator.
613template<class CONTAINER,
614 class = bsl::enable_if_t<!bsl::IsStdAllocator_v<CONTAINER>>
615 >
617
618/// Deduce the template parameters `VALUE` and `CONTAINER` from the
619/// parameters supplied to the constructor of `queue`. This deduction
620/// guide does not participate unless the supplied allocator is convertible
621/// to the underlying container's `allocator_type`.
622template<
623 class CONTAINER,
624 class ALLOCATOR,
625 class = bsl::enable_if_t<bsl::uses_allocator_v<CONTAINER, ALLOCATOR>>
626 >
628
629/// Deduce the template parameter `VALUE` from the parameters supplied to the
630/// constructor of `queue`.
631template <class INPUT_ITER,
632 class TYPE = BloombergLP::bslstl::IteratorUtil::
633 IterVal_t<INPUT_ITER>>
634queue(INPUT_ITER, INPUT_ITER) -> queue<TYPE>;
635
636/// Deduce the template parameters `VALUE` and `CONTAINER` from the parameters
637/// supplied to the constructor of `queue`. This deduction guide does not
638/// participate unless the `ALLOCATOR` parameter meets the requirements for a
639/// standard allocator.
640template <class INPUT_ITER,
641 class ALLOCATOR,
642 class TYPE = BloombergLP::bslstl::IteratorUtil::
643 IterVal_t<INPUT_ITER>,
644 class = enable_if_t<IsStdAllocator_v<ALLOCATOR>>>
645queue(INPUT_ITER, INPUT_ITER, ALLOCATOR)-> queue<TYPE, deque<TYPE, ALLOCATOR>>;
646
647#if defined(BSLS_LIBRARYFEATURES_HAS_CPP20_CONCEPTS) \
648 && defined(BSLS_LIBRARYFEATURES_HAS_CPP20_RANGES)
649/// Deduce the template parameter `VALUE` from the parameters supplied to the
650/// constructor of `queue`.
651template <ranges::input_range t_RANGE>
653
654/// Deduce the template parameters `VALUE` and `ALLOCATOR` from the parameters
655/// supplied to the constructor of `queue`. This deduction guide does not
656/// participate unless the `t_ALLOCATOR` parameter meets the requirements for a
657/// standard allocator.
658template <ranges::input_range t_RANGE,
659 class t_ALLOCATOR,
660 class t_TYPE = ranges::range_value_t<t_RANGE>>
661requires IsStdAllocator_v<t_ALLOCATOR>
662queue(from_range_t, t_RANGE&&, t_ALLOCATOR)
664#endif
665#endif
666
667// FREE OPERATORS
668
669/// Return `true` if the specified `lhs` and `rhs` objects have the same
670/// value, and `false` otherwise. Two `queue` objects `lhs` and `rhs` have
671/// the same value if they have the same number of elements, and each
672/// element in the ordered sequence of elements of `lhs` has the same value
673/// as the corresponding element in the ordered sequence of elements of
674/// `rhs`. This method requires that the (template parameter) type `VALUE`
675/// be `equality-comparable` (see {Requirements on `VALUE`}).
676template <class VALUE, class CONTAINER>
679
680/// Return `true` if the specified `lhs` and `rhs` objects do not have the
681/// same value, and `false` otherwise. Two `queue` objects `lhs` and `rhs`
682/// do not have the same value if they do not have the same number of
683/// elements, or some element in the ordered sequence of elements of `lhs`
684/// does not have the same value as the corresponding element in the ordered
685/// sequence of elements of `rhs`. This method requires that the (template
686/// parameter) type `VALUE` be `equality-comparable` (see {Requirements on
687/// `VALUE`}).
688template <class VALUE, class CONTAINER>
691
692/// Return `true` if the value of the specified `lhs` queue is
693/// lexicographically less than that of the specified `rhs` queue, and
694/// `false` otherwise. Given iterators `i` and `j` over the respective
695/// sequences `[lhs.begin() .. lhs.end())` and `[rhs.begin() .. rhs.end())`,
696/// the value of queue `lhs` is lexicographically less than that of queue
697/// `rhs` if `true == *i < *j` for the first pair of corresponding iterator
698/// positions where `*i < *j` and `*j < *i` are not both `false`. If no
699/// such corresponding iterator position exists, the value of `lhs` is
700/// lexicographically less than that of `rhs` if `lhs.size() < rhs.size()`.
701/// This method requires that `operator<`, inducing a total order, be
702/// defined for `value_type`.
703template <class VALUE, class CONTAINER>
706
707/// Return `true` if the value of the specified `lhs` queue is
708/// lexicographically greater than that of the specified `rhs` queue, and
709/// `false` otherwise. The value of queue `lhs` is lexicographically
710/// greater than that of queue `rhs` if `rhs` is lexicographically less than
711/// `lhs` (see `operator<`). This method requires that `operator<`, inducing a total order, be defined for `value_type`.
712///
713/// \note Note that this
714/// operator returns `rhs < lhs`.
715template <class VALUE, class CONTAINER>
718
719/// Return `true` if the value of the specified `lhs` queue is
720/// lexicographically less than or equal to that of the specified `rhs`
721/// queue, and `false` otherwise. The value of queue `lhs` is
722/// lexicographically less than or equal to that of queue `rhs` if `rhs` is
723/// not lexicographically less than `lhs` (see `operator<`). This method
724/// requires that `operator<`, inducing a total order, be defined for `value_type`.
725///
726/// \note Note that this operator returns `!(rhs < lhs)`.
727template <class VALUE, class CONTAINER>
730
731/// Return `true` if the value of the specified `lhs` queue is
732/// lexicographically greater than or equal to that of the specified `rhs`
733/// queue, and `false` otherwise. The value of queue `lhs` is
734/// lexicographically greater than or equal to that of queue `rhs` if `lhs`
735/// is not lexicographically less than `rhs` (see `operator<`). This method
736/// requires that `operator<`, inducing a total order, be defined for `value_type`.
737///
738/// \note Note that this operator returns `!(lhs < rhs)`.
739template <class VALUE, class CONTAINER>
742
743// FREE FUNCTIONS
744
745/// Swap the value of the specified `lhs` queue with the value of the
746/// specified `rhs` queue.
747template <class VALUE, class CONTAINER>
751
752// ============================================================================
753// TEMPLATE AND INLINE FUNCTION DEFINITIONS
754// ============================================================================
755
756 // -----------
757 // class queue
758 // -----------
759
760// CREATORS
761template <class VALUE, class CONTAINER>
762inline
766
767template <class VALUE, class CONTAINER>
768inline
770: c(original.c)
771{
772}
773
774template <class VALUE, class CONTAINER>
775inline
776queue<VALUE, CONTAINER>::queue(BloombergLP::bslmf::MovableRef<queue> original)
777: c(MoveUtil::move(MoveUtil::access(original).c))
778{
779}
780
781template <class VALUE, class CONTAINER>
782inline
783queue<VALUE, CONTAINER>::queue(const CONTAINER& container)
784: c(container)
785{
786}
787
788template <class VALUE, class CONTAINER>
789template <class ALLOCATOR>
790inline
792 const ALLOCATOR& basicAllocator,
794 ALLOCATOR>::type *)
795: c(basicAllocator)
796{
797}
798
799template <class VALUE, class CONTAINER>
800template <class ALLOCATOR>
801inline
803 const CONTAINER& container,
804 const ALLOCATOR& basicAllocator,
806 ALLOCATOR>::type *)
807: c(container, basicAllocator)
808{
809}
810
811template <class VALUE, class CONTAINER>
812template <class ALLOCATOR>
813inline
815 const queue& queue,
816 const ALLOCATOR& basicAllocator,
818 ALLOCATOR>::type *)
819: c(queue.c, basicAllocator)
820{
821}
822
823template <class VALUE, class CONTAINER>
824inline
825queue<VALUE, CONTAINER>::queue(BloombergLP::bslmf::MovableRef<CONTAINER>
826 container)
827: c(MoveUtil::move(container))
828{
829}
830
831template <class VALUE, class CONTAINER>
832template <class ALLOCATOR>
833inline
835 BloombergLP::bslmf::MovableRef<CONTAINER> container,
836 const ALLOCATOR& basicAllocator,
838 ALLOCATOR>::type *)
839: c(MoveUtil::move(container), basicAllocator)
840{
841}
842
843template <class VALUE, class CONTAINER>
844template <class ALLOCATOR>
845inline
847 BloombergLP::bslmf::MovableRef<queue> original,
848 const ALLOCATOR& basicAllocator,
850 ALLOCATOR>::type *)
851: c(MoveUtil::move(MoveUtil::access(original).c), basicAllocator)
852{
853}
854
855template <class VALUE, class CONTAINER>
856template <class INPUT_ITER>
857inline
858queue<VALUE, CONTAINER>::queue(INPUT_ITER first, INPUT_ITER last)
859: c(first, last)
860{
861}
862
863template <class VALUE, class CONTAINER>
864template <class INPUT_ITER, class ALLOCATOR>
865inline
867 INPUT_ITER first,
868 INPUT_ITER last,
869 const ALLOCATOR& allocator,
871 ALLOCATOR>::type *)
872: c(first, last, allocator)
873{
874}
875
876template <class VALUE, class CONTAINER>
877template <class t_RANGE>
879inline
883#ifdef BSLS_LIBRARYFEATURES_HAS_CPP23_RANGES_TO_CONTAINER
884: c(ranges::to<CONTAINER>(std::forward<t_RANGE>(range)))
885#else
887#endif
888{
889}
890
891template <class VALUE, class CONTAINER>
892template <class t_RANGE, class t_ALLOCATOR>
894inline
898 const t_ALLOCATOR& allocator,
899 typename enable_if<
901 t_ALLOCATOR>::type *)
902#ifdef BSLS_LIBRARYFEATURES_HAS_CPP23_RANGES_TO_CONTAINER
903: c(ranges::to<CONTAINER>(std::forward<t_RANGE>(range), allocator))
904#else
906#endif
907{
908}
909
910// PRIVATE MANIPULATORS
911template <class VALUE, class CONTAINER>
912template <class INPUT_ITER, class SENTINEL>
913inline
915 SENTINEL last)
916{
917 while (first != last) {
918 push(*first);
919 ++first;
920 }
921}
922
923// MANIPULATORS
924template <class VALUE, class CONTAINER>
925inline
927{
928 c = rhs.c;
929 return *this;
930}
931
932template <class VALUE, class CONTAINER>
933inline
935 BloombergLP::bslmf::MovableRef<queue> rhs)
936{
937 c = MoveUtil::move(MoveUtil::access(rhs).c);
938 return *this;
939}
940
941#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
942template <class VALUE, class CONTAINER>
943template <class... Args>
944inline
947{
948 c.emplace_back(BSLS_COMPILERFEATURES_FORWARD(Args,args)...);
949 return back();
950}
951#endif
952
953template <class VALUE, class CONTAINER>
954inline
956{
957 c.push_back(value);
958}
959
960template <class VALUE, class CONTAINER>
961inline
962void queue<VALUE, CONTAINER>::push(BloombergLP::bslmf::MovableRef<value_type>
963 value)
964{
965 c.push_back(MoveUtil::move(value));
966}
967
968template <class VALUE, class CONTAINER>
969template <class t_RANGE>
971void queue<VALUE, CONTAINER>::push_range(
973{
974#if defined(BSLS_LIBRARYFEATURES_HAS_CPP20_CONCEPTS) \
975 && defined(BSLS_LIBRARYFEATURES_HAS_CPP20_RANGES)
976 if constexpr (requires{ c.append_range(std::forward<t_RANGE>(range)); }) {
977 c.append_range(std::forward<t_RANGE>(range));
978 }
979 else {
980 ranges::copy(range, back_inserter(c));
981 }
982#else
983 privatePushRange(bsl::begin(range), bsl::end(range));
984#endif
985}
986
987template <class VALUE, class CONTAINER>
988inline
990{
991 c.pop_front();
992}
993
994template <class VALUE, class CONTAINER>
995inline
998 bsl::is_nothrow_swappable<CONTAINER>::value)
999{
1000 BloombergLP::bslalg::SwapUtil::swap(&c, &other.c);
1001}
1002
1003// ACCESSORS
1004template <class VALUE, class CONTAINER>
1005inline
1007{
1008 return c.empty();
1009}
1010
1011template <class VALUE, class CONTAINER>
1012inline
1015{
1016 return c.size();
1017}
1018
1019template <class VALUE, class CONTAINER>
1020inline
1023{
1024 return c.front();
1025}
1026
1027template <class VALUE, class CONTAINER>
1028inline
1031{
1032 return c.front();
1033}
1034
1035template <class VALUE, class CONTAINER>
1036inline
1039{
1040 return c.back();
1041}
1042
1043template <class VALUE, class CONTAINER>
1044inline
1047{
1048 return c.back();
1049}
1050
1051// FREE OPERATORS
1052template <class VALUE, class CONTAINER>
1053inline
1054bool operator==(const queue<VALUE, CONTAINER>& lhs,
1056{
1057 return lhs.c == rhs.c;
1058}
1059
1060template <class VALUE, class CONTAINER>
1061inline
1062bool operator!=(const queue<VALUE, CONTAINER>& lhs,
1064{
1065 return lhs.c != rhs.c;
1066}
1067
1068template <class VALUE, class CONTAINER>
1069inline
1070bool operator< (const queue<VALUE, CONTAINER>& lhs,
1072{
1073 return lhs.c < rhs.c;
1074}
1075
1076template <class VALUE, class CONTAINER>
1077inline
1078bool operator> (const queue<VALUE, CONTAINER>& lhs,
1080{
1081 return lhs.c > rhs.c;
1082}
1083
1084template <class VALUE, class CONTAINER>
1085inline
1086bool operator<=(const queue<VALUE, CONTAINER>& lhs,
1088{
1089 return lhs.c <= rhs.c;
1090}
1091
1092template <class VALUE, class CONTAINER>
1093inline
1094bool operator>=(const queue<VALUE, CONTAINER>& lhs,
1096{
1097 return lhs.c >= rhs.c;
1098}
1099
1100#if defined BSLS_COMPILERFEATURES_SUPPORT_THREE_WAY_COMPARISON \
1101 && defined BSLS_LIBRARYFEATURES_HAS_CPP20_CONCEPTS
1102template <class VALUE, three_way_comparable CONTAINER>
1103inline compare_three_way_result_t<CONTAINER>
1104operator<=>(const queue<VALUE, CONTAINER>& lhs,
1105 const queue<VALUE, CONTAINER>& rhs)
1106{
1107 return lhs.c <=> rhs.c;
1108}
1109#endif
1110
1111// FREE FUNCTIONS
1112template <class VALUE, class CONTAINER>
1113inline
1120
1121} // close namespace bsl
1122
1123#endif // End C++11 code
1124
1125#undef BSLSTL_QUEUE_REQUIRES_CONTAINER_COMPATIBLE_RANGE
1126
1127#endif
1128
1129// ----------------------------------------------------------------------------
1130// Copyright 2016 Bloomberg Finance L.P.
1131//
1132// Licensed under the Apache License, Version 2.0 (the "License");
1133// you may not use this file except in compliance with the License.
1134// You may obtain a copy of the License at
1135//
1136// http://www.apache.org/licenses/LICENSE-2.0
1137//
1138// Unless required by applicable law or agreed to in writing, software
1139// distributed under the License is distributed on an "AS IS" BASIS,
1140// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1141// See the License for the specific language governing permissions and
1142// limitations under the License.
1143// ----------------------------- END-OF-FILE ----------------------------------
1144
1145/** @} */
1146/** @} */
1147/** @} */
Definition bslma_bslallocator.h:588
Definition bslstl_queue.h:324
void push(BloombergLP::bslmf::MovableRef< value_type > value)
Definition bslstl_queue.h:962
queue(const queue &original)
Create a queue having the value of the specified original.
Definition bslstl_queue.h:769
friend bool operator==(const queue< VALUE2, CONTAINER2 > &, const queue< VALUE2, CONTAINER2 > &)
void pop()
Definition bslstl_queue.h:989
CONTAINER::const_reference const_reference
Definition bslstl_queue.h:381
size_type size() const
Definition bslstl_queue.h:1014
friend bool operator<=(const queue< VALUE2, CONTAINER2 > &, const queue< VALUE2, CONTAINER2 > &)
queue()
Definition bslstl_queue.h:763
bool empty() const
Definition bslstl_queue.h:1006
BSLMF_NESTED_TRAIT_DECLARATION_IF(queue, BloombergLP::bslma::UsesBslmaAllocator, BloombergLP::bslma::UsesBslmaAllocator< container_type >::value)
friend bool operator>=(const queue< VALUE2, CONTAINER2 > &, const queue< VALUE2, CONTAINER2 > &)
friend bool operator!=(const queue< VALUE2, CONTAINER2 > &, const queue< VALUE2, CONTAINER2 > &)
CONTAINER::value_type value_type
Definition bslstl_queue.h:379
void push_range(BSLS_COMPILERFEATURES_FORWARD_REF(t_RANGE) range)
Definition bslstl_queue.h:971
queue(BloombergLP::bslmf::MovableRef< queue > container)
Definition bslstl_queue.h:776
void push(const value_type &value)
Definition bslstl_queue.h:955
queue(BloombergLP::bslmf::MovableRef< CONTAINER > container)
Definition bslstl_queue.h:825
queue(const ALLOCATOR &basicAllocator, typename enable_if< bsl::uses_allocator< CONTAINER, ALLOCATOR >::value, ALLOCATOR >::type *=0)
Definition bslstl_queue.h:791
queue(const CONTAINER &container)
Definition bslstl_queue.h:783
CONTAINER::size_type size_type
Definition bslstl_queue.h:382
queue(BloombergLP::bslmf::MovableRef< CONTAINER > container, const ALLOCATOR &basicAllocator, typename enable_if< bsl::uses_allocator< CONTAINER, ALLOCATOR >::value, ALLOCATOR >::type *=0)
Definition bslstl_queue.h:834
queue & operator=(const queue &rhs)
Definition bslstl_queue.h:926
void swap(queue &other) BSLS_KEYWORD_NOEXCEPT_SPECIFICATION(bsl reference front()
Definition bslstl_queue.h:581
reference back()
Definition bslstl_queue.h:1038
queue(BloombergLP::bslmf::MovableRef< queue > original, const ALLOCATOR &basicAllocator, typename enable_if< bsl::uses_allocator< CONTAINER, ALLOCATOR >::value, ALLOCATOR >::type *=0)
Definition bslstl_queue.h:846
queue(INPUT_ITER first, INPUT_ITER last, const ALLOCATOR &allocator, typename enable_if< bsl::uses_allocator< CONTAINER, ALLOCATOR >::value, ALLOCATOR >::type *=0)
Definition bslstl_queue.h:866
queue(const queue &original, const ALLOCATOR &basicAllocator, typename enable_if< bsl::uses_allocator< CONTAINER, ALLOCATOR >::value, ALLOCATOR >::type *=0)
Definition bslstl_queue.h:814
CONTAINER container_type
Definition bslstl_queue.h:383
queue(const CONTAINER &container, const ALLOCATOR &basicAllocator, typename enable_if< bsl::uses_allocator< CONTAINER, ALLOCATOR >::value, ALLOCATOR >::type *=0)
Definition bslstl_queue.h:802
queue(INPUT_ITER first, INPUT_ITER last)
Definition bslstl_queue.h:858
CONTAINER::reference reference
Definition bslstl_queue.h:380
friend bool operator<(const queue< VALUE2, CONTAINER2 > &, const queue< VALUE2, CONTAINER2 > &)
friend bool operator>(const queue< VALUE2, CONTAINER2 > &, const queue< VALUE2, CONTAINER2 > &)
reference emplace(Args &&... args)
Definition bslstl_queue.h:946
CONTAINER c
Definition bslstl_queue.h:387
#define BSLMF_ASSERT(expr)
Definition bslmf_assert.h:231
#define BSLS_COMPILERFEATURES_FORWARD_REF(T)
Definition bsls_compilerfeatures.h:2343
#define BSLS_COMPILERFEATURES_FORWARD(T, V)
Definition bsls_compilerfeatures.h:2349
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
#define BSLS_KEYWORD_NOEXCEPT_SPECIFICATION(...)
Definition bsls_keyword.h:676
#define BSLSTL_QUEUE_REQUIRES_CONTAINER_COMPATIBLE_RANGE(R, T)
Definition bslstl_queue.h:294
Definition bdlat_valuetypefunctions.h:939
ALLOCATOR const STRING_VIEW_LIKE_TYPE & rhs
Definition bslstl_string.h:3918
T::iterator begin(T &container)
Definition bslstl_iterator.h:1593
const from_range_t from_range
ALLOCATOR & lhs
Definition bslstl_string.h:3917
T::iterator end(T &container)
Definition bslstl_iterator.h:1621
Definition bdlbb_blob.h:579
Definition bslmf_enableif.h:530
Definition bslstl_ranges.h:301
Definition bslmf_issame.h:146
Definition bslmf_usesallocator.h:165