📜  C++ STL中的unordered_multiset key_eq()函数

📅  最后修改于: 2021-05-30 18:06:01             🧑  作者: Mango

unordered_multiset :: key_eq()是C++ STL中的内置函数,该函数根据比较结果返回布尔值。它取决于unordered_multiset容器使用的键等效项比较谓词。密钥等效项比较是一个谓词,该谓词接受两个参数并返回一个布尔值,该布尔值指示它们是否被视为等效。如果它们相等则返回true,否则返回false。它在构造时由容器采用,类似于比较中使用的(==)运算符。

语法

unordered_multiset_name.key_eq()(args1, args2)

参数:该函数接受两个强制性参数args1args2 ,在这两个参数之间进行比较。 data_type与unordered_multiset的相同。

返回值:该函数返回一个布尔值。

下面的程序说明了unordered_multiset :: key_eq()函数:

程序1

// CPP program to illustrate the
// unordered_multiset::key_eq() function
  
#include 
#include 
#include 
  
using namespace std;
  
int main()
{
  
    unordered_multiset sampleSet;
  
    bool answer = sampleSet.key_eq()("GEEKS", "geeks");
  
    // checks if both are same
    if (answer)
        cout << "GEEKS and geeks are treated similarly in the container\n";
    else
        cout << "GEEKS and geeks are treated dissimilarly in the container\n";
  
    return 0;
}
输出:
GEEKS and geeks are treated dissimilarly in the container

程序2

// CPP program to illustrate the
// unordered_multiset::key_eq() function
  
#include 
#include 
#include 
  
using namespace std;
  
int main()
{
  
    unordered_multiset sampleSet;
  
    bool answer = sampleSet.key_eq()(100, 200);
  
    // check
    if (answer)
        cout << "100 and 200 are treated similarly in the container\n";
    else
        cout << "100 and 200 are treated dissimilarly in the container\n";
  
    answer = sampleSet.key_eq()(100, 100);
    if (answer)
        cout << "100 and 100 are treated similarly in the container\n";
    else
        cout << "100 and 100 are treated dissimilarly in the container\n";
  
    return 0;
}
输出:
100 and 200 are treated dissimilarly in the container
100 and 100 are treated similarly in the container
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程”