unordered_set key_eq()是C++ STL中的内置函数,该函数根据比较结果返回布尔值。它返回unordered_set使用的 key 等效比较谓词。键等价比较是一个谓词,该谓词接受两个参数并返回一个bool值,指示它们是否相等。
用法:
key_equal key_eq() const
返回值:此方法返回键相等性比较对象。
时间复杂度:O(1)
范例1:
#include <iostream>
#include <string>
#include <unordered_set>
using namespace std;
int main()
{
// unordered_set ms is created
unordered_set<string> ms;
bool res = ms.key_eq()("a", "A");
cout << "ms.key_eq() is ";
if (res == 1) {
cout << "case insensitive";
}
else {
// res is 0 as arguments are not equivalent
cout << "case sensitive";
}
cout << "\n";
return 0;
}
输出:
ms.key_eq() is case sensitive
范例2:
#include <iostream>
#include <string>
#include <unordered_set>
using namespace std;
int main()
{
// unordered_set mp is created
unordered_set<string> mp;
// the 2 strings are compared
bool
r
= mp.key_eq()(
"1000 is a huge number",
"2000 is a huge number");
cout << "strings are ";
if (r == 1) {
cout << "same";
}
else {
// the strings are not same so r=0
cout << "not same";
}
cout << "\n";
return 0;
}
输出:
strings are not same
相关用法
- p5.js arc()用法及代码示例
- C++ div()用法及代码示例
- C++ fma()用法及代码示例
- C++ log()用法及代码示例
- PHP image_type_to_mime_type()用法及代码示例
- C++ map key_comp()用法及代码示例
- PHP image_type_to_extension()用法及代码示例
注:本文由纯净天空筛选整理自lakshita大神的英文原创作品 unordered_set key_eq() function in C++ STL。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。