GeezerVison is showing cpprefjp.github.io — std::operator!= - cpprefjp C++日本語リファレンス
最終更新日時:
2026年09月11日 13時06分31秒 (JST)
Akira Takahashi
が更新
履歴
編集
function template
<unordered_set>
std:: operator!= (C++11)
namespace std {
// operator==により、以下の演算子が使用可能になる (C++20)
template < class Key , class Hash , class Pred , class Allocator >
bool operator != ( const unordered_multiset < Key , Hash , Pred , Allocator >& a ,
const unordered_multiset < Key , Hash , Pred , Allocator >& b ); // (1) C++11
template < class Key , class Hash , class Pred , class Allocator >
constexpr bool operator != ( const unordered_multiset < Key , Hash , Pred , Allocator >& a ,
const unordered_multiset < Key , Hash , Pred , Allocator >& b ); // (1) C++26
}
概要
unordered_multiset オブジェクトを非等値比較する。
要件
a.key_eq () と b.key_eq () は同じふるまいをすること。
key_type の等値比較演算子(operator==)で等値と判定された 2 つのオブジェクトは、key_eq () でも等値と判定されること。
戻り値
以下と等価:
計算量
Ei を a の i 番目の同値キーのグループの大きさ、n = a.size ()であるとして、
備考
本関数は、コンテナ内の要素の比較に key_eq () で返されるキー比較用関数オブジェクトを使用しないことに注意。
本関数は、標準コンテナの要件を満たさない。これは、標準コンテナの要件が iterator と std::equal を用いて定義されているためである。しかし、本関数の戻り値は、!(a == b) という意味においては、標準コンテナと同様とも考えることができる。
例
#include <iostream>
#include <string>
#include <unordered_set>
#include <iterator>
#include <algorithm>
template < class C >
void print ( const std::string & label , const C & c , std::ostream & os = std::cout )
{
os << label << ":" ;
std::copy ( std::begin ( c ), std::end ( c ), std::ostream_iterator < typename C :: value_type > ( os , ", " ));
os << std::endl ;
}
int main ()
{
std::cout << std::boolalpha ;
std :: unordered_multiset < int > ums1 { 1 , 2 , 3 , 1 , 2 , 3 , };
std :: unordered_multiset < int > ums2 { 4 , 5 , 6 , 4 , 5 , 6 , };
std :: unordered_multiset < int > ums3 { 1 , 2 , 3 , 1 , 2 , 3 , };
:: print ( "ums1" , ums1 );
:: print ( "ums2" , ums2 );
:: print ( "ums3" , ums3 );
std::cout << "ums1 != ums2:" << ( ums1 != ums2 ) << std::endl ;
std::cout << "ums1 != ums3:" << ( ums1 != ums3 ) << std::endl ;
}
出力例
ums1:3, 3, 2, 2, 1, 1,
ums2:6, 6, 5, 5, 4, 4,
ums3:3, 3, 2, 2, 1, 1,
ums1 != ums2:true
ums1 != ums3:false
注:unordered_multiset は非順序連想コンテナであるため、出力順序は無意味であることに注意
バージョン
言語
処理系
実装例
namespace std {
template < class Key , class Hash , class Pred , class Allocator >
bool operator != ( const unordered_multiset < Key , Hash , Pred , Allocator >& a ,
const unordered_multiset < Key , Hash , Pred , Allocator >& b )
{
return ! ( a == b );
}
}
関連項目
参照