Last Updated : 18 Sep, 2024
The
unordered_map::max_size
is a built in function in C++ STL. It returns maximum number of elements which unordered_map can hold. Maximum number of elements in any container depends upon system and library implementation.
Syntax
size unordered_map.max_size()
Parameters:
It does not accept any parameters.
Return type:
Unsigned integer a container can hold maximum elements.
Example 1
CPP
// C++ program to illustrate the
// unordered_map::max_size function
#include <bits/stdc++.h>
using namespace std;
int main()
{
// declaration of unordered_map
unordered_map<int, int> sample;
cout << " Current size is : " << sample.size() << endl;
cout << " max size is : " << sample.max_size() << endl;
// insert elements
sample.insert({ 1, 10 });
sample.insert({ 2, 10 });
sample.insert({ 3, 10 });
sample.insert({ 4, 10 });
cout << " Current size is : " << sample.size() << endl;
cout << " max size is : " << sample.max_size() << endl;
return 0;
}
Current size is : 0 max size is : 1152921504606846975 Current size is : 4 max size is : 1152921504606846975
Example 2
CPP
// C++ program to illustrate the
// unordered_map::max_size function
#include <bits/stdc++.h>
using namespace std;
int main()
{
// declaration of unordered_map
unordered_map<char, int> sample;
cout << " Current size is : " << sample.size() << endl;
cout << " max size is : " << sample.max_size() << endl;
// insert elements
sample.insert({ 'a', 10 });
sample.insert({ 'b', 10 });
sample.insert({ 'c', 10 });
cout << " Current size is : " << sample.size() << endl;
cout << " max size is : " << sample.max_size() << endl;
return 0;
}
Current size is : 0 max size is : 1152921504606846975 Current size is : 3 max size is : 1152921504606846975
Complexity :
Its complexity is constant.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4