unordered_multiset empty() function in C++STL

The unordered_multiset::empty() is a built-in function in C++ STL which returns a boolean value. It returns true if the unordered_multiset container is empty. Otherwise, it returns false.

Syntax:

unordered_multiset_name.empty()

Parameters: The function does not accepts any parameter.

Return Value: It returns a boolean value which denotes whether a unordered_multiset is empty or not.

Below programs illustrates the above function:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate the
// unordered_multiset::empty() function
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
  
    // declaration
    unordered_multiset<int> sample;
  
    // inserts element
    sample.insert(11);
    sample.insert(11);
    sample.insert(11);
    sample.insert(12);
    sample.insert(13);
    sample.insert(13);
    sample.insert(14);
  
    // if not empty then print the elements
    if (sample.empty() == false) {
        cout << "Elements: ";
  
        for (auto it = sample.begin(); it != sample.end(); it++) {
            cout << *it << " ";
        }
    }
  
    // container is erased completely
    sample.clear();
  
    if (sample.empty() == true)
        cout << "\nContainer is empty";
    return 0;
}

chevron_right


Output:

Elements: 14 11 11 11 12 13 13 
Container is empty

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate the
// unordered_multiset::empty() function
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
  
    // declaration
    unordered_multiset<char> sample;
  
    // inserts element
    sample.insert('a');
    sample.insert('a');
    sample.insert('b');
    sample.insert('c');
    sample.insert('d');
    sample.insert('d');
    sample.insert('d');
  
    // if not empty then print the elements
    if (sample.empty() == false) {
        cout << "Elements: ";
  
        for (auto it = sample.begin(); it != sample.end(); it++) {
            cout << *it << " ";
        }
    }
  
    // container is erased completely
    sample.clear();
  
    if (sample.empty() == true)
        cout << "\nContainer is empty";
    return 0;
}

chevron_right


Output:

Elements: a a b c d d d 
Container is empty


My Personal Notes arrow_drop_up

The function of education is to teach one to think intensively and to think critically

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.