C++ unordered_multimap - max_size() Function
The C++ unordered_multimap::max_size function returns the maximum size the unordered_multimap can reach. The function returns the maximum potential size the unordered_multimap can reach due to known system or library implementation limitations.
Syntax
size_type max_size() const noexcept;
Parameters
No parameter is required.
Return Value
Maximum number of elements that can be held in a unordered_multimap.
Time Complexity
Constant i.e, Θ(1).
Example:
In the example below, the unordered_multimap::max_size function is used find out the maximum number of elements that a unordered_multimap can hold.
#include <iostream> #include <unordered_map> using namespace std; int main (){ unordered_multimap<string, string> uMMap; unordered_multimap<string, string>::iterator it; uMMap.insert(pair<string, string>("USA", "New York")); uMMap.insert(pair<string, string>("USA", "Washington")); uMMap.insert(pair<string, string>("CAN", "Toronto")); uMMap.insert(pair<string, string>("CAN", "Montreal")); uMMap.insert(pair<string, string>("IND", "Delhi")); cout<<"The unordered_multimap contains:\n"; for(it = uMMap.begin(); it != uMMap.end(); ++it) cout<<it->first<<" "<<it->second<<"\n"; cout<<"\nUnordered Multimap size is: "<<uMMap.size()<<"\n"; cout<<"Maximum size of the Unordered Multimap: "<<uMMap.max_size()<<"\n"; return 0; }
A possible output could be:
The unordered_multimap contains: IND Delhi CAN Montreal CAN Toronto USA Washington USA New York Unordered Multimap size is: 5 Maximum size of the Unordered Multimap: 115292150460684697
❮ C++ <unordered_map> Library