Quick Links: |
Provide container adapter class template queue
.
More...
Classes | |
class | bsl::queue< VALUE, CONTAINER > |
Typedefs | |
typedef CONTAINER::value_type | bsl::queue::value_type |
typedef CONTAINER::reference | bsl::queue::reference |
typedef CONTAINER::const_reference | bsl::queue::const_reference |
typedef CONTAINER::size_type | bsl::queue::size_type |
typedef CONTAINER | bsl::queue::container_type |
Functions | |
bsl::queue::BSLMF_NESTED_TRAIT_DECLARATION_IF (queue, BloombergLP::bslma::UsesBslmaAllocator, BloombergLP::bslma::UsesBslmaAllocator< container_type >::value) | |
bsl::queue::queue () | |
bsl::queue::queue (const queue &original) | |
bsl::queue::queue (BloombergLP::bslmf::MovableRef< queue > container) | |
bsl::queue::queue (const CONTAINER &container) | |
bsl::queue::queue (BloombergLP::bslmf::MovableRef< CONTAINER > container) | |
template<class ALLOCATOR > | |
bsl::queue::queue (const ALLOCATOR &basicAllocator, typename enable_if< bsl::uses_allocator< CONTAINER, ALLOCATOR >::value, ALLOCATOR >::type *=0) | |
template<class ALLOCATOR > | |
bsl::queue::queue (const CONTAINER &container, const ALLOCATOR &basicAllocator, typename enable_if< bsl::uses_allocator< CONTAINER, ALLOCATOR >::value, ALLOCATOR >::type *=0) | |
template<class ALLOCATOR > | |
bsl::queue::queue (const queue &original, const ALLOCATOR &basicAllocator, typename enable_if< bsl::uses_allocator< CONTAINER, ALLOCATOR >::value, ALLOCATOR >::type *=0) | |
template<class ALLOCATOR > | |
bsl::queue::queue (BloombergLP::bslmf::MovableRef< CONTAINER > container, const ALLOCATOR &basicAllocator, typename enable_if< bsl::uses_allocator< CONTAINER, ALLOCATOR >::value, ALLOCATOR >::type *=0) | |
template<class ALLOCATOR > | |
bsl::queue::queue (BloombergLP::bslmf::MovableRef< queue > original, const ALLOCATOR &basicAllocator, typename enable_if< bsl::uses_allocator< CONTAINER, ALLOCATOR >::value, ALLOCATOR >::type *=0) | |
queue & | bsl::queue::operator= (const queue &rhs) |
queue & | bsl::queue::operator= (BloombergLP::bslmf::MovableRef< queue > rhs) |
template<class... Args> | |
reference | bsl::queue::emplace (Args &&...args) |
void | bsl::queue::push (const value_type &value) |
void | bsl::queue::push (BloombergLP::bslmf::MovableRef< value_type > value) |
void | bsl::queue::pop () |
reference | bsl::queue::back () |
bool | bsl::queue::empty () const |
size_type | bsl::queue::size () const |
const_reference | bsl::queue::front () const |
const_reference | bsl::queue::back () const |
template<class VALUE , class CONTAINER > | |
bool | bsl::operator== (const queue< VALUE, CONTAINER > &lhs, const queue< VALUE, CONTAINER > &rhs) |
template<class VALUE , class CONTAINER > | |
bool | bsl::operator!= (const queue< VALUE, CONTAINER > &lhs, const queue< VALUE, CONTAINER > &rhs) |
template<class VALUE , class CONTAINER > | |
bool | bsl::operator< (const queue< VALUE, CONTAINER > &lhs, const queue< VALUE, CONTAINER > &rhs) |
template<class VALUE , class CONTAINER > | |
bool | bsl::operator> (const queue< VALUE, CONTAINER > &lhs, const queue< VALUE, CONTAINER > &rhs) |
template<class VALUE , class CONTAINER > | |
bool | bsl::operator<= (const queue< VALUE, CONTAINER > &lhs, const queue< VALUE, CONTAINER > &rhs) |
template<class VALUE , class CONTAINER > | |
bool | bsl::operator>= (const queue< VALUE, CONTAINER > &lhs, const queue< VALUE, CONTAINER > &rhs) |
template<class VALUE , class CONTAINER > | |
void | bsl::swap (queue< VALUE, CONTAINER > &lhs, queue< VALUE, CONTAINER > &rhs) BSLS_KEYWORD_NOEXCEPT_SPECIFICATION(false) |
Variables | |
CONTAINER | bsl::queue::c |
void swap(queue &other) BSLS_KEYWORD_NOEXCEPT_SPECIFICATION(bsl reference | bsl::queue::front () |
Friends | |
template<class VALUE2 , class CONTAINER2 > | |
bool | bsl::queue::operator== (const queue< VALUE2, CONTAINER2 > &, const queue< VALUE2, CONTAINER2 > &) |
template<class VALUE2 , class CONTAINER2 > | |
bool | bsl::queue::operator!= (const queue< VALUE2, CONTAINER2 > &, const queue< VALUE2, CONTAINER2 > &) |
template<class VALUE2 , class CONTAINER2 > | |
bool | bsl::queue::operator< (const queue< VALUE2, CONTAINER2 > &, const queue< VALUE2, CONTAINER2 > &) |
template<class VALUE2 , class CONTAINER2 > | |
bool | bsl::queue::operator> (const queue< VALUE2, CONTAINER2 > &, const queue< VALUE2, CONTAINER2 > &) |
template<class VALUE2 , class CONTAINER2 > | |
bool | bsl::queue::operator<= (const queue< VALUE2, CONTAINER2 > &, const queue< VALUE2, CONTAINER2 > &) |
template<class VALUE2 , class CONTAINER2 > | |
bool | bsl::queue::operator>= (const queue< VALUE2, CONTAINER2 > &, const queue< VALUE2, CONTAINER2 > &) |
queue
. bsl::queue | class template of a first-in-first-out data structure |
bsl::queue
, holding a container (of a parameterized type CONTAINER
containing elements of another parameterized type VALUE
), and adapting it to provide a first-in-first-out queue data structure. queue
is an allocator-aware, value-semantic type whose salient attributes are its size (number of elements held) and the sequence of values (of held elements) in the order that they were pushed into the queue
. If queue
is instantiated with a parameterized type VALUE
that is not itself value-semantic, then it will not retain all of its value-semantic qualities. queue
implemented here adheres to the C++11 standard when compiled with a C++11 compiler, and makes the best approximation when compiled with a C++03 compiler. In particular, for C++03 we emulate move semantics, but limit forwarding (in emplace
) to const
lvalues, and make no effort to emulate noexcept
or initializer-lists. bsl::queue
adapter can accept for its (optional) CONTAINER
template parameter bsl::deque
(the default), bsl::vector
, or other container classes that support the following types and methods. value_type
reference
const_reference
size_type
allocator_type
(if any queue
constructor taking an allocator is used) void push_back(const value_type&)
(and variant taking rvalue reference) void pop_front()
reference front()
reference back()
bool empty() const
size_type size() const
const_reference front() const
const_reference back() const
emplace_back
==
, !=
, <
, >
, <=
, >=
operators swap
function (found via ADL with std::swap
in the lookup set) CONTAINER
template parameter is omitted the VALUE
template parameter specifies the value_type
of bsl::vector
, the default container type. The VALUE
template has no other role. CONTAINER::value_type
determines the contained value type and VALUE
is simply ignored. The resulting code may work with instances of VALUE
(e.g., VALUE
is convertible to CONTAINER::value_type
) or not (compiler errors). ALLOCATOR
template parameter in some of queue
constructors determines how the held container (of parameterized CONTAINER
) will allocate memory. A queue
supports allocators meeting the requirements of the C++11 standard [allocator.requirements] as long as the held container does. In addition it supports scoped-allocators derived from the bslma::Allocator
memory allocation protocol. Clients intending to use bslma
style allocators should use bsl::allocator
as the ALLOCATOR
template parameter, providing a C++11 standard-compatible adapter for a bslma::Allocator
object. bsl::queue
container adapter to implement a message processor in a server program that receives and displays messages from clients. bsl::queue
in the message processor to buffer received, but as yet unprinted, messages. The message processor pushes newly received messages onto the queue in the receiving thread, and pops them off the queue in the processing thread. Message
type: struct Message { int d_msgId; // message identifier given by client const char *d_msg_p; // message content (C-style string, not owned) };
MessageProcessor
, which provides methods to receive and process messages: class MessageProcessor { // This class receives and processes messages from clients.
bsl::queue<Message>
type, which is an instantiation of bsl::queue
that uses Message
for its VALUE
(template parameter) type and (by default) bsl::deque<Message>
for its CONTAINER
(template parameter) type: // DATA bsl::queue<Message> d_msgQueue; // queue holding received but // unprocessed messages // ... public: // CREATORS explicit MessageProcessor(bslma::Allocator *basicAllocator = 0); // Create a message processor object. Optionally specify a // 'basicAllocator' used to supply memory. If 'basicAllocator' is // 0, the currently installed default allocator is used. // MANIPULATORS void receiveMessage(const Message &message); // Enqueue the specified 'message' onto this message processor. void processMessages(int verbose); // Dequeue all messages currently contained by this processor, // and print them to the console if the specified 'verbose' flag // is not 0. };
MessageProcessor
constructor: MessageProcessor::MessageProcessor(bslma::Allocator *basicAllocator) : d_msgQueue(basicAllocator) { }
d_msgQueue
object the bslma::Allocator*
supplied to the MessageProcessor
at construction. receiveMessage
method, which pushes the given message onto the queue object: void MessageProcessor::receiveMessage(const Message &message) { // ... (some synchronization) d_msgQueue.push(message); // ... }
processMessages
method, which pops all messages off the queue object: void MessageProcessor::processMessages(int verbose) { // ... (some synchronization) while (!d_msgQueue.empty()) { const Message& message = d_msgQueue.front(); if (verbose) { printf("Msg %d: %s\n", message.d_msgId, message.d_msg_p); } d_msgQueue.pop(); } // ... }
typedef CONTAINER::value_type bsl::queue< VALUE, CONTAINER >::value_type [inherited] |
typedef CONTAINER::reference bsl::queue< VALUE, CONTAINER >::reference [inherited] |
typedef CONTAINER::const_reference bsl::queue< VALUE, CONTAINER >::const_reference [inherited] |
typedef CONTAINER::size_type bsl::queue< VALUE, CONTAINER >::size_type [inherited] |
typedef CONTAINER bsl::queue< VALUE, CONTAINER >::container_type [inherited] |
bsl::queue< VALUE, CONTAINER >::BSLMF_NESTED_TRAIT_DECLARATION_IF | ( | queue< VALUE, CONTAINER > | , | |
BloombergLP::bslma::UsesBslmaAllocator | , | |||
BloombergLP::bslma::UsesBslmaAllocator< container_type >::value | ||||
) | [inherited] |
bsl::queue< VALUE, CONTAINER >::queue | ( | ) | [explicit, inherited] |
Create an empty queue having a container of the parameterized CONTAINER
type.
bsl::queue< VALUE, CONTAINER >::queue | ( | const queue< VALUE, CONTAINER > & | original | ) | [inherited] |
Create a queue having the value of the specified original
.
bsl::queue< VALUE, CONTAINER >::queue | ( | BloombergLP::bslmf::MovableRef< queue< VALUE, CONTAINER > > | container | ) | [inherited] |
Create a queue having the value of the specified original
. The allocator associated with original
(if any) is propagated for use in the new queue. original
is left in valid but unspecified state.
bsl::queue< VALUE, CONTAINER >::queue | ( | const CONTAINER & | container | ) | [explicit, inherited] |
Create a queue having the specified container
that holds elements of the parameterized VALUE
type.
bsl::queue< VALUE, CONTAINER >::queue | ( | BloombergLP::bslmf::MovableRef< CONTAINER > | container | ) | [explicit, inherited] |
Create a queue having the same sequence of values as the specified container
. The allocator associated with container
(if any) is propagated for use in the new queue. container
is left in valid but unspecified state.
bsl::queue< VALUE, CONTAINER >::queue | ( | const ALLOCATOR & | basicAllocator, | |
typename enable_if< bsl::uses_allocator< CONTAINER, ALLOCATOR >::value, ALLOCATOR >::type * | = 0 | |||
) | [explicit, inherited] |
Create an empty queue. This queue object uses the specified basicAllocator
to supply memory. Note that the ALLOCATOR
parameter type has to be convertible to the allocator of the CONTAINER
parameter type, CONTAINER::allocator_type
; otherwise, this constructor is disabled.
bsl::queue< VALUE, CONTAINER >::queue | ( | const CONTAINER & | container, | |
const ALLOCATOR & | basicAllocator, | |||
typename enable_if< bsl::uses_allocator< CONTAINER, ALLOCATOR >::value, ALLOCATOR >::type * | = 0 | |||
) | [inherited] |
Create a queue having the same sequence of values as the specified container
. The queue object uses the specified basicAllocator
to obtain memory. Note that the ALLOCATOR
parameter type has to be convertible to the allocator of the CONTAINER
parameter type, CONTAINER::allocator_type
; otherwise, this constructor is disabled.
bsl::queue< VALUE, CONTAINER >::queue | ( | const queue< VALUE, CONTAINER > & | original, | |
const ALLOCATOR & | basicAllocator, | |||
typename enable_if< bsl::uses_allocator< CONTAINER, ALLOCATOR >::value, ALLOCATOR >::type * | = 0 | |||
) | [inherited] |
Create a queue having the value of the specified original
that will use the specified basicAllocator
to supply memory. Note that the ALLOCATOR
parameter type has to be convertible to the allocator of the CONTAINER
parameter type, CONTAINER::allocator_type
. Otherwise this constructor is disabled.
bsl::queue< VALUE, CONTAINER >::queue | ( | BloombergLP::bslmf::MovableRef< CONTAINER > | container, | |
const ALLOCATOR & | basicAllocator, | |||
typename enable_if< bsl::uses_allocator< CONTAINER, ALLOCATOR >::value, ALLOCATOR >::type * | = 0 | |||
) | [inherited] |
Create a queue whose underlying container has the value of the specified container
(on entry) and uses basicAllocator
to supply memory. The allocated-extended move constructor of CONTAINER
is used to create the new queue. container
is left in a valid but unspecified state. Note that a bslma::Allocator *
can be supplied for basicAllocator
if the (template parameter) ALLOCATOR
is bsl::allocator
(the default). Also note that this method assumes that CONTAINER
has a move constructor. Also note that if CONTAINER::allocator_type
does not exist, this constructor is disabled.
bsl::queue< VALUE, CONTAINER >::queue | ( | BloombergLP::bslmf::MovableRef< queue< VALUE, CONTAINER > > | original, | |
const ALLOCATOR & | basicAllocator, | |||
typename enable_if< bsl::uses_allocator< CONTAINER, ALLOCATOR >::value, ALLOCATOR >::type * | = 0 | |||
) | [inherited] |
Create a queue having the value of the specified original
(on entry), that uses basicAllocator
to supply memory. The allocator-extended move constructor of CONTAINER
is used to create the new queue. original
is left in a valid but unspecified state. Note that a bslma::Allocator *
can be supplied for basicAllocator
if the (template parameter) ALLOCATOR
is bsl::allocator
(the default). Also note that this method assumes that CONTAINER
has a move constructor. Also note that if CONTAINER::allocator_type
does not exist, this constructor is disabled.
queue& bsl::queue< VALUE, CONTAINER >::operator= | ( | const queue< VALUE, CONTAINER > & | rhs | ) | [inherited] |
Assign to this queue the value of the specified rhs
, and return a reference providing modifiable access to this queue.
queue& bsl::queue< VALUE, CONTAINER >::operator= | ( | BloombergLP::bslmf::MovableRef< queue< VALUE, CONTAINER > > | rhs | ) | [inherited] |
Assign to this queue the value as the specified rhs
and return a reference providing modifiable access to this queue. The move-assignment operator of CONTAINER
is used to set the value of this queue. rhs
is left in a valid but unspecified state, and if an exception is thrown, *this
is left in a valid but unspecified state.
reference bsl::queue< VALUE, CONTAINER >::emplace | ( | Args &&... | args | ) | [inherited] |
Push onto this queue a newly created value_type
object constructed by forwarding get_allocator()
(if required) and the specified (variable number of) args
to the corresponding constructor of value_type
. Return a reference providing modifiable access to the inserted element.
void bsl::queue< VALUE, CONTAINER >::push | ( | const value_type & | value | ) | [inherited] |
Push onto the back of this queue a value_type
object having the specified value
.
void bsl::queue< VALUE, CONTAINER >::push | ( | BloombergLP::bslmf::MovableRef< value_type > | value | ) | [inherited] |
Push onto the back of this queue a value_type
object having the value of the specified value
(on entry) by moving the contents of value
to the new object on this queue. value
is left in a valid but unspecified state.
void bsl::queue< VALUE, CONTAINER >::pop | ( | ) | [inherited] |
Remove the front (the earliest pushed) element from this queue
object.
reference bsl::queue< VALUE, CONTAINER >::back | ( | ) | [inherited] |
Return a reference providing modifiable access to the back (the latest pushed) element of this queue
object.
bool bsl::queue< VALUE, CONTAINER >::empty | ( | ) | const [inherited] |
Return true
if this queue
object contains no elements, and false
otherwise. In effect, performs return c.empty();
.
size_type bsl::queue< VALUE, CONTAINER >::size | ( | ) | const [inherited] |
Return the number of elements in this queue. In effect, performs return c.size();
.
const_reference bsl::queue< VALUE, CONTAINER >::front | ( | ) | const [inherited] |
Return the immutable front (the earliest pushed) element from this queue
object. In effect, performs c.front()
.
const_reference bsl::queue< VALUE, CONTAINER >::back | ( | ) | const [inherited] |
Return the immutable back (the latest pushed) element from this queue
object. In effect, performs c.back()
.
bool bsl::operator== | ( | const queue< VALUE, CONTAINER > & | lhs, | |
const queue< VALUE, CONTAINER > & | rhs | |||
) |
Return true
if the specified lhs
and rhs
objects have the same value, and false
otherwise. Two queue
objects lhs
and rhs
have the same value if they have the same number of elements, and each element in the ordered sequence of elements of lhs
has the same value as the corresponding element in the ordered sequence of elements of rhs
. This method requires that the (template parameter) type VALUE
be equality-comparable
(see Requirements on VALUE
).
bool bsl::operator!= | ( | const queue< VALUE, CONTAINER > & | lhs, | |
const queue< VALUE, CONTAINER > & | rhs | |||
) |
Return true
if the specified lhs
and rhs
objects do not have the same value, and false
otherwise. Two queue
objects lhs
and rhs
do not have the same value if they do not have the same number of elements, or some element in the ordered sequence of elements of lhs
does not have the same value as the corresponding element in the ordered sequence of elements of rhs
. This method requires that the (template parameter) type VALUE
be equality-comparable
(see Requirements on VALUE
).
bool bsl::operator< | ( | const queue< VALUE, CONTAINER > & | lhs, | |
const queue< VALUE, CONTAINER > & | rhs | |||
) |
Return true
if the value of the specified lhs
queue is lexicographically less than that of the specified rhs
queue, and false
otherwise. Given iterators i
and j
over the respective sequences [lhs.begin() .. lhs.end())
and [rhs.begin() .. rhs.end())
, the value of queue lhs
is lexicographically less than that of queue rhs
if true == *i < *j
for the first pair of corresponding iterator positions where *i < *j
and *j < *i
are not both false
. If no such corresponding iterator position exists, the value of lhs
is lexicographically less than that of rhs
if lhs.size() < rhs.size()
. This method requires that operator<
, inducing a total order, be defined for value_type
.
bool bsl::operator> | ( | const queue< VALUE, CONTAINER > & | lhs, | |
const queue< VALUE, CONTAINER > & | rhs | |||
) |
Return true
if the value of the specified lhs
queue is lexicographically greater than that of the specified rhs
queue, and false
otherwise. The value of queue lhs
is lexicographically greater than that of queue rhs
if rhs
is lexicographically less than lhs
(see operator<
). This method requires that operator<
, inducing a total order, be defined for value_type
. Note that this operator returns rhs < lhs
.
bool bsl::operator<= | ( | const queue< VALUE, CONTAINER > & | lhs, | |
const queue< VALUE, CONTAINER > & | rhs | |||
) |
Return true
if the value of the specified lhs
queue is lexicographically less than or equal to that of the specified rhs
queue, and false
otherwise. The value of queue lhs
is lexicographically less than or equal to that of queue rhs
if rhs
is not lexicographically less than lhs
(see operator<
). This method requires that operator<
, inducing a total order, be defined for value_type
. Note that this operator returns !(rhs < lhs)
.
bool bsl::operator>= | ( | const queue< VALUE, CONTAINER > & | lhs, | |
const queue< VALUE, CONTAINER > & | rhs | |||
) |
Return true
if the value of the specified lhs
queue is lexicographically greater than or equal to that of the specified rhs
queue, and false
otherwise. The value of queue lhs
is lexicographically greater than or equal to that of queue rhs
if lhs
is not lexicographically less than rhs
(see operator<
). This method requires that operator<
, inducing a total order, be defined for value_type
. Note that this operator returns !(lhs < rhs)
.
void bsl::swap | ( | queue< VALUE, CONTAINER > & | lhs, | |
queue< VALUE, CONTAINER > & | rhs | |||
) |
Swap the value of the specified lhs
queue with the value of the specified rhs
queue.
CONTAINER bsl::queue< VALUE, CONTAINER >::c [protected, inherited] |
Contains the elements of this queue.
void swap (queue& other) BSLS_KEYWORD_NOEXCEPT_SPECIFICATION( bsl reference bsl::queue< VALUE, CONTAINER >::front() [inherited] |
< Efficiently exchange the value of this object with the value of the specified other
object. In effect, performs using bsl::swap; swap(c, other.c);
. Return a reference providing modifiable access to the front (the earliest pushed) element from this queue
object.
bool operator== | ( | const queue< VALUE2, CONTAINER2 > & | , | |
const queue< VALUE2, CONTAINER2 > & | ||||
) | [friend, inherited] |
bool operator!= | ( | const queue< VALUE2, CONTAINER2 > & | , | |
const queue< VALUE2, CONTAINER2 > & | ||||
) | [friend, inherited] |
bool operator< | ( | const queue< VALUE2, CONTAINER2 > & | , | |
const queue< VALUE2, CONTAINER2 > & | ||||
) | [friend, inherited] |
bool operator> | ( | const queue< VALUE2, CONTAINER2 > & | , | |
const queue< VALUE2, CONTAINER2 > & | ||||
) | [friend, inherited] |
bool operator<= | ( | const queue< VALUE2, CONTAINER2 > & | , | |
const queue< VALUE2, CONTAINER2 > & | ||||
) | [friend, inherited] |