libstdc++
std::priority_queue< _Tp, _Sequence, _Compare > Class Template Reference

#include <stl_queue.h>

Public Types

typedef _Sequence::const_reference const_reference
typedef _Sequence container_type
typedef _Sequence::reference reference
typedef _Sequence::size_type size_type
typedef _Compare value_compare
typedef _Sequence::value_type value_type

Public Member Functions

template<typename _Seq = _Sequence, typename _Requires = typename enable_if<__and_<is_default_constructible<_Compare>, is_default_constructible<_Seq>>::value>::type>
constexpr priority_queue ()
template<typename _InputIterator, typename _Alloc, typename = std::_RequireInputIter<_InputIterator>, typename _Requires = _Uses<_Alloc>>
constexpr priority_queue (_InputIterator __first, _InputIterator __last, const _Alloc &__alloc)
template<typename _InputIterator, typename _Alloc, typename _Requires = _Uses<_Alloc>>
constexpr priority_queue (_InputIterator __first, _InputIterator __last, const _Compare &__x, _Sequence &&__s, const _Alloc &__alloc)
template<typename _InputIterator, typename _Alloc, typename = std::_RequireInputIter<_InputIterator>, typename _Requires = _Uses<_Alloc>>
constexpr priority_queue (_InputIterator __first, _InputIterator __last, const _Compare &__x, const _Alloc &__alloc)
template<typename _InputIterator, typename _Alloc, typename = std::_RequireInputIter<_InputIterator>, typename _Requires = _Uses<_Alloc>>
constexpr priority_queue (_InputIterator __first, _InputIterator __last, const _Compare &__x, const _Sequence &__s, const _Alloc &__alloc)
template<typename _Alloc, typename _Requires = _Uses<_Alloc>>
constexpr priority_queue (const _Alloc &__a)
template<typename _Alloc, typename _Requires = _Uses<_Alloc>>
constexpr priority_queue (const _Compare &__x, _Sequence &&__c, const _Alloc &__a)
constexpr priority_queue (const _Compare &__x, _Sequence &&__s=_Sequence())
template<typename _Alloc, typename _Requires = _Uses<_Alloc>>
constexpr priority_queue (const _Compare &__x, const _Alloc &__a)
template<typename _Alloc, typename _Requires = _Uses<_Alloc>>
constexpr priority_queue (const _Compare &__x, const _Sequence &__c, const _Alloc &__a)
constexpr priority_queue (const _Compare &__x, const _Sequence &__s)
 priority_queue (const priority_queue &)=default
template<typename _Alloc, typename _Requires = _Uses<_Alloc>>
constexpr priority_queue (const priority_queue &__q, const _Alloc &__a)
constexpr priority_queue (priority_queue &&__q) noexcept(__and_< is_nothrow_move_constructible< _Sequence >, is_nothrow_move_constructible< _Compare > >::value)
template<typename _Alloc, typename _Requires = _Uses<_Alloc>>
constexpr priority_queue (priority_queue &&__q, const _Alloc &__a)
template<typename... _Args>
constexpr void emplace (_Args &&... __args)
constexpr bool empty () const
priority_queueoperator= (const priority_queue &)=default
constexpr priority_queueoperator= (priority_queue &&__q) noexcept(__and_< is_nothrow_move_assignable< _Sequence >, is_nothrow_move_assignable< _Compare > >::value)
constexpr void pop ()
constexpr void push (const value_type &__x)
constexpr void push (value_type &&__x)
constexpr size_type size () const
constexpr void swap (priority_queue &__pq) noexcept(__and_<//c++1z or gnu++11 __is_nothrow_swappable< _Sequence >, __is_nothrow_swappable< _Compare > >::value)
constexpr const_reference top () const
template<typename _InputIterator, typename = std::_RequireInputIter<_InputIterator>>
constexpr priority_queue (_InputIterator __first, _InputIterator __last, const _Compare &__x=_Compare())
template<typename _InputIterator, typename = std::_RequireInputIter<_InputIterator>>
constexpr priority_queue (_InputIterator __first, _InputIterator __last, const _Compare &__x, const _Sequence &__s)
template<typename _InputIterator, typename = std::_RequireInputIter<_InputIterator>>
constexpr priority_queue (_InputIterator __first, _InputIterator __last, const _Compare &__x, _Sequence &&__s)

Protected Attributes

_Sequence c
_Compare comp

Detailed Description

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare = less<typename _Sequence::value_type>>
class std::priority_queue< _Tp, _Sequence, _Compare >

A standard container automatically sorting its contents.

Template Parameters
_TpType of element.
_SequenceType of underlying sequence, defaults to vector<_Tp>.
_CompareComparison function object type, defaults to less<_Sequence::value_type>.

This is not a true container, but an adaptor. It holds another container, and provides a wrapper interface to that container. The wrapper is what enforces priority-based sorting and queue behavior. Very few of the standard container/sequence interface requirements are met (e.g., iterators).

The second template parameter defines the type of the underlying sequence/container. It defaults to std::vector, but it can be any type that supports front(), push_back, pop_back, and random-access iterators, such as std::deque or an appropriate user-defined type.

The third template parameter supplies the means of making priority comparisons. It defaults to less<value_type> but can be anything defining a strict weak ordering.

Members not found in normal containers are container_type, which is a typedef for the second Sequence parameter, and push, pop, and top, which are standard queue operations.

Note
No equality/comparison operators are provided for priority_queue.
Sorting of the elements takes place as they are added to, and removed from, the priority_queue using the priority_queue's member functions. If you access the elements by other means, and change their data such that the sorting order would be different, the priority_queue will not re-sort the elements for you. (How could it know to do so?)

Definition at line 552 of file stl_queue.h.

Member Typedef Documentation

◆ const_reference

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare = less<typename _Sequence::value_type>>
typedef _Sequence::const_reference std::priority_queue< _Tp, _Sequence, _Compare >::const_reference

Definition at line 584 of file stl_queue.h.

◆ container_type

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare = less<typename _Sequence::value_type>>
typedef _Sequence std::priority_queue< _Tp, _Sequence, _Compare >::container_type

Definition at line 586 of file stl_queue.h.

◆ reference

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare = less<typename _Sequence::value_type>>
typedef _Sequence::reference std::priority_queue< _Tp, _Sequence, _Compare >::reference

Definition at line 583 of file stl_queue.h.

◆ size_type

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare = less<typename _Sequence::value_type>>
typedef _Sequence::size_type std::priority_queue< _Tp, _Sequence, _Compare >::size_type

Definition at line 585 of file stl_queue.h.

◆ value_compare

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare = less<typename _Sequence::value_type>>
typedef _Compare std::priority_queue< _Tp, _Sequence, _Compare >::value_compare

Definition at line 589 of file stl_queue.h.

◆ value_type

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare = less<typename _Sequence::value_type>>
typedef _Sequence::value_type std::priority_queue< _Tp, _Sequence, _Compare >::value_type

Definition at line 582 of file stl_queue.h.

Constructor & Destructor Documentation

◆ priority_queue() [1/17]

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare = less<typename _Sequence::value_type>>
template<typename _Seq = _Sequence, typename _Requires = typename enable_if<__and_<is_default_constructible<_Compare>, is_default_constructible<_Seq>>::value>::type>
std::priority_queue< _Tp, _Sequence, _Compare >::priority_queue ( )
inlineconstexpr

Default constructor creates no elements.

Definition at line 611 of file stl_queue.h.

◆ priority_queue() [2/17]

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare = less<typename _Sequence::value_type>>
std::priority_queue< _Tp, _Sequence, _Compare >::priority_queue ( const _Compare & __x,
const _Sequence & __s )
inlineexplicitconstexpr

Definition at line 616 of file stl_queue.h.

◆ priority_queue() [3/17]

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare = less<typename _Sequence::value_type>>
std::priority_queue< _Tp, _Sequence, _Compare >::priority_queue ( const _Compare & __x,
_Sequence && __s = _Sequence() )
inlineexplicitconstexpr

Definition at line 622 of file stl_queue.h.

◆ priority_queue() [4/17]

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare = less<typename _Sequence::value_type>>
std::priority_queue< _Tp, _Sequence, _Compare >::priority_queue ( priority_queue< _Tp, _Sequence, _Compare > && __q)
inlineconstexprnoexcept

Definition at line 630 of file stl_queue.h.

◆ priority_queue() [5/17]

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare = less<typename _Sequence::value_type>>
template<typename _Alloc, typename _Requires = _Uses<_Alloc>>
std::priority_queue< _Tp, _Sequence, _Compare >::priority_queue ( const _Alloc & __a)
inlineexplicitconstexpr

Definition at line 651 of file stl_queue.h.

◆ priority_queue() [6/17]

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare = less<typename _Sequence::value_type>>
template<typename _Alloc, typename _Requires = _Uses<_Alloc>>
std::priority_queue< _Tp, _Sequence, _Compare >::priority_queue ( const _Compare & __x,
const _Alloc & __a )
inlineconstexpr

Definition at line 656 of file stl_queue.h.

◆ priority_queue() [7/17]

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare = less<typename _Sequence::value_type>>
template<typename _Alloc, typename _Requires = _Uses<_Alloc>>
std::priority_queue< _Tp, _Sequence, _Compare >::priority_queue ( const _Compare & __x,
const _Sequence & __c,
const _Alloc & __a )
inlineconstexpr

Definition at line 663 of file stl_queue.h.

◆ priority_queue() [8/17]

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare = less<typename _Sequence::value_type>>
template<typename _Alloc, typename _Requires = _Uses<_Alloc>>
std::priority_queue< _Tp, _Sequence, _Compare >::priority_queue ( const _Compare & __x,
_Sequence && __c,
const _Alloc & __a )
inlineconstexpr

Definition at line 670 of file stl_queue.h.

◆ priority_queue() [9/17]

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare = less<typename _Sequence::value_type>>
template<typename _Alloc, typename _Requires = _Uses<_Alloc>>
std::priority_queue< _Tp, _Sequence, _Compare >::priority_queue ( const priority_queue< _Tp, _Sequence, _Compare > & __q,
const _Alloc & __a )
inlineconstexpr

Definition at line 676 of file stl_queue.h.

◆ priority_queue() [10/17]

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare = less<typename _Sequence::value_type>>
template<typename _Alloc, typename _Requires = _Uses<_Alloc>>
std::priority_queue< _Tp, _Sequence, _Compare >::priority_queue ( priority_queue< _Tp, _Sequence, _Compare > && __q,
const _Alloc & __a )
inlineconstexpr

Definition at line 681 of file stl_queue.h.

◆ priority_queue() [11/17]

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare = less<typename _Sequence::value_type>>
template<typename _InputIterator, typename = std::_RequireInputIter<_InputIterator>>
std::priority_queue< _Tp, _Sequence, _Compare >::priority_queue ( _InputIterator __first,
_InputIterator __last,
const _Compare & __x = _Compare() )
inlineconstexpr

Builds a queue from a range.

Parameters
__firstAn input iterator.
__lastAn input iterator.
__xA comparison functor describing a strict weak ordering.
__sAn initial sequence with which to start.

Begins by copying __s, inserting a copy of the elements from [first,last) into the copy of __s, then ordering the copy according to __x.

For more information on function objects, see the documentation on functor base classes.

Definition at line 719 of file stl_queue.h.

◆ priority_queue() [12/17]

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare = less<typename _Sequence::value_type>>
template<typename _InputIterator, typename = std::_RequireInputIter<_InputIterator>>
std::priority_queue< _Tp, _Sequence, _Compare >::priority_queue ( _InputIterator __first,
_InputIterator __last,
const _Compare & __x,
const _Sequence & __s )
inlineconstexpr

Builds a queue from a range.

Parameters
__firstAn input iterator.
__lastAn input iterator.
__xA comparison functor describing a strict weak ordering.
__sAn initial sequence with which to start.

Begins by copying __s, inserting a copy of the elements from [first,last) into the copy of __s, then ordering the copy according to __x.

For more information on function objects, see the documentation on functor base classes.

Definition at line 729 of file stl_queue.h.

◆ priority_queue() [13/17]

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare = less<typename _Sequence::value_type>>
template<typename _InputIterator, typename = std::_RequireInputIter<_InputIterator>>
std::priority_queue< _Tp, _Sequence, _Compare >::priority_queue ( _InputIterator __first,
_InputIterator __last,
const _Compare & __x,
_Sequence && __s )
inlineconstexpr

Builds a queue from a range.

Parameters
__firstAn input iterator.
__lastAn input iterator.
__xA comparison functor describing a strict weak ordering.
__sAn initial sequence with which to start.

Begins by copying __s, inserting a copy of the elements from [first,last) into the copy of __s, then ordering the copy according to __x.

For more information on function objects, see the documentation on functor base classes.

Definition at line 741 of file stl_queue.h.

References std::move().

◆ priority_queue() [14/17]

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare = less<typename _Sequence::value_type>>
template<typename _InputIterator, typename _Alloc, typename = std::_RequireInputIter<_InputIterator>, typename _Requires = _Uses<_Alloc>>
std::priority_queue< _Tp, _Sequence, _Compare >::priority_queue ( _InputIterator __first,
_InputIterator __last,
const _Alloc & __alloc )
inlineconstexpr

Definition at line 759 of file stl_queue.h.

◆ priority_queue() [15/17]

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare = less<typename _Sequence::value_type>>
template<typename _InputIterator, typename _Alloc, typename = std::_RequireInputIter<_InputIterator>, typename _Requires = _Uses<_Alloc>>
std::priority_queue< _Tp, _Sequence, _Compare >::priority_queue ( _InputIterator __first,
_InputIterator __last,
const _Compare & __x,
const _Alloc & __alloc )
inlineconstexpr

Definition at line 768 of file stl_queue.h.

◆ priority_queue() [16/17]

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare = less<typename _Sequence::value_type>>
template<typename _InputIterator, typename _Alloc, typename = std::_RequireInputIter<_InputIterator>, typename _Requires = _Uses<_Alloc>>
std::priority_queue< _Tp, _Sequence, _Compare >::priority_queue ( _InputIterator __first,
_InputIterator __last,
const _Compare & __x,
const _Sequence & __s,
const _Alloc & __alloc )
inlineconstexpr

Definition at line 777 of file stl_queue.h.

◆ priority_queue() [17/17]

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare = less<typename _Sequence::value_type>>
template<typename _InputIterator, typename _Alloc, typename _Requires = _Uses<_Alloc>>
std::priority_queue< _Tp, _Sequence, _Compare >::priority_queue ( _InputIterator __first,
_InputIterator __last,
const _Compare & __x,
_Sequence && __s,
const _Alloc & __alloc )
inlineconstexpr

Definition at line 790 of file stl_queue.h.

Member Function Documentation

◆ emplace()

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare = less<typename _Sequence::value_type>>
template<typename... _Args>
void std::priority_queue< _Tp, _Sequence, _Compare >::emplace ( _Args &&... __args)
inlineconstexpr

Definition at line 884 of file stl_queue.h.

◆ empty()

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare = less<typename _Sequence::value_type>>
bool std::priority_queue< _Tp, _Sequence, _Compare >::empty ( ) const
inlinenodiscardconstexpr

Returns true if the queue is empty.

Definition at line 835 of file stl_queue.h.

Referenced by __gnu_parallel::multiseq_partition(), and __gnu_parallel::multiseq_selection().

◆ operator=()

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare = less<typename _Sequence::value_type>>
priority_queue & std::priority_queue< _Tp, _Sequence, _Compare >::operator= ( priority_queue< _Tp, _Sequence, _Compare > && __q)
inlineconstexprnoexcept

Definition at line 638 of file stl_queue.h.

◆ pop()

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare = less<typename _Sequence::value_type>>
void std::priority_queue< _Tp, _Sequence, _Compare >::pop ( )
inlineconstexpr

Removes first element.

This is a typical queue operation. It shrinks the queue by one. The time complexity of the operation depends on the underlying sequence.

Note that no data is returned, and if the first element's data is needed, it should be retrieved before pop() is called.

Definition at line 918 of file stl_queue.h.

Referenced by __gnu_parallel::multiseq_partition(), and __gnu_parallel::multiseq_selection().

◆ push() [1/2]

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare = less<typename _Sequence::value_type>>
void std::priority_queue< _Tp, _Sequence, _Compare >::push ( const value_type & __x)
inlineconstexpr

Add data to the queue.

Parameters
__xData to be added.

This is a typical queue operation. The time complexity of the operation depends on the underlying sequence.

Definition at line 866 of file stl_queue.h.

Referenced by __gnu_parallel::multiseq_partition(), and __gnu_parallel::multiseq_selection().

◆ push() [2/2]

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare = less<typename _Sequence::value_type>>
void std::priority_queue< _Tp, _Sequence, _Compare >::push ( value_type && __x)
inlineconstexpr

Definition at line 875 of file stl_queue.h.

◆ size()

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare = less<typename _Sequence::value_type>>
size_type std::priority_queue< _Tp, _Sequence, _Compare >::size ( ) const
inlinenodiscardconstexpr

Returns the number of elements in the queue.

Definition at line 841 of file stl_queue.h.

◆ swap()

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare = less<typename _Sequence::value_type>>
void std::priority_queue< _Tp, _Sequence, _Compare >::swap ( priority_queue< _Tp, _Sequence, _Compare > & __pq)
inlineconstexprnoexcept

Definition at line 928 of file stl_queue.h.

◆ top()

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare = less<typename _Sequence::value_type>>
const_reference std::priority_queue< _Tp, _Sequence, _Compare >::top ( ) const
inlinenodiscardconstexpr

Returns a read-only (constant) reference to the data at the first element of the queue.

Definition at line 850 of file stl_queue.h.

Referenced by __gnu_parallel::multiseq_partition(), and __gnu_parallel::multiseq_selection().

Member Data Documentation

◆ c

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare = less<typename _Sequence::value_type>>
_Sequence std::priority_queue< _Tp, _Sequence, _Compare >::c
protected

Definition at line 593 of file stl_queue.h.

◆ comp

template<typename _Tp, typename _Sequence = vector<_Tp>, typename _Compare = less<typename _Sequence::value_type>>
_Compare std::priority_queue< _Tp, _Sequence, _Compare >::comp
protected

Definition at line 594 of file stl_queue.h.


The documentation for this class was generated from the following file: