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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。