C++ Standard Library C++ STL Library

C++ multiset - empty() Function



The C++ multiset::empty function is used to check whether the multiset is empty or not. It returns true if the size of the multiset is zero, else returns false.

Syntax

bool empty() const;
bool empty() const noexcept;

Parameters

No parameter is required.

Return Value

true if the size of the multiset is zero, else returns false.

Time Complexity

Constant i.e, Θ(1).

Example:

In the example below, the multiset::empty function is used to check whether the multiset is empty or not.

#include <iostream>
#include <set>
using namespace std;
 
int main (){
  multiset<int> MyMSet;

  cout<<boolalpha;

  cout<<"Is the Multiset empty?: "<<MyMSet.empty()<<"\n";

  cout<<"Add elements in the Multiset.\n";
  MyMSet.insert(10);
  MyMSet.insert(20);
  MyMSet.insert(30);

  cout<<"Now, Is the Multiset empty?: "<<MyMSet.empty()<<"\n";
  return 0;
}

The output of the above code will be:

Is the Multiset empty?: true
Add elements in the Multiset.
Now, Is the Multiset empty?: false

❮ C++ <set> Library