map::empty() in C++ STL Last Updated : 17 Jan, 2018 Comments Improve Suggest changes 11 Likes Like Report Maps are associative containers that store elements in a mapped fashion. Each element has a key value and a mapped value. No two mapped values can have same key values. map::empty() empty() function is used to check if the map container is empty or not. Syntax : mapname.empty() Parameters : No parameters are passed. Returns : True, if map is empty False, Otherwise Examples: Input : map mymap['a']=10; mymap['b']=20; mymap.empty(); Output : False Input : map mymap.empty(); Output : True Errors and Exceptions 1. It has a no exception throw guarantee. 2. Shows error when a parameter is passed. CPP // Non Empty map example // CPP program to illustrate // Implementation of empty() function #include <iostream> #include <map> using namespace std; int main() { map<char, int> mymap; mymap['a'] = 1; mymap['b'] = 2; if (mymap.empty()) { cout << "True"; } else { cout << "False"; } return 0; } Output: False CPP // Empty map example // CPP program to illustrate // Implementation of empty() function #include <iostream> #include <map> using namespace std; int main() { map<char, int> mymap; if (mymap.empty()) { cout << "True"; } else { cout << "False"; } return 0; } Output: True Time Complexity : O(1) Create Quiz Comment A AyushSaxena Follow 11 Improve A AyushSaxena Follow 11 Improve Article Tags : Misc C++ STL cpp-map Explore C++ BasicsIntroduction to C++3 min readData Types in C++6 min readVariables in C++4 min readOperators in C++9 min readBasic Input / Output in C++3 min readControl flow statements in Programming15+ min readLoops in C++7 min readFunctions in C++8 min readArrays in C++8 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++12 min readFile Handling in C++8 min readMultithreading in C++8 min readNamespace in C++5 min readOOP in C++Object Oriented Programming in C++8 min readInheritance in C++6 min readPolymorphism in C++5 min readEncapsulation in C++3 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL2 min readIterators in C++ STL10 min readC++ STL Algorithm Library3 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read Like