BDE 4.14.0 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-description"> Description </a>
27/// * <a href="#bslstl_queue-requirements-on-container"> Requirements on CONTAINER </a>
28/// * <a href="#bslstl_queue-required-types"> Required Types </a>
29/// * <a href="#bslstl_queue-required-methods-free-operators-and-free-functions"> Required Methods, Free Operators, and Free Functions </a>
30/// * <a href="#bslstl_queue-requirements-on-value"> Requirements on VALUE </a>
31/// * <a href="#bslstl_queue-value-and-container-value_type"> VALUE and CONTAINER::value_type </a>
32/// * <a href="#bslstl_queue-memory-allocation"> Memory Allocation </a>
33/// * <a href="#bslstl_queue-usage"> Usage </a>
34/// * <a href="#bslstl_queue-example-1-messages-queue"> Example 1: Messages Queue </a>
35///
36/// # Purpose {#bslstl_queue-purpose}
37/// Provide container adapter class template `queue`.
38///
39/// # Classes {#bslstl_queue-classes}
40///
41/// - bsl::queue: class template of a first-in-first-out data structure
42///
43/// **Canonical header:** bsl_queue.h
44///
45/// @see bslstl_priorityqueue, bslstl_stack
46///
47/// # Description {#bslstl_queue-description}
48/// This component defines a class template, `bsl::queue`, holding
49/// a container (of a parameterized type `CONTAINER` containing elements of
50/// another parameterized type `VALUE`), and adapting it to provide a
51/// first-in-first-out queue data structure.
52///
53/// An instantiation of `queue` is an allocator-aware, value-semantic type whose
54/// salient attributes are its size (number of elements held) and the sequence
55/// of values (of held elements) in the order that they were pushed into the
56/// `queue`. If `queue` is instantiated with a parameterized type `VALUE` that
57/// is not itself value-semantic, then it will not retain all of its
58/// value-semantic qualities.
59///
60/// A queue meets the requirements of a container adaptor as described in the
61/// C++ standard [queue]. The `queue` implemented here adheres to the C++11
62/// standard when compiled with a C++11 compiler, and makes the best
63/// approximation when compiled with a C++03 compiler. In particular, for C++03
64/// we emulate move semantics, but limit forwarding (in `emplace`) to `const`
65/// lvalues, and make no effort to emulate `noexcept` or initializer-lists.
66///
67/// ## Requirements on CONTAINER {#bslstl_queue-requirements-on-container}
68///
69///
70/// The `bsl::queue` adapter can accept for its (optional) `CONTAINER` template
71/// parameter `bsl::deque` (the default), `bsl::vector`, or other container
72/// classes that support the following types and methods.
73///
74/// ### Required Types {#bslstl_queue-required-types}
75///
76///
77/// * `value_type`
78/// * `reference`
79/// * @ref const_reference
80/// * `size_type`
81/// * `allocator_type` (if any `queue` constructor taking an allocator is used)
82///
83/// ### Required Methods, Free Operators, and Free Functions {#bslstl_queue-required-methods-free-operators-and-free-functions}
84///
85///
86/// * `void push_back(const value_type&)` (and variant taking rvalue reference)
87/// * `void pop_front()`
88/// * `reference front()`
89/// * `reference back()`
90/// * `bool empty() const`
91/// * `size_type size() const`
92/// * `const_reference front() const`
93/// * `const_reference back() const`
94/// * @ref emplace_back
95/// * copy-assignment and move-assignment operators
96/// * free `==`, `!=`, `<`, `>`, `<=`, `>=` operators
97/// * free `swap` function (found via ADL with `std::swap` in the lookup set)
98///
99/// ## Requirements on VALUE {#bslstl_queue-requirements-on-value}
100///
101///
102/// The following term is used to more precisely specify the requirements on
103/// template parameter types in function-level documentation:
104///
105/// *equality-comparable*:
106/// The type provides an equality-comparison operator that defines an
107/// equivalence relationship and is both reflexive and transitive.
108///
109/// ### VALUE and CONTAINER::value_type {#bslstl_queue-value-and-container-value_type}
110///
111///
112/// When the `CONTAINER` template parameter is omitted the `VALUE` template
113/// parameter specifies the `value_type` of `bsl::vector`, the default container
114/// type. The `VALUE` template has no other role.
115///
116/// For C++17 and later, the behavior is undefined unless:
117/// @code
118/// true == bsl::is_same<VALUE, typename CONTAINER::value_type>::value
119/// @endcode
120/// Prior to C++17, `CONTAINER::value_type` determines the contained value type
121/// and `VALUE` is simply ignored. The resulting code may work with instances
122/// of `VALUE` (e.g., `VALUE` is convertible to `CONTAINER::value_type`) or not
123/// (compiler errors).
124///
125/// ## Memory Allocation {#bslstl_queue-memory-allocation}
126///
127///
128/// The type supplied as `ALLOCATOR` template parameter in some of `queue`
129/// constructors determines how the held container (of parameterized
130/// `CONTAINER`) will allocate memory. A `queue` supports allocators meeting
131/// the requirements of the C++11 standard [allocator.requirements] as long as
132/// the held container does. In addition it supports scoped-allocators derived
133/// from the `bslma::Allocator` memory allocation protocol. Clients intending
134/// to use `bslma` style allocators should use `bsl::allocator` as the
135/// `ALLOCATOR` template parameter, providing a C++11 standard-compatible
136/// adapter for a `bslma::Allocator` object.
137///
138/// ## Usage {#bslstl_queue-usage}
139///
140///
141/// In this section we show intended use of this component.
142///
143/// ### Example 1: Messages Queue {#bslstl_queue-example-1-messages-queue}
144///
145///
146/// In this example, we will use the `bsl::queue` container adapter to implement
147/// a message processor in a server program that receives and displays messages
148/// from clients.
149///
150/// Suppose we want to write a server program that has two threads: one thread
151/// (receiving thread) receives messages from clients, passing them to a message
152/// processor; the other thread (processing thread) runs the message processor,
153/// printing the messages to the console in the same order as they were
154/// received. To accomplish this task, we can use `bsl::queue` in the message
155/// processor to buffer received, but as yet unprinted, messages. The message
156/// processor pushes newly received messages onto the queue in the receiving
157/// thread, and pops them off the queue in the processing thread.
158///
159/// First, we define a `Message` type:
160/// @code
161/// struct Message {
162/// int d_msgId; // message identifier given by client
163/// const char *d_msg_p; // message content (C-style string, not owned)
164/// };
165/// @endcode
166/// Then, we define the class `MessageProcessor`, which provides methods to
167/// receive and process messages:
168/// @code
169/// class MessageProcessor {
170/// // This class receives and processes messages from clients.
171/// @endcode
172/// Here, we define a private data member of `bsl::queue<Message>` type, which
173/// is an instantiation of `bsl::queue` that uses `Message` for its `VALUE`
174/// (template parameter) type and (by default) `bsl::deque<Message>` for its
175/// `CONTAINER` (template parameter) type:
176/// @code
177/// // DATA
178/// bsl::queue<Message> d_msgQueue; // queue holding received but
179/// // unprocessed messages
180/// // ...
181///
182/// public:
183/// // CREATORS
184/// explicit MessageProcessor(bslma::Allocator *basicAllocator = 0);
185/// // Create a message processor object. Optionally specify a
186/// // 'basicAllocator' used to supply memory. If 'basicAllocator' is
187/// // 0, the currently installed default allocator is used.
188///
189/// // MANIPULATORS
190/// void receiveMessage(const Message &message);
191/// // Enqueue the specified 'message' onto this message processor.
192///
193/// void processMessages(int verbose);
194/// // Dequeue all messages currently contained by this processor,
195/// // and print them to the console if the specified 'verbose' flag
196/// // is not 0.
197/// };
198/// @endcode
199/// Next, we implement the `MessageProcessor` constructor:
200/// @code
201/// MessageProcessor::MessageProcessor(bslma::Allocator *basicAllocator)
202/// : d_msgQueue(basicAllocator)
203/// {
204/// }
205/// @endcode
206/// Notice that we pass to the contained `d_msgQueue` object the
207/// `bslma::Allocator*` supplied to the `MessageProcessor` at construction.
208///
209/// Now, we implement the `receiveMessage` method, which pushes the given
210/// message onto the queue object:
211/// @code
212/// void MessageProcessor::receiveMessage(const Message &message)
213/// {
214/// // ... (some synchronization)
215///
216/// d_msgQueue.push(message);
217///
218/// // ...
219/// }
220/// @endcode
221/// Finally, we implement the `processMessages` method, which pops all messages
222/// off the queue object:
223/// @code
224/// void MessageProcessor::processMessages(int verbose)
225/// {
226/// // ... (some synchronization)
227///
228/// while (!d_msgQueue.empty()) {
229/// const Message& message = d_msgQueue.front();
230/// if (verbose) {
231/// printf("Msg %d: %s\n", message.d_msgId, message.d_msg_p);
232/// }
233/// d_msgQueue.pop();
234/// }
235///
236/// // ...
237/// }
238/// @endcode
239/// Note that the sequence of messages popped from the queue will be in exactly
240/// the same order in which they were pushed, due to the first-in-first-out
241/// property of the queue.
242/// @}
243/** @} */
244/** @} */
245
246/** @addtogroup bsl
247 * @{
248 */
249/** @addtogroup bslstl
250 * @{
251 */
252/** @addtogroup bslstl_queue
253 * @{
254 */
255
256#include <bslscm_version.h>
257
258#include <bslstl_compare.h>
259#include <bslstl_deque.h>
260
261#include <bslalg_swaputil.h>
262
263#include <bslma_isstdallocator.h>
265
266#include <bslmf_assert.h>
267#include <bslmf_enableif.h>
268#include <bslmf_isconvertible.h>
269#include <bslmf_issame.h>
270#include <bslmf_movableref.h>
272#include <bslmf_usesallocator.h>
273#include <bslmf_util.h> // 'forward(V)'
274
276#include <bsls_libraryfeatures.h>
277#include <bsls_keyword.h>
278#include <bsls_platform.h>
279#include <bsls_util.h> // 'forward<T>(V)'
280
281#if BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
282// Include version that can be compiled with C++03
283// Generated on Thu Oct 21 10:11:37 2021
284// Command line: sim_cpp11_features.pl bslstl_queue.h
285# define COMPILING_BSLSTL_QUEUE_H
286# include <bslstl_queue_cpp03.h>
287# undef COMPILING_BSLSTL_QUEUE_H
288#else
289
290namespace bsl {
291
292 // ===========
293 // class queue
294 // ===========
295
296/// This class is a value-semantic class template, having a container of the
297/// parameterized `CONTAINER` type that holds elements of the parameterized
298/// `VALUE` type, to provide a first-in-first-out queue data structure. The
299/// container object held by a `queue` class object is referenced as `c` in
300/// the following function-level documentation.
301///
302/// See @ref bslstl_queue
303template <class VALUE, class CONTAINER = deque<VALUE> >
304class queue {
305
306#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY
307 // STATIC CHECK: Type mismatch is UB per C++17
309#endif
310
311 // FRIENDS
312 template <class VALUE2, class CONTAINER2>
315
316 template <class VALUE2, class CONTAINER2>
319
320 template <class VALUE2, class CONTAINER2>
323
324 template <class VALUE2, class CONTAINER2>
327
328 template <class VALUE2, class CONTAINER2>
331
332 template <class VALUE2, class CONTAINER2>
335
336#if defined BSLS_COMPILERFEATURES_SUPPORT_THREE_WAY_COMPARISON \
337 && defined BSLS_LIBRARYFEATURES_HAS_CPP20_CONCEPTS
338 template <class VALUE2, three_way_comparable CONTAINER2>
339 friend compare_three_way_result_t<CONTAINER2>
340 operator<=>(const queue<VALUE2, CONTAINER2>&,
342#endif
343
344 // PRIVATE TYPES
345
346 /// This `typedef` is a convenient alias for the utility associated with
347 /// movable references.
348 typedef BloombergLP::bslmf::MovableRefUtil MoveUtil;
349
350 public:
351 // PUBLIC TYPES
352 typedef typename CONTAINER::value_type value_type;
353 typedef typename CONTAINER::reference reference;
354 typedef typename CONTAINER::const_reference const_reference;
355 typedef typename CONTAINER::size_type size_type;
356 typedef CONTAINER container_type;
357
358 protected:
359 // PROTECTED DATA
360 CONTAINER c; // Contains the elements of this queue.
361 // 'protected' and named ('c') per the C++11 standard.
362
363 public:
364 // TRAITS
366 queue,
367 BloombergLP::bslma::UsesBslmaAllocator,
368 BloombergLP::bslma::UsesBslmaAllocator<container_type>::value);
369
370 // CREATORS
371
372 /// Create an empty queue having a container of the parameterized
373 /// `CONTAINER` type.
374 explicit queue();
375
376 /// Create a queue having the value of the specified `original`.
377 queue(const queue& original);
378
379 /// Create a queue having the value of the specified `original`. The
380 /// allocator associated with `original` (if any) is propagated for use
381 /// in the new queue. `original` is left in valid but unspecified
382 /// state.
383 queue(BloombergLP::bslmf::MovableRef<queue> container);
384
385 /// Create a queue having the specified `container` that holds elements
386 /// of the parameterized `VALUE` type.
387 explicit queue(const CONTAINER& container);
388
389 /// Create a queue having the same sequence of values as the specified
390 /// `container`. The allocator associated with `container` (if any) is
391 /// propagated for use in the new queue. `container` is left in valid
392 /// but unspecified state.
393 explicit queue(BloombergLP::bslmf::MovableRef<CONTAINER> container);
394
395 /// Create an empty queue. This queue object uses the specified
396 /// `basicAllocator` to supply memory. Note that the `ALLOCATOR`
397 /// parameter type has to be convertible to the allocator of the
398 /// `CONTAINER` parameter type, `CONTAINER::allocator_type`; otherwise,
399 /// this constructor is disabled.
400 template <class ALLOCATOR>
401 explicit
402 queue(const ALLOCATOR& basicAllocator,
404 ALLOCATOR>::type * = 0);
405
406 /// Create a queue having the same sequence of values as the specified
407 /// `container`. The queue object uses the specified `basicAllocator`
408 /// to obtain memory. Note that the `ALLOCATOR` parameter type has to
409 /// be convertible to the allocator of the `CONTAINER` parameter type,
410 /// `CONTAINER::allocator_type`; otherwise, this constructor is
411 /// disabled.
412 template <class ALLOCATOR>
413 queue(const CONTAINER& container,
414 const ALLOCATOR& basicAllocator,
416 ALLOCATOR>::type * = 0);
417
418 /// Create a queue having the value of the specified `original` that
419 /// will use the specified `basicAllocator` to supply memory. Note that
420 /// the `ALLOCATOR` parameter type has to be convertible to the
421 /// allocator of the `CONTAINER` parameter type,
422 /// `CONTAINER::allocator_type`. Otherwise this constructor is
423 /// disabled.
424 template <class ALLOCATOR>
425 queue(const queue& original,
426 const ALLOCATOR& basicAllocator,
428 ALLOCATOR>::type * = 0);
429
430 /// Create a queue whose underlying container has the value of the
431 /// specified `container` (on entry) and uses `basicAllocator` to supply
432 /// memory. The allocated-extended move constructor of `CONTAINER` is
433 /// used to create the new queue. `container` is left in a valid but
434 /// unspecified state. Note that a `bslma::Allocator *` can be supplied
435 /// for `basicAllocator` if the (template parameter) `ALLOCATOR` is
436 /// `bsl::allocator` (the default). Also note that this method assumes
437 /// that `CONTAINER` has a move constructor. Also note that if
438 /// `CONTAINER::allocator_type` does not exist, this constructor is
439 /// disabled.
440 template <class ALLOCATOR>
441 queue(BloombergLP::bslmf::MovableRef<CONTAINER> container,
442 const ALLOCATOR& basicAllocator,
444 ALLOCATOR>::type * = 0);
445
446 /// Create a queue having the value of the specified `original` (on
447 /// entry), that uses `basicAllocator` to supply memory. The
448 /// allocator-extended move constructor of `CONTAINER` is used to create
449 /// the new queue. `original` is left in a valid but unspecified state.
450 /// Note that a `bslma::Allocator *` can be supplied for
451 /// `basicAllocator` if the (template parameter) `ALLOCATOR` is
452 /// `bsl::allocator` (the default). Also note that this method assumes
453 /// that `CONTAINER` has a move constructor. Also note that if
454 /// `CONTAINER::allocator_type` does not exist, this constructor is
455 /// disabled.
456 template <class ALLOCATOR>
457 queue(BloombergLP::bslmf::MovableRef<queue> original,
458 const ALLOCATOR& basicAllocator,
460 ALLOCATOR>::type * = 0);
461
462 // MANIPULATORS
463
464 /// Assign to this queue the value of the specified `rhs`, and return a
465 /// reference providing modifiable access to this queue.
466 queue& operator=(const queue& rhs);
467
468 /// Assign to this queue the value as the specified `rhs` and return a
469 /// reference providing modifiable access to this queue. The
470 /// move-assignment operator of `CONTAINER` is used to set the value of
471 /// this queue. `rhs` is left in a valid but unspecified state, and if
472 /// an exception is thrown, `*this` is left in a valid but unspecified
473 /// state.
474 queue& operator=(BloombergLP::bslmf::MovableRef<queue> rhs);
475
476#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
477 /// Push onto this queue a newly created `value_type` object constructed
478 /// by forwarding `get_allocator()` (if required) and the specified
479 /// (variable number of) `args` to the corresponding constructor of
480 /// `value_type`. Return a reference providing modifiable access to the
481 /// inserted element.
482 template <class... Args>
483 reference emplace(Args&&... args);
484
485#endif
486
487 /// Push onto the back of this queue a `value_type` object having the
488 /// specified `value`.
489 void push(const value_type& value);
490
491 /// Push onto the back of this queue a `value_type` object having the
492 /// value of the specified `value` (on entry) by moving the
493 /// contents of `value` to the new object on this queue. `value` is
494 /// left in a valid but unspecified state.
495 void push(BloombergLP::bslmf::MovableRef<value_type> value);
496
497 void pop();
498 /// Remove the front (the earliest pushed) element from this `queue`
499 /// object.
500
502 bsl::is_nothrow_swappable<CONTAINER>::value);
503 // Efficiently exchange the value of this object with the value of the
504 // specified 'other' object. In effect, performs
505 // 'using bsl::swap; swap(c, other.c);'.
506
507 /// Return a reference providing modifiable access to the front (the
508 /// earliest pushed) element from this `queue` object.
510
511 /// Return a reference providing modifiable access to the back (the
512 /// latest pushed) element of this `queue` object.
514
515 // ACCESSORS
516
517 /// Return `true` if this `queue` object contains no elements, and
518 /// `false` otherwise. In effect, performs `return c.empty();`.
519 bool empty() const;
520
521 /// Return the number of elements in this queue. In effect, performs
522 /// `return c.size();`.
524
525 /// Return the immutable front (the earliest pushed) element from this
526 /// `queue` object. In effect, performs `c.front()`.
528
529 /// Return the immutable back (the latest pushed) element from this
530 /// `queue` object. In effect, performs `c.back()`.
532};
533
534#ifdef BSLS_COMPILERFEATURES_SUPPORT_CTAD
535// CLASS TEMPLATE DEDUCTION GUIDES
536
537/// Deduce the template parameters `VALUE` and `CONTAINER` from the
538/// parameters supplied to the constructor of `queue`. This deduction guide
539/// does not participate if the parameter meets the requirements for a
540/// standard allocator.
541template<class CONTAINER,
542 class = bsl::enable_if_t<!bsl::IsStdAllocator_v<CONTAINER>>
543 >
545
546/// Deduce the template parameters `VALUE` and `CONTAINER` from the
547/// parameters supplied to the constructor of `queue`. This deduction
548/// guide does not participate unless the supplied allocator is convertible
549/// to the underlying container's `allocator_type`.
550template<
551 class CONTAINER,
552 class ALLOCATOR,
553 class = bsl::enable_if_t<bsl::uses_allocator_v<CONTAINER, ALLOCATOR>>
554 >
556#endif
557
558// FREE OPERATORS
559
560/// Return `true` if the specified `lhs` and `rhs` objects have the same
561/// value, and `false` otherwise. Two `queue` objects `lhs` and `rhs` have
562/// the same value if they have the same number of elements, and each
563/// element in the ordered sequence of elements of `lhs` has the same value
564/// as the corresponding element in the ordered sequence of elements of
565/// `rhs`. This method requires that the (template parameter) type `VALUE`
566/// be `equality-comparable` (see {Requirements on `VALUE`}).
567template <class VALUE, class CONTAINER>
568bool operator==(const queue<VALUE, CONTAINER>& lhs,
569 const queue<VALUE, CONTAINER>& rhs);
570
571/// Return `true` if the specified `lhs` and `rhs` objects do not have the
572/// same value, and `false` otherwise. Two `queue` objects `lhs` and `rhs`
573/// do not have the same value if they do not have the same number of
574/// elements, or some element in the ordered sequence of elements of `lhs`
575/// does not have the same value as the corresponding element in the ordered
576/// sequence of elements of `rhs`. This method requires that the (template
577/// parameter) type `VALUE` be `equality-comparable` (see {Requirements on
578/// `VALUE`}).
579template <class VALUE, class CONTAINER>
580bool operator!=(const queue<VALUE, CONTAINER>& lhs,
581 const queue<VALUE, CONTAINER>& rhs);
582
583/// Return `true` if the value of the specified `lhs` queue is
584/// lexicographically less than that of the specified `rhs` queue, and
585/// `false` otherwise. Given iterators `i` and `j` over the respective
586/// sequences `[lhs.begin() .. lhs.end())` and `[rhs.begin() .. rhs.end())`,
587/// the value of queue `lhs` is lexicographically less than that of queue
588/// `rhs` if `true == *i < *j` for the first pair of corresponding iterator
589/// positions where `*i < *j` and `*j < *i` are not both `false`. If no
590/// such corresponding iterator position exists, the value of `lhs` is
591/// lexicographically less than that of `rhs` if `lhs.size() < rhs.size()`.
592/// This method requires that `operator<`, inducing a total order, be
593/// defined for `value_type`.
594template <class VALUE, class CONTAINER>
595bool operator< (const queue<VALUE, CONTAINER>& lhs,
596 const queue<VALUE, CONTAINER>& rhs);
597
598/// Return `true` if the value of the specified `lhs` queue is
599/// lexicographically greater than that of the specified `rhs` queue, and
600/// `false` otherwise. The value of queue `lhs` is lexicographically
601/// greater than that of queue `rhs` if `rhs` is lexicographically less than
602/// `lhs` (see `operator<`). This method requires that `operator<`,
603/// inducing a total order, be defined for `value_type`. Note that this
604/// operator returns `rhs < lhs`.
605template <class VALUE, class CONTAINER>
606bool operator> (const queue<VALUE, CONTAINER>& lhs,
607 const queue<VALUE, CONTAINER>& rhs);
608
609/// Return `true` if the value of the specified `lhs` queue is
610/// lexicographically less than or equal to that of the specified `rhs`
611/// queue, and `false` otherwise. The value of queue `lhs` is
612/// lexicographically less than or equal to that of queue `rhs` if `rhs` is
613/// not lexicographically less than `lhs` (see `operator<`). This method
614/// requires that `operator<`, inducing a total order, be defined for
615/// `value_type`. Note that this operator returns `!(rhs < lhs)`.
616template <class VALUE, class CONTAINER>
617bool operator<=(const queue<VALUE, CONTAINER>& lhs,
618 const queue<VALUE, CONTAINER>& rhs);
619
620/// Return `true` if the value of the specified `lhs` queue is
621/// lexicographically greater than or equal to that of the specified `rhs`
622/// queue, and `false` otherwise. The value of queue `lhs` is
623/// lexicographically greater than or equal to that of queue `rhs` if `lhs`
624/// is not lexicographically less than `rhs` (see `operator<`). This method
625/// requires that `operator<`, inducing a total order, be defined for
626/// `value_type`. Note that this operator returns `!(lhs < rhs)`.
627template <class VALUE, class CONTAINER>
628bool operator>=(const queue<VALUE, CONTAINER>& lhs,
629 const queue<VALUE, CONTAINER>& rhs);
630
631// FREE FUNCTIONS
632
633/// Swap the value of the specified `lhs` queue with the value of the
634/// specified `rhs` queue.
635template <class VALUE, class CONTAINER>
636void swap(queue<VALUE, CONTAINER>& lhs,
639
640// ============================================================================
641// TEMPLATE AND INLINE FUNCTION DEFINITIONS
642// ============================================================================
643
644 // -----------
645 // class queue
646 // -----------
647
648// CREATORS
649template <class VALUE, class CONTAINER>
650inline
654
655template <class VALUE, class CONTAINER>
656inline
658: c(original.c)
659{
660}
661
662template <class VALUE, class CONTAINER>
663inline
664queue<VALUE, CONTAINER>::queue(BloombergLP::bslmf::MovableRef<queue> original)
665: c(MoveUtil::move(MoveUtil::access(original).c))
666{
667}
668
669template <class VALUE, class CONTAINER>
670inline
671queue<VALUE, CONTAINER>::queue(const CONTAINER& container)
672: c(container)
673{
674}
675
676template <class VALUE, class CONTAINER>
677template <class ALLOCATOR>
678inline
680 const ALLOCATOR& basicAllocator,
682 ALLOCATOR>::type *)
683: c(basicAllocator)
684{
685}
686
687template <class VALUE, class CONTAINER>
688template <class ALLOCATOR>
689inline
691 const CONTAINER& container,
692 const ALLOCATOR& basicAllocator,
694 ALLOCATOR>::type *)
695: c(container, basicAllocator)
696{
697}
698
699template <class VALUE, class CONTAINER>
700template <class ALLOCATOR>
701inline
703 const queue& queue,
704 const ALLOCATOR& basicAllocator,
706 ALLOCATOR>::type *)
707: c(queue.c, basicAllocator)
708{
709}
710
711template <class VALUE, class CONTAINER>
712inline
713queue<VALUE, CONTAINER>::queue(BloombergLP::bslmf::MovableRef<CONTAINER>
714 container)
715: c(MoveUtil::move(container))
716{
717}
718
719template <class VALUE, class CONTAINER>
720template <class ALLOCATOR>
721inline
723 BloombergLP::bslmf::MovableRef<CONTAINER> container,
724 const ALLOCATOR& basicAllocator,
726 ALLOCATOR>::type *)
727: c(MoveUtil::move(container), basicAllocator)
728{
729}
730
731template <class VALUE, class CONTAINER>
732template <class ALLOCATOR>
733inline
735 BloombergLP::bslmf::MovableRef<queue> original,
736 const ALLOCATOR& basicAllocator,
738 ALLOCATOR>::type *)
739: c(MoveUtil::move(MoveUtil::access(original).c), basicAllocator)
740{
741}
742
743// MANIPULATORS
744template <class VALUE, class CONTAINER>
745inline
747{
748 c = rhs.c;
749 return *this;
750}
751
752template <class VALUE, class CONTAINER>
753inline
755 BloombergLP::bslmf::MovableRef<queue> rhs)
756{
757 c = MoveUtil::move(MoveUtil::access(rhs).c);
758 return *this;
759}
760
761#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
762template <class VALUE, class CONTAINER>
763template <class... Args>
764inline
767{
768 c.emplace_back(BSLS_COMPILERFEATURES_FORWARD(Args,args)...);
769 return back();
770}
771#endif
772
773template <class VALUE, class CONTAINER>
774inline
776{
777 c.push_back(value);
778}
779
780template <class VALUE, class CONTAINER>
781inline
782void queue<VALUE, CONTAINER>::push(BloombergLP::bslmf::MovableRef<value_type>
783 value)
784{
785 c.push_back(MoveUtil::move(value));
786}
787
788template <class VALUE, class CONTAINER>
789inline
791{
792 c.pop_front();
793}
794
795template <class VALUE, class CONTAINER>
796inline
799 bsl::is_nothrow_swappable<CONTAINER>::value)
800{
801 BloombergLP::bslalg::SwapUtil::swap(&c, &other.c);
802}
803
804// ACCESSORS
805template <class VALUE, class CONTAINER>
806inline
808{
809 return c.empty();
810}
811
812template <class VALUE, class CONTAINER>
813inline
816{
817 return c.size();
818}
819
820template <class VALUE, class CONTAINER>
821inline
824{
825 return c.front();
826}
827
828template <class VALUE, class CONTAINER>
829inline
832{
833 return c.front();
834}
835
836template <class VALUE, class CONTAINER>
837inline
840{
841 return c.back();
842}
843
844template <class VALUE, class CONTAINER>
845inline
848{
849 return c.back();
850}
851
852// FREE OPERATORS
853template <class VALUE, class CONTAINER>
854inline
855bool operator==(const queue<VALUE, CONTAINER>& lhs,
856 const queue<VALUE, CONTAINER>& rhs)
857{
858 return lhs.c == rhs.c;
859}
860
861template <class VALUE, class CONTAINER>
862inline
863bool operator!=(const queue<VALUE, CONTAINER>& lhs,
864 const queue<VALUE, CONTAINER>& rhs)
865{
866 return lhs.c != rhs.c;
867}
868
869template <class VALUE, class CONTAINER>
870inline
871bool operator< (const queue<VALUE, CONTAINER>& lhs,
872 const queue<VALUE, CONTAINER>& rhs)
873{
874 return lhs.c < rhs.c;
875}
876
877template <class VALUE, class CONTAINER>
878inline
879bool operator> (const queue<VALUE, CONTAINER>& lhs,
880 const queue<VALUE, CONTAINER>& rhs)
881{
882 return lhs.c > rhs.c;
883}
884
885template <class VALUE, class CONTAINER>
886inline
887bool operator<=(const queue<VALUE, CONTAINER>& lhs,
888 const queue<VALUE, CONTAINER>& rhs)
889{
890 return lhs.c <= rhs.c;
891}
892
893template <class VALUE, class CONTAINER>
894inline
895bool operator>=(const queue<VALUE, CONTAINER>& lhs,
896 const queue<VALUE, CONTAINER>& rhs)
897{
898 return lhs.c >= rhs.c;
899}
900
901#if defined BSLS_COMPILERFEATURES_SUPPORT_THREE_WAY_COMPARISON \
902 && defined BSLS_LIBRARYFEATURES_HAS_CPP20_CONCEPTS
903template <class VALUE, three_way_comparable CONTAINER>
904inline compare_three_way_result_t<CONTAINER>
905operator<=>(const queue<VALUE, CONTAINER>& lhs,
906 const queue<VALUE, CONTAINER>& rhs)
907{
908 return lhs.c <=> rhs.c;
909}
910#endif
911
912// FREE FUNCTIONS
913template <class VALUE, class CONTAINER>
914inline
918{
919 lhs.swap(rhs);
920}
921
922} // close namespace bsl
923
924#endif // End C++11 code
925
926#endif
927
928// ----------------------------------------------------------------------------
929// Copyright 2016 Bloomberg Finance L.P.
930//
931// Licensed under the Apache License, Version 2.0 (the "License");
932// you may not use this file except in compliance with the License.
933// You may obtain a copy of the License at
934//
935// http://www.apache.org/licenses/LICENSE-2.0
936//
937// Unless required by applicable law or agreed to in writing, software
938// distributed under the License is distributed on an "AS IS" BASIS,
939// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
940// See the License for the specific language governing permissions and
941// limitations under the License.
942// ----------------------------- END-OF-FILE ----------------------------------
943
944/** @} */
945/** @} */
946/** @} */
Definition bslstl_queue.h:304
void push(BloombergLP::bslmf::MovableRef< value_type > value)
Definition bslstl_queue.h:782
queue(const queue &original)
Create a queue having the value of the specified original.
Definition bslstl_queue.h:657
friend bool operator==(const queue< VALUE2, CONTAINER2 > &, const queue< VALUE2, CONTAINER2 > &)
const_reference back() const
Definition bslstl_queue.h:847
void pop()
Definition bslstl_queue.h:790
CONTAINER::const_reference const_reference
Definition bslstl_queue.h:354
size_type size() const
Definition bslstl_queue.h:815
friend bool operator<=(const queue< VALUE2, CONTAINER2 > &, const queue< VALUE2, CONTAINER2 > &)
queue()
Definition bslstl_queue.h:651
bool empty() const
Definition bslstl_queue.h:807
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:352
queue(BloombergLP::bslmf::MovableRef< queue > container)
Definition bslstl_queue.h:664
const_reference front() const
void push(const value_type &value)
Definition bslstl_queue.h:775
queue(BloombergLP::bslmf::MovableRef< CONTAINER > container)
Definition bslstl_queue.h:713
queue(const ALLOCATOR &basicAllocator, typename enable_if< bsl::uses_allocator< CONTAINER, ALLOCATOR >::value, ALLOCATOR >::type *=0)
Definition bslstl_queue.h:679
queue(const CONTAINER &container)
Definition bslstl_queue.h:671
CONTAINER::size_type size_type
Definition bslstl_queue.h:355
queue & operator=(BloombergLP::bslmf::MovableRef< queue > rhs)
Definition bslstl_queue.h:754
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:722
queue & operator=(const queue &rhs)
Definition bslstl_queue.h:746
void swap(queue &other) BSLS_KEYWORD_NOEXCEPT_SPECIFICATION(bsl reference front()
Definition bslstl_queue.h:509
reference back()
Definition bslstl_queue.h:839
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:734
queue(const queue &original, const ALLOCATOR &basicAllocator, typename enable_if< bsl::uses_allocator< CONTAINER, ALLOCATOR >::value, ALLOCATOR >::type *=0)
Definition bslstl_queue.h:702
CONTAINER container_type
Definition bslstl_queue.h:356
queue(const CONTAINER &container, const ALLOCATOR &basicAllocator, typename enable_if< bsl::uses_allocator< CONTAINER, ALLOCATOR >::value, ALLOCATOR >::type *=0)
Definition bslstl_queue.h:690
CONTAINER::reference reference
Definition bslstl_queue.h:353
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:766
CONTAINER c
Definition bslstl_queue.h:360
#define BSLMF_ASSERT(expr)
Definition bslmf_assert.h:229
#define BSLS_COMPILERFEATURES_FORWARD(T, V)
Definition bsls_compilerfeatures.h:2018
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_KEYWORD_NOEXCEPT_SPECIFICATION(...)
Definition bsls_keyword.h:634
Definition bdlb_printmethods.h:283
Definition bslmf_enableif.h:525
Definition bslmf_issame.h:146
Definition bslmf_usesallocator.h:165