Last Updated : 26 Oct, 2018
The
unordered_set key_eq()is a built-in function in
C++ STLwhich returns a boolean value according to the comparison. It returns the key equivalence comparison predicate used by the unordered_set. The key equivalence comparison is a predicate that takes two arguments and returns a bool value indicating whether they are equal.
Syntax:key_equal key_eq() constReturn Value:
This method returns the key equality comparison object.
Time Complexity:O(1)
Example 1: CPP
#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;
}
Output:
ms.key_eq() is case sensitiveExample 2: CPP
#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;
}
Output:
strings are not same
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4