Javatpoint Logo
Javatpoint Logo

C++ multimap empty() function

The C++ multimap empty() function is used to check whether the multimap container is empty or not. It returns true if the multimap container is empty (size is 0) otherwise, it returns false.

Syntax

Parameter

None

Return value

It returns true if the multimap container is empty (size is 0) otherwise, it returns false.

Complexity

Constant.

Iterator Validity

No changes.

Data races

The container is accessed.

Exception safety

This function never throws exception.

Example 1

Let's see the simple example to check if a multimap contains any element or not:

Output:

 Initially, numbers.empty(): 1

 After adding elements, numbers.empty(): 0

In the above example, initially size of multimap is 0 hence, empty() function returns 1(true) and after adding elements it returns 0(false).

Example 2

Let's see a simple example to check whether multimap is empty or not:

Output:

Multimap is empty
Multimap is not empty

In the above example, if condition statement is used. If multimap is empty, it will return multimap is empty, and after adding elements it will return multimap is not empty.

Example 3

Let's see a simple example:

Output:

a => 200
a => 100
b => 100

In the above example, It simply use the empty() function in while loop and prints the elements of multimap until the multimap is not empty.

Example 4

Let's see a simple example:

Output:

Multimap is empty. Please insert content! 
 
Enter three sets of name and number: 
Nikita 1111
Divya  3333
Amita  4444

List of telephone numbers: 
Amita 4444 
Divya 3333 
Nikita 1111

In the above example, the program first creates phone multimap interactively with three names. Then it checks the multimap is empty or not. If multimap is empty then it displays a message otherwise, it displays all the names and their telephone numbers available in the multimap.

Next TopicC++ multimap




Please Share

facebook twitter google plus pinterest