C++ max_bucket_count()

Anonymous contributor's avatar
Anonymous contributor
Published Jan 5, 2026
Contribute to Docs

The max_bucket_count() method returns the maximum number of buckets that an unordered_set container can have. This value represents a theoretical upper limit imposed by the system or library implementation, not the current number of buckets in use. The actual number of buckets used by the container is typically much smaller and can be queried using bucket_count().

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn C++ — a versatile programming language that’s important for developing software, games, databases, and more.
    • Beginner Friendly.
      11 hours

Syntax

unordered_set_name.max_bucket_count();

Parameters:

This method takes no parameters.

Return value:

Returns a size_type value representing the maximum possible number of buckets the container could theoretically hold. This is an implementation-defined limit that is typically a very large number.

Example

This example demonstrates obtaining the maximum bucket count and comparing it with the current bucket count:

#include <iostream>
#include <unordered_set>
using namespace std;
int main() {
unordered_set<int> numbers = {10, 20, 30, 40, 50};
cout << "Maximum bucket count: " << numbers.max_bucket_count() << "\n";
cout << "Current bucket count: " << numbers.bucket_count() << "\n";
cout << "Number of elements: " << numbers.size() << "\n";
return 0;
}

A sample output of this code is:

Maximum bucket count: 576460752303423487
Current bucket count: 7
Number of elements: 5

Note: The exact maximum bucket count value may vary depending on the system architecture and compiler implementation.

Codebyte Example

In this example, the code demonstrates how the maximum bucket count remains constant while the current bucket count can change as elements are added:

Code
Output

All contributors

Contribute to Docs

Learn C++ on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn C++ — a versatile programming language that’s important for developing software, games, databases, and more.
    • Beginner Friendly.
      11 hours