public member function
<queue>

std::priority_queue::size

size_type size() const;
Return size
Returns the number of elements in the priority_queue.

This member function effectively calls member size of the underlying container object.

Parameters

none

Return Value

The number of elements in the underlying container.

Member type size_type is an unsigned integral type.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// priority_queue::size
#include <iostream>       // std::cout
#include <queue>          // std::priority_queue

int main ()
{
  std::priority_queue<int> myints;
  std::cout << "0. size: " << myints.size() << '\n';

  for (int i=0; i<5; i++) myints.push(i);
  std::cout << "1. size: " << myints.size() << '\n';

  myints.pop();
  std::cout << "2. size: " << myints.size() << '\n';

  return 0;
}

Output:

0. size: 0
1. size: 5
2. size: 4


Complexity

Constant (calling size on the underlying container).

See also