
- 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
multimap empty() function in C++ STL
In this article, we will be discussing the working, syntax, and examples of multimap::empty() 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::empty()?
multimap::empty() function is an inbuilt function in C++ STL, which is defined in <map>header file. empty() is used to check whether the associated multimap container is empty or not.
This function checks if the size of the container is 0 then returns true, else if there are some values then it returns false.
Syntax
map_name.empty();
Parameters
The function accepts no parameter.
Return value
This function returns true if the map is empty and false if it is not.
Input
multimap<char, int > newmap; newmap.insert(make_pair(‘A’, 10)); newmap.insert(make_pair(‘B’, 20)); newmap.insert(make_pair(‘C’, 30)); mymap.empty();
Output
false
Input
std::multimap<int> mymap; mymap.empty();
Output
true
Example
#include<iostream> #include<map> using namespace std; int main(){ multimap<int,int > mul_1; //inserting elements to multimap1 mul_1.insert({1,10}); mul_1.insert({2,20}); mul_1.insert({3,30}); mul_1.insert({4,40}); mul_1.insert({5,50}); if(mul_1.empty()){ cout<<"\nMultimap is empty"; } else{ cout<<"\nMultimap is not empty"; cout<<"\nElements in multimap1 are: "<<"\n"; for(auto i= mul_1.begin(); i!= mul_1.end(); i++){ cout<<(*i).first<<" "<< (*i).second << "\n"; } } }
Output
If we run the above code it will generate the following output −
Multimap is not empty Elements in multimap1 are: 1 10 2 20 3 30 4 40 5 50
- Related Articles
- multimap value_comp() function in C++ STL
- multimap upper_bound() function in C++ STL
- multimap swap() function in C++ STL
- multimap size() function in C++ STL
- multimap lower_bound() function in C++ STL
- multimap get_allocator() function in C++ STL
- multimap clear() function in C++ STL
- multiset empty() function in C++ STL
- list empty() function in C++ STL
- multimap::begin() and multimap::end() in C++ STL
- multimap::crbegin() and multimap::crend() in C++ STL
- multimap::cbegin() and multimap::cend() in C++ STL
- multimap::swap() in C++ STL
- multimap::operator= in C++ STL
- multimap::erase() in C++ STL
