Javatpoint Logo
Javatpoint Logo

C++ map max_size() Function

C++ map max_size() function is used to get the maximum size a map container can hold.

Syntax

Member type size_type is an unsigned integral type.

Parameter

None

Return value

It returns the maximum allowed length of the map container.

Example 1

Let's see a simple example to calculate the maximum size of the map.

Output:

Maximum size of a 'map' is 461168601842738790

In the above example, max_size() function returns the maximum size of the map.

Example 2

Let's see a simple example.

Output:

The map contains 1000 elements.

In the above example, member max_size is used to check beforehand whether the map will allow for 1000 elements to be inserted.

Example 3

Let's see a simple example to find the max size of an empty map and a non-empty map.

Output:

The max size of mp1 is 461168601842738790
The max size of mp2 is 461168601842738790

In the above example, there are two maps i.e. m1 and m2. m1 is a non-empty map and m2 is an empty map. But the maximum size of both maps is the same.

Example 4

Let's see a simple example.

Output:

Enter the number of fmly members : 3
Enter the name and age of each member: 
Ram 42
Sita 37
Laxman 40

Total number of population of city map: 384307168202282325
Total memnber of fmly is:3
Details of fmly members: 

Name    |  Age 
__________________________
Laxman | 40 
Ram      | 42 
Sita       | 37

In the above example, the program first creates city map interactively with given number of size. Then, it displays the total size a city map can contain, total size of a fmly and all the names and their age available in the map.

Next TopicC++ Map



Please Share

facebook twitter google plus pinterest