Namespaces
Variants
Views
Actions

std::queue<T,Container>::size

From cppreference.com
< cpp‎ | container‎ | queue
 
 
 
 
size_type size() const;

Returns the number of elements in the underlying container, that is, c.size().

Contents

[edit] Parameters

(none)

[edit] Return value

The number of elements in the container adaptor.

[edit] Complexity

Constant.

[edit] Example

#include <algorithm>
#include <iostream>
#include <queue>
 
int main()
{
    std::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

[edit] See also

checks whether the container adaptor is empty
(public member function) [edit]
(C++17)(C++20)
returns the size of a container or array
(function template) [edit]