unordered_map::empty()函数用于检查容器大小是否为零。如果容器大小为零,则返回TRUE,否则返回FALSE。
用法:
unordered_map_name.empty()
参数:该函数不接受任何参数
返回类型:此函数返回布尔值TRUE或FALSE。
Examples:
Input: ump = { {1, 2}, {3, 4}, {5, 6}, {7, 8}}
ump.empty();
Output: FalseInput: ump = { };
ump.empty();
Output: True
// CPP program to illustrate
// Implementation of unordered_map empty() function
#include <bits/stdc++.h>
using namespace std;
int main()
{
// Take any two unordered_map
unordered_map<int, int> ump1, ump2;
// Inserting values
ump1[1] = 2;
ump1[3] = 4;
ump1[5] = 6;
ump1[7] = 8;
// Print the size of container
cout << "ump1 size = " << ump1.size() << endl;
cout << "ump2 size = " << ump2.size() << endl;
// Running the function for ump1
if (ump1.empty())
cout << "True\n";
else
cout << "False\n";
// Running the function for ump2
if (ump2.empty())
cout << "True\n";
else
cout << "False\n";
// Running the function for ump1 after
// clearing it
ump1.clear();
if (ump1.empty())
cout << "True\n";
else
cout << "False\n";
return 0;
}
输出:
ump1 size = 4 ump2 size = 0 False True True
相关用法
- C++ set::empty()用法及代码示例
- C++ map::empty()用法及代码示例
- C++ match_results empty()用法及代码示例
- C++ array::empty()用法及代码示例
- C++ unordered_set empty()用法及代码示例
- C++ unordered_multimap empty()用法及代码示例
- C++ multiset empty()用法及代码示例
- C++ list empty()用法及代码示例
- C++ unordered_multiset empty()用法及代码示例
- C++ multimap empty()用法及代码示例
注:本文由纯净天空筛选整理自ankit15697大神的英文原创作品 unordered_map empty in C++ STL。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。