![The C++ Standard Library](/cpp_standard_library/images/cpp-mini-lib-logo.jpg)
- The C Standard Library
- The C Standard Library
- The C++ Standard Library
- C++ Library - Home
- C++ Library - <fstream>
- C++ Library - <iomanip>
- C++ Library - <ios>
- C++ Library - <iosfwd>
- C++ Library - <iostream>
- C++ Library - <istream>
- C++ Library - <ostream>
- C++ Library - <sstream>
- C++ Library - <streambuf>
- C++ Library - <atomic>
- C++ Library - <complex>
- C++ Library - <exception>
- C++ Library - <functional>
- C++ Library - <limits>
- C++ Library - <locale>
- C++ Library - <memory>
- C++ Library - <new>
- C++ Library - <numeric>
- C++ Library - <regex>
- C++ Library - <stdexcept>
- C++ Library - <string>
- C++ Library - <thread>
- C++ Library - <tuple>
- C++ Library - <typeinfo>
- C++ Library - <utility>
- C++ Library - <valarray>
- The C++ STL Library
- C++ Library - <array>
- C++ Library - <bitset>
- C++ Library - <deque>
- C++ Library - <forward_list>
- C++ Library - <list>
- C++ Library - <map>
- C++ Library - <multimap>
- C++ Library - <queue>
- C++ Library - <priority_queue>
- C++ Library - <set>
- C++ Library - <stack>
- C++ Library - <unordered_map>
- C++ Library - <unordered_set>
- C++ Library - <vector>
- C++ Library - <algorithm>
- C++ Library - <iterator>
- C++ Programming Resources
- C++ Programming Tutorial
- C++ Useful Resources
- C++ Discussion
C++ unordered_multimap::max_size() Function
The C++ std::unordered_multimap::max_size() function is used to return the maximum number of elements that can be held by unordered_multimap or container. This number depends on the system or library implementation.
If we try to use the max_size() function in the same program with different unordered_multimaps or empty unordered_multimaps, we get the same maximum size of the unordered_multimap container.
Syntax
Following is the syntax of std::unordered_multimap::max_size() function.
size_type max_size() const;
Parameters
This function does not accepts any parameter.
Return value
This function returns the maximum number of elements that can be held by unordered_multimap.
Example 1
In the following example, we are demonstrating the usage of the unordered_multimap::max_size()function.
#include <iostream> #include <unordered_map> using namespace std; int main(void) { unordered_multimap<char, int> umm; cout << "max_size of unordered_multimap = " << umm.max_size() << endl; return 0; }
Output
Let us compile and run the above program, this will produce the following result −
max_size of unordered_multimap = 576460752303423487
Example 2
Consider the following example, where we are going to use the max_size() function and getting the maximum size of the container before and after the insertion of elements into the empty multimap.
#include <iostream> #include <unordered_map> using namespace std; int main(void) { unordered_multimap<char, int> um; cout << "max_size of unordered_multimap = " << um.max_size() << endl; um.insert({{'A', 2}, {'B', 5}, {'C', 6}, {'D', 8}, {'D', 10}}); cout<<"*** Maximum size of unordered multimap after inserting the element to it ***"<<endl; cout << "max_size of unordered_multimap = " << um.max_size() << endl; return 0; }
Output
If we run the above code it will generate the following output −
max_size of unordered_multimap = 576460752303423487 *** Maximum size of unordered multimap after inserting the element to it *** max_size of unordered_multimap = 576460752303423487
Example 3
Let's look at the following example, where we are going to check whether the maximum size of the two multimaps with different elements are same or not.
#include <iostream> #include <unordered_map> using namespace std; int main(void) { unordered_multimap<int, int> ummap, umm; cout << "max_size of unordered_multimap = " << ummap.max_size() << endl; cout << "max_size of unordered_multimap = " << umm.max_size() << endl; ummap.insert({{1, 2}, {2, 5}, {3, 6}, {4, 10}}); umm.insert({{2, 2}, {3, 5}, {5, 6}, {6, 10}}); cout<<"*** Maximum size of unordered multimap after inserting the element to it ***"<<endl; cout << "max_size of unordered_multimap = " << ummap.max_size() << endl; cout << "max_size of unordered_multimap = " << umm.max_size() << endl; return 0; }
Output
Following is the output of the above code −
max_size of unordered_multimap = 576460752303423487 max_size of unordered_multimap = 576460752303423487 *** Maximum size of unordered multimap after inserting the element to it *** max_size of unordered_multimap = 576460752303423487 max_size of unordered_multimap = 576460752303423487
Example 4
Following is the example, where we are going to use the size() and max_size() functions to compare between normal size and max_size.
#include <iostream> #include <unordered_map> using namespace std; int main(void) { unordered_multimap<int, int> ummap = {{1, 10}, {1, 100}, {2, 20}, {2, 200}, {3, 30}}; cout<<"size of the ummap: "<<ummap.size()<<endl; cout<<"Maximum size of the ummap: "<<ummap.max_size(); return 0; }
Output
Output of the above code is as follows −
size of the ummap: 5 Maximum size of the ummap: 576460752303423487