C++ Standard Library C++ STL Library

C++ unordered_multiset - size() Function



The C++ unordered_multiset::size function is used to find out the total number of elements in the unordered_multiset.

Syntax

size_type size() const noexcept;

Parameters

No parameter is required.

Return Value

Number of elements present in the unordered_multiset.

Time Complexity

Constant i.e, Θ(1).

Example:

In the example below, the unordered_multiset::size function is used find out the total number of elements in a unordered_multiset called uMSet.

#include <iostream>
#include <unordered_set>
using namespace std;
 
int main (){
  unordered_multiset<int> uMSet{55, 25, 55, 5, 72, 72};

  cout<<"Unordered Multiset size is: "<<uMSet.size()<<"\n";

  cout<<"Three elements are added in the Unordered Multiset.\n";
  uMSet.insert(72);
  uMSet.insert(22);
  uMSet.insert(54);

  cout<<"Now, Unordered Multiset size is: "<<uMSet.size()<<"\n";
  return 0;
}

The output of the above code will be:

Unordered Multiset size is: 6
Three elements are added in the Unordered Multiset.
Now, Unordered Multiset size is: 9

❮ C++ <unordered_set> Library

5