當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


C++ unordered_multiset key_eq()用法及代碼示例


unordered_multiset::key_eq()是C++ STL中的內置函數,該函數根據比較結果返回布爾值。它取決於unordered_multiset容器使用的鍵等效項比較謂詞。 key 等效項比較是一個謂詞,該謂詞接受兩個參數並返回一個布爾值,該布爾值指示是否將它們視為等效。如果它們相等則返回true,否則返回false。它在構造時由容器采用,類似於比較中使用的(==)運算符。

用法

unordered_multiset_name.key_eq()(args1, args2)

參數:該函數接受兩個必需參數args1和args2,在這兩個參數之間進行比較。 data_type與unordered_multiset相同。


返回值:該函數返回一個布爾值。

以下示例程序旨在說明unordered_multiset::key_eq()函數:

程序1

// CPP program to illustrate the 
// unordered_multiset::key_eq() function 
  
#include <iostream> 
#include <string> 
#include <unordered_set> 
  
using namespace std; 
  
int main() 
{ 
  
    unordered_multiset<string> 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 <iostream> 
#include <string> 
#include <unordered_set> 
  
using namespace std; 
  
int main() 
{ 
  
    unordered_multiset<int> 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


相關用法


注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 unordered_multiset key_eq() function in C++ STL。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。