Skip to content
Related Articles
Open in App
Not now

Related Articles

unordered_set max_size() in C++ STL

Improve Article
Save Article
  • Difficulty Level : Basic
  • Last Updated : 28 Sep, 2018
Improve Article
Save Article

The unordered_set::max_size() is a built-in function in C++ STL, defined in <unordered_set.h> which returns maximum number of elements that an unordered_set container can hold(i.e the maximum size of the unordered_set) due to system constraints or internal implementation .



Parameters: This function does not accepts any parameter. It simply returns the maximum size of the container.

Return Value: This function returns the maximum number of elements that the unordered_set can hold.

Exception: This function does not throw any kind of exception.

Below program illustrate the unordered_set::max_size() function in C++:

// C++ program to illustrate the
// unordered_set::max_size function
#include <iostream>
#include <unordered_set>
using namespace std;
int main()
    // declaration
    unordered_set<int> sample;
    // Get the maximum size of the unordered_set
    cout << sample.max_size();
    return 0;



Time Complexity: O(1)

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!