unordered_set empty() function in C++ STL

The unordered_set::empty is a built-in function in C++ STL which is used to check if an unordered_set container is empty or not. It returns True if the unordered_set container is empty, otherwise it returns False.

Syntax:

map_name.empty()

Parameters: This function does not accepts any parameter.

Return Value: It returns a boolean value True if the unordered_set container is empty, else false.

Below programs illustrate the above function:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate the
// unordered_set::empty function
#include <iostream>
#include <unordered_set>
using namespace std;
  
int main()
{
  
    // declaration
    unordered_set<int> sample;
  
    // Check whether the unordered_set is empty
    if (sample.empty() == true)
        cout << "true" << endl;
    else
        cout << "false" << endl;
  
    // Insert a value
    sample.insert(5);
  
    // Now check whether it is empty
    if (sample.empty() == true)
        cout << "true" << endl;
    else
        cout << "false" << endl;
  
    return 0;
}

chevron_right


Output:

true
false

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to illustrate the
// unordered_set::empty function
#include <iostream>
#include <unordered_set>
using namespace std;
  
int main()
{
    // declaration
    unordered_set<int> uset;
  
    // Insert a value
    uset.insert({ 5, 6, 7, 8 });
    // Check whether the unordered_set is empty
    if (uset.empty() == true)
        cout << "true" << endl;
    else
        cout << "false" << endl;
  
    return 0;
}

chevron_right


Output:

false


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.