Facebook Page Twitter Page LinkedIn Page
× C++ Standard Library C++ STL Library


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 below example, 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<<"Is the Multiset empty?: "<<MyMSet.empty()<<"\n\n";

  cout<<"Add three 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?: 1

Add three elements in the Multiset:
Now, Is the Multiset empty?: 0

❮ C++ - Multiset