public member function
<queue>

std::priority_queue::pop

void pop();
Remove top element
Removes the element on top of the priority_queue, effectively reducing its size by one. The element removed is the one with the highest value.

The value of this element can be retrieved before being popped by calling member priority_queue::top.

This member function effectively calls the pop_heap algorithm to keep the heap property of priority_queues and then calls the member function pop_back of the underlying container object to remove the element.

This calls the removed element's destructor.

Parameters

none

Return value

none

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// priority_queue::push/pop
#include <iostream>       // std::cout
#include <queue>          // std::priority_queue

int main ()
{
  std::priority_queue<int> mypq;

  mypq.push(30);
  mypq.push(100);
  mypq.push(25);
  mypq.push(40);

  std::cout << "Popping out elements...";
  while (!mypq.empty())
  {
     std::cout << ' ' << mypq.top();
     mypq.pop();
  }
  std::cout << '\n';

  return 0;
}


Output:
Popping out elements... 100 40 30 25

Complexity

One call to pop_heap and one call to pop_back on the underlying container.

Data races

The container and up to all its contained elements are modified.

Exception safety

Provides the same level of guarantees as the operations performed on the underlying container object.

See also