![The C++ Standard Library](/cpp_standard_library/images/cpp-mini-lib-logo.jpg)
- The C Standard Library
- The C Standard Library
- The C++ Standard Library
- C++ Library - Home
- C++ Library - <fstream>
- C++ Library - <iomanip>
- C++ Library - <ios>
- C++ Library - <iosfwd>
- C++ Library - <iostream>
- C++ Library - <istream>
- C++ Library - <ostream>
- C++ Library - <sstream>
- C++ Library - <streambuf>
- C++ Library - <atomic>
- C++ Library - <complex>
- C++ Library - <exception>
- C++ Library - <functional>
- C++ Library - <limits>
- C++ Library - <locale>
- C++ Library - <memory>
- C++ Library - <new>
- C++ Library - <numeric>
- C++ Library - <regex>
- C++ Library - <stdexcept>
- C++ Library - <string>
- C++ Library - <thread>
- C++ Library - <tuple>
- C++ Library - <typeinfo>
- C++ Library - <utility>
- C++ Library - <valarray>
- The C++ STL Library
- C++ Library - <array>
- C++ Library - <bitset>
- C++ Library - <deque>
- C++ Library - <forward_list>
- C++ Library - <list>
- C++ Library - <map>
- C++ Library - <multimap>
- C++ Library - <queue>
- C++ Library - <priority_queue>
- C++ Library - <set>
- C++ Library - <stack>
- C++ Library - <unordered_map>
- C++ Library - <unordered_set>
- C++ Library - <vector>
- C++ Library - <algorithm>
- C++ Library - <iterator>
- C++ Programming Resources
- C++ Programming Tutorial
- C++ Useful Resources
- C++ Discussion
C++ unordered_multimap::key_eq() Function
The C++ std::unordered_multimap::key_eq() function is used to return the boolean value that depends on the key equivalence comparison predicate used by the container that compares keys for equality. It returns true if the equivalence occurs; otherwise, it returns false.
The key equivalence comparison is a predicate that takes two arguments of the key type and returns a bool value indicating whether they are to be considered equivalent. Default predicate is equal_to, which returns the same as applying the equal-to operator (==) to the arguments.
Syntax
Following is the syntax of std::unordered_multimap::key_eq() function.
key_equal key_eq() const;
Parameters
This function does not accept any parameter.
Return value
This function returns the key comparison function.
Example 1
In the following example, we are demonstrating the usage of the unordered_multimap::key_eq() function.
#include <iostream> #include <string> #include <unordered_map> using namespace std; int main () { unordered_multimap<string,string> umm; bool case_insensitive = umm.key_eq()("jerry","JERRY"); cout << "umm.key_eq() is "; cout << ( case_insensitive ? "case insensitive" : "case sensitive" ); cout << endl; return 0; }
Output
If we run the above code it will generate the following output −
umm.key_eq() is case sensitive
Example 2
Consider the following example, where we are going to use the key_eq() function and checking both keys of unordered_multimap is similar or not.
#include <iostream> #include <string> #include <unordered_map> using namespace std; int main () { unordered_multimap<string,string> umm; bool equal = umm.key_eq()("tutorialspoint","TUTORIALSPOAINT"); if(equal){ cout<<"both are similar\n"; } else{ cout<<"dissimilar\n"; } return 0; }
Output
Following is the output of the above code −
dissimilar
Example 3
Let's look at the following example, where we are going to use multimap that accepts integer values and apply the key_eq() function to check both key or similar or not.
#include <iostream> #include <string> #include <unordered_map> using namespace std; int main () { unordered_multimap<int,int> umm; bool equal = umm.key_eq()(105, 105); if(equal) cout<<"similar\n"; else cout<<"dissimilar"; return 0; }
Output
Output of the above code is as follows −
similar