class template


template <class T, class Container = vector<T>,
  class Compare = less<typename Container::value_type> > class priority_queue;
Priority queue
Priority queues are a type of container adaptors, specifically designed such that its first element is always the greatest of the elements it contains, according to some strict weak ordering criterion.

This context is similar to a heap, where elements can be inserted at any moment, and only the max heap element can be retrieved (the one at the top in the priority queue).

Priority queues are implemented as container adaptors, which are classes that use an encapsulated object of a specific container class as its underlying container, providing a specific set of member functions to access its elements. Elements are popped from the "back" of the specific container, which is known as the top of the priority queue.

The underlying container may be any of the standard container class templates or some other specifically designed container class. The container shall be accessible through random access iterators and support the following operations:
  • empty()
  • size()
  • front()
  • push_back()
  • pop_back()

The standard container classes vector and deque fulfill these requirements. By default, if no container class is specified for a particular priority_queue class instantiation, the standard container vector is used.

Support of random access iterators is required to keep a heap structure internally at all times. This is done automatically by the container adaptor by automatically calling the algorithm functions make_heap, push_heap and pop_heap when needed.

Template parameters

Type of the elements.
Aliased as member type priority_queue::value_type.
Type of the internal underlying container object where the elements are stored.
Its value_type shall be T.
Aliased as member type priority_queue::container_type.
A binary predicate that takes two elements (of type T) as arguments and returns a bool.
The expression comp(a,b), where comp is an object of this type and a and b are elements in the container, shall return true if a is considered to go before b in the strict weak ordering the function defines.
The priority_queue uses this function to maintain the elements sorted in a way that preserves heap properties (i.e., that the element popped is the last according to this strict weak ordering).
This can be a function pointer or a function object, and defaults to less<T>, which returns the same as applying the less-than operator (a<b).

Member types

member typedefinitionnotes
value_typeThe first template parameter (T)Type of the elements
container_typeThe second template parameter (Container)Type of the underlying container
size_typean unsigned integral typeusually the same as size_t
member typedefinitionnotes
value_typeThe first template parameter (T)Type of the elements
container_typeThe second template parameter (Container)Type of the underlying container
referencecontainer_type::referenceusually, value_type&
const_referencecontainer_type::const_referenceusually, const value_type&
size_typean unsigned integral typeusually, the same as size_t

Member functions

Non-member function overloads

Non-member class specializations

  • 1793521592 2018-02-23
  • 2864591591 2018-02-23
  • 6167231590 2018-02-23
  • 3669201589 2018-02-23
  • 7946381588 2018-02-23
  • 8957701587 2018-02-23
  • 3891941586 2018-02-23
  • 6039851585 2018-02-23
  • 2573991584 2018-02-23
  • 7728781583 2018-02-23
  • 3731582 2018-02-23
  • 1007451581 2018-02-22
  • 8908121580 2018-02-22
  • 141161579 2018-02-22
  • 9421578 2018-02-22
  • 2826901577 2018-02-22
  • 3647361576 2018-02-22
  • 5717551575 2018-02-22
  • 523811574 2018-02-22
  • 6439871573 2018-02-22