std::priority_queue<T,Container,Compare>::size
size_type size() const; |
Returns the number of elements in the underlying container, that is, c.size()
.
Parameters
(none)
Return value
The number of elements in the container adaptor.
Complexity
Constant.
Example
#include <algorithm> #include <iostream> #include <queue> int main() { std::priority_queue<int> queue; std::cout << "Initially, queue.size(): " << queue.size() << '\n'; for (int i = 0; i < 8; ++i) queue.push(i); std::cout << "After adding elements, queue.size(): " << queue.size() << '\n'; }
Output:
Initially, queue.size(): 0 After adding elements, queue.size(): 8
See also
checks whether the container adaptor is empty (public member function) |
|
(C++17)(C++20) | returns the size of a container or array (function template) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/container/priority_queue/size