# std::priority_queue<T,Container,Compare>::size

From cppreference.com
< cpp‎ | container‎ | priority queue

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.

### Complexity

Constant.

### Example

Run this code

    #include <algorithm>
    #include <iostream>
    #include <queue>

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

        std::cout << "Initially, container.size(): " << container.size() << '\n';

        for (int i = 0; i < 7; ++i)
            container.push(i);

        std::cout << "After adding elements, container.size(): " << container.size() << '\n';
    }

Output:

    Initially, container.size(): 0
    After adding elements, container.size(): 7

### See also

empty | checks whether the underlying container is empty (public member function)

Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/container/priority_queue/size&oldid=133056"