C++ std::unordered_set max_bucket_count() Function
Beginner
5 min read
Updated: Nov 2026
3 examples
std::unordered_set
Definition
In C++, std::unordered_set::max_bucket_count() returns the largest number of buckets this unordered_set type could ever have.
The value is usually huge. Real programs run out of memory long before they reach it. Include <unordered_set> to use it.
This is a member of std::unordered_set<T>, a hash table of unique values. Find, insert, and erase are usually average constant time. Unlike std::set, values are not sorted and iteration order is unspecified. Elements are const, so you cannot change a stored value through an iterator. There is no operator[] and no at(). Prefer find() or contains() to look up a value, and call reserve() before many inserts.
Syntax
Call max_bucket_count with empty brackets.
C++
std::size_t limit = m.max_bucket_count();
bool ok = m.bucket_count() <= limit;
Call
What it does
m.max_bucket_count()
Returns the theoretical maximum bucket count.
Do not print the raw number in tests that must match everywhere. It is implementation-defined. Use it only as an upper bound check.
Library declarations
C++
size_type max_bucket_count() const;
Parameters
Parameter
Description
None
max_bucket_count() takes no parameters. Call it with empty brackets.
Return Value
Return Value
Description
size_type
The maximum number of buckets the type could support.
C++ Examples
Example 1 — max_bucket_count() Is Far Above Current Buckets
Show that the limit is larger than the current table.