Javatpoint Logo
Javatpoint Logo

C++ multiset empty()

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

Syntax

Parameter

None

Return value

The empty() function returns true if the multiset container is empty (size is 0) otherwise, it returns false.

Complexity

Constant.

Iterator validity

No changes.

Data Races

The container is accessed.

Concurrently accessing the elements of multiset is safe.

Exception Safety

This function never throws exception.

Example 1

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

Output:

 Initially, numbers.empty(): 1

 After adding elements, numbers.empty(): 0

In the above example, initially size of multiset 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 multiset is empty or not:

Output:

Multiset is empty
Multiset is not empty

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

Example 3

Le's see a simple example:

Output:

100
200
300
400

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

Example 4

Let's see a simple example:

Output:

Multiset is empty. Please insert content! 
 
Enter three sets of number: 
10002
10002
10003

List of telephone numbers: 
10002 
10002 
10003 

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

Next TopicC++ multiset




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials