
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
multiset empty() function in C++ STL
In this article we will be discussing the working, syntax and examples of multiset::empty() function in C++ STL.
What is a multiset in C++ STL?
Multisets are the containers similar to the set container, meaning they store the values in the form of keys same as a set, in a specific order.
In multiset the values are identified as keys as same as sets. The main difference between multiset and set is that the set has distinct keys, meaning no two keys are the same, in multiset there can be the same keys value.
Multiset keys are used to implement binary search trees.
What is multiset::empty()?
multiset::empty() function is an inbuilt function in C++ STL, which is defined in <set> header file.
This function checks if the associated multiset container is empty or not.
empty() checks the associated container size is 0 then will be true, else if any elements are present in the container or the size of the container is not 0 then the function will return false.
Syntax
ms_name.empty();
Parameters
The function accepts no parameter.
Return value
This function Boolean value true, if the container is empty else false.
Example
Input: std::multiset<int> mymultiset = {1, 2, 2, 3, 4}; mymultiset.empty(); Output: false Input: std::multiset<int> mymultiset; mymultiset.empty(); Output: true
Example
#include <bits/stdc++.h> using namespace std; int main() { int arr[] = {2, 3, 4, 5}; multiset<int> check(arr, arr + 4); if (check.empty()) cout <<"The multiset is empty"; else cout << "The multiset isn't empty"; return 0; }
Output
If we run the above code it will generate the following output −
The multiset isn't empty
Example
#include <bits/stdc++.h> using namespace std; int main() { int arr[] = {}; multiset<int> check(arr, arr + 0); if (check.empty()) cout <<"The multiset is empty"; else cout << "The multiset isn't empty"; return 0; }
Output
If we run the above code it will generate the following output −
The multiset is empty
- Related Articles
- multiset insert() function in C++ STL
- multiset clear() function in C++ STL
- multiset count() function in C++ STL
- Multiset emplace_hint() function in C++ STL
- multiset equal_range() function in C++ STL
- multiset begin() and end() function in C++ STL
- multiset cbegin() and cend() function in C++ STL
- multiset crbegin() and crend() function in C++ STL
- list empty() function in C++ STL
- multimap empty() function in C++ STL
- C++ Program to Implement Multiset in STL
- multiset size() in C++ STL with Examples
- multiset max_size() in C++ STL with Examples
- multiset upper_bound() in C++ STL with Examples
- multiset lower_bound() in C++ STL with Examples
