template<typename Tp>
Queue class

Template parameters
Tp the queue data type

A thread-safe queue implementation.

Constructors, destructors, conversion operators

Queue()
Queue(int maxSize) explicit

Public functions

auto empty() -> bool
auto size() -> int
auto length() const -> int
auto push(const Tp& value) -> bool
auto push(Tp&& value) -> bool
auto pop(Tp& target) -> bool
void wait_pop(Tp& target)
auto pop_if(function<bool(const Tp&front)>&& predicate) -> bool

Function documentation

template<typename Tp>
Queue<Tp>::Queue()

Creates an empty instance of this queue.

template<typename Tp>
Queue<Tp>::Queue(int maxSize) explicit

Parameters
maxSize the queue's capacity

Creates an instance of this queue with a maximum capacity.

template<typename Tp>
bool Queue<Tp>::empty()

Returns true if this queue is empty

Whether this queue is empty.

template<typename Tp>
int Queue<Tp>::size()

Returns the current size

Returns the current size of this queue.

template<typename Tp>
int Queue<Tp>::length() const

Returns the capacity

Returns the queue capacity.

template<typename Tp>
bool Queue<Tp>::push(const Tp& value)

Parameters
value the value to insert
Returns whether insertion succeeded

Pushes a value reference onto this queue and notifies any waiters.

template<typename Tp>
bool Queue<Tp>::push(Tp&& value)

Parameters
value the value to insert
Returns whether insertion succeeded

Pushes an rvalue reference onto this queue and notifies any waiters.

template<typename Tp>
bool Queue<Tp>::pop(Tp& target)

Parameters
target a reference to receive the popped value
Returns whether the operation succeeded

Pops an item from this queue and returns it through the target.

template<typename Tp>
void Queue<Tp>::wait_pop(Tp& target)

Parameters
target a reference to receive the popped value

Waits for an indefinite amount of time for another thread to insert an item into this queue.

template<typename Tp>
bool Queue<Tp>::pop_if(function<bool(const Tp&front)>&& predicate)

Parameters
predicate the function to test
Returns whether the operation succeeded

Pops an item if the predicate function succeeds determines it should.