multimap maxsize() in C++ STL

C++Server Side ProgrammingProgramming

In this article we will be discussing the working, syntax, and examples of multimap::max_size() function in C++ STL.

What is Multimap in C++ STL?

Multimaps are the associative containers, which are similar to map containers. It also facilitates to store the elements formed by a combination of key-value and mapped value in a specific order. In a multimap container, there can be multiple elements associated with the same key. The data is internally always sorted with the help of its associated keys.

What is multimap::max_size?

multimap::max_size() function is an inbuilt function in C++ STL, which is defined in <map> header file. max_size() is used to return the maximum size of the multimap container.

This function is used to check the maximum number of values that an associated multimap container can hold. The size is like the potential of the container, hence there is no guarantee that it can reach that value or not.

Syntax

multiMap_name.max_size();

Parameter

This function accepts no parameter.

Return value

This function returns the number of elements a container can hold.

Input

multimap newmap;
newmap.max_size();

Output 

Max size of multimap is − 461168601842738790

Example

 Live Demo

#include <bits/stdc++.h>
using namespace std;
int main(){
   //creating multimap
   multimap<int, int> mul;
   multimap<char,char> char_mul;
   multimap<float, float> float_mul;
   cout<<"Max size of multimap is "<<mul.max_size();
   cout<<"\nMax size of multimap is "<<char_mul.max_size();
   cout<<"\nMax size of multimap is "<<float_mul.max_size();
   return 0;
}

Output

If we run the above code it will generate the following output −

Max size of multimap is 461168601842738790
Max size of multimap is 461168601842738790
Max size of multimap is 461168601842738790
raja
Published on 22-Apr-2020 11:36:29
Advertisements