C++ std::unordered_map max_bucket_count() Function
Beginner
5 min read
Updated: Nov 2026
3 examples
std::unordered_map
Definition
In C++, std::unordered_map::max_bucket_count() returns the largest number of buckets this unordered_map type could ever have.
The value is usually huge. Real programs run out of memory long before they reach it. Include <unordered_map> to use it.
This is a member of std::unordered_map<Key, T>, a hash table of key and value pairs. Each key is unique. Find, insert, and erase are usually average constant time. Unlike std::map, keys are not sorted and iteration order is unspecified. Read a value with at() or find(). The m[key] operator also works, but it adds a default value when the key is missing.
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.