<unordered_set>
運算子
operator!=
測試運算子左邊的 unordered_set 物件是否不等於右邊的 unordered_set 物件。
bool operator!=(const unordered_set <Key, Hash, Pred, Allocator>& left, const unordered_set <Key, Hash, Pred, Allocator>& right);
參數
left
unordered_set
類型的物件。
right
unordered_set
類型的物件。
傳回值
如果 unordered_set 不相等為 true
;如果相等則為 false
。
備註
unordered_set 物件之間的比較不會受到其儲存元素的任何順序影響。 如果兩個 unordered_set 的元素數量相同,且一個容器中的元素是另一個容器中元素的排列,則兩個 unordered_set 相等。 反之則為不相等。
範例
// unordered_set_ne.cpp
// compile by using: cl.exe /EHsc /nologo /W4 /MTd
#include <unordered_set>
#include <iostream>
#include <ios>
int main()
{
using namespace std;
unordered_set<char> c1, c2, c3;
c1.insert('a');
c1.insert('b');
c1.insert('c');
c2.insert('c');
c2.insert('a');
c2.insert('d');
c3.insert('c');
c3.insert('a');
c3.insert('b');
cout << boolalpha;
cout << "c1 != c2: " << (c1 != c2) << endl;
cout << "c1 != c3: " << (c1 != c3) << endl;
cout << "c2 != c3: " << (c2 != c3) << endl;
return (0);
}
輸出:
c1 != c2: true
c1 != c3: false
c2 != c3: true
operator==
測試運算子左邊的 unordered_set 物件是否等於右邊的 unordered_set 物件。
bool operator==(const unordered_set <Key, Hash, Pred, Allocator>& left, const unordered_set <Key, Hash, Pred, Allocator>& right);
參數
left
unordered_set
類型的物件。
right
unordered_set
類型的物件。
傳回值
如果 unordered_set 相等為 true
;如果不相等則為 false
。
備註
unordered_set 物件之間的比較不會受到其儲存元素的任何順序影響。 如果兩個 unordered_set 的元素數量相同,且一個容器中的元素是另一個容器中元素的排列,則兩個 unordered_set 相等。 反之則為不相等。
範例
// unordered_set_eq.cpp
// compile by using: cl.exe /EHsc /nologo /W4 /MTd
#include <unordered_set>
#include <iostream>
#include <ios>
int main()
{
using namespace std;
unordered_set<char> c1, c2, c3;
c1.insert('a');
c1.insert('b');
c1.insert('c');
c2.insert('c');
c2.insert('a');
c2.insert('d');
c3.insert('c');
c3.insert('a');
c3.insert('b');
cout << boolalpha;
cout << "c1 == c2: " << (c1 == c2) << endl;
cout << "c1 == c3: " << (c1 == c3) << endl;
cout << "c2 == c3: " << (c2 == c3) << endl;
return (0);
}
c1 == c2: false
c1 == c3: true
c2 == c3: false
operator!= (multiset)
測試運算子左邊的 unordered_multiset 物件是否不等於右邊的 unordered_multiset 物件。
bool operator!=(const unordered_multiset <Key, Hash, Pred, Allocator>& left, const unordered_multiset <Key, Hash, Pred, Allocator>& right);
參數
left
unordered_multiset
類型的物件。
right
unordered_multiset
類型的物件。
傳回值
如果 unordered_multiset 不相等為 true
;如果相等則為 false
。
備註
unordered_multiset 物件之間的比較不會受到其儲存元素的任何順序影響。 如果兩個 unordered_multiset 的元素數量相同,且一個容器中的元素是另一個容器中元素的排列,則兩個 unordered_multiset 相等。 反之則為不相等。
範例
// unordered_multiset_ne.cpp
// compile by using: cl.exe /EHsc /nologo /W4 /MTd
#include <unordered_set>
#include <iostream>
#include <ios>
int main()
{
using namespace std;
unordered_multiset<char> c1, c2, c3;
c1.insert('a');
c1.insert('b');
c1.insert('c');
c1.insert('c');
c2.insert('c');
c2.insert('c');
c2.insert('a');
c2.insert('d');
c3.insert('c');
c3.insert('c');
c3.insert('a');
c3.insert('b');
cout << boolalpha;
cout << "c1 != c2: " << (c1 != c2) << endl;
cout << "c1 != c3: " << (c1 != c3) << endl;
cout << "c2 != c3: " << (c2 != c3) << endl;
return (0);
}
c1 != c2: true
c1 != c3: false
c2 != c3: true
operator== (multiset)
測試運算子左邊的 unordered_multiset 物件是否等於右邊的 unordered_multiset 物件。
bool operator==(const unordered_multiset <Key, Hash, Pred, Allocator>& left, const unordered_multiset <Key, Hash, Pred, Allocator>& right);
參數
left
unordered_multiset
類型的物件。
right
unordered_multiset
類型的物件。
傳回值
如果 unordered_multiset 相等為 true
;如果不相等則為 false
。
備註
unordered_multiset 物件之間的比較不會受到其儲存元素的任何順序影響。 如果兩個 unordered_multiset 的元素數量相同,且一個容器中的元素是另一個容器中元素的排列,則兩個 unordered_multiset 相等。 反之則為不相等。
範例
// unordered_multiset_eq.cpp
// compile by using: cl.exe /EHsc /nologo /W4 /MTd
#include <unordered_set>
#include <iostream>
#include <ios>
int main()
{
using namespace std;
unordered_multiset<char> c1, c2, c3;
c1.insert('a');
c1.insert('b');
c1.insert('c');
c1.insert('c');
c2.insert('c');
c2.insert('c');
c2.insert('a');
c2.insert('d');
c3.insert('c');
c3.insert('c');
c3.insert('a');
c3.insert('b');
cout << boolalpha;
cout << "c1 == c2: " << (c1 == c2) << endl;
cout << "c1 == c3: " << (c1 == c3) << endl;
cout << "c2 == c3: " << (c2 == c3) << endl;
return (0);
}
c1 == c2: false
c1 == c3: true
c2 == c3: false