Skip to content
Related Articles
Get the best out of our app
Open App

Related Articles

unordered_set max_bucket_count() function in C++ STL

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The unordered_set::max_bucket_count() is a built-in function in C++ STL which is used to find the maximum number of buckets that unordered_set can have. This function returns the maximum number of buckets a system can have because of the constraints specified by the system and some limitations. 

Parameters : This function does not take any parameters. 

Syntax :

size_type max_bucket_count()

Where, size_type is an unsigned integral type. 

Return Value : It returns the maximum number of buckets that the unordered_set container can have. 

Exceptions : An Exception is thrown if any element comparison object throws exception. 

Below program illustrate the unordered_set::max_bucket_count() function: 


// CPP program to illustrate
// unordered_set::max_bucket_count() function
#include <iostream>
#include <unordered_set>
using namespace std;
int main()
    unordered_set<int> Myset;
    // printing the contents
    cout<<"Elements : ";
    for (auto it = Myset.begin(); it != Myset.end(); ++it)
        cout << "[" << *it << "]";
    cout << endl;
    // inspect current parameters
    cout << "max_size : " << Myset.max_size() << endl;
    cout << "max_bucket_count() : " << Myset.max_bucket_count() << endl;
    cout << "max_load_factor() : " << Myset.max_load_factor() << endl;
    return 0;


Elements : [20][10]
max_size : 1152921504606846975
max_bucket_count() : 1152921504606846975
max_load_factor() : 1

Time Complexity: It takes constant time of complexity to perform an operation.

My Personal Notes arrow_drop_up
Last Updated : 05 Jun, 2023
Like Article
Save Article
Similar Reads
Related Tutorials