101 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// <unordered_set>10 11// template <class Key, class Hash, class Pred, class Alloc>12// bool13// operator==(const unordered_set<Key, Hash, Pred, Alloc>& x,14// const unordered_set<Key, Hash, Pred, Alloc>& y);15//16// template <class Key, class Hash, class Pred, class Alloc>17// bool18// operator!=(const unordered_set<Key, Hash, Pred, Alloc>& x,19// const unordered_set<Key, Hash, Pred, Alloc>& y);20 21#include <unordered_set>22#include <cassert>23 24#include "test_macros.h"25#include "min_allocator.h"26 27int main(int, char**) {28 {29 typedef std::unordered_set<int> C;30 typedef int P;31 P a[] = {P(10), P(20), P(30), P(40), P(50), P(60), P(70), P(80)};32 const C c1(std::begin(a), std::end(a));33 const C c2;34 assert(!(c1 == c2));35 assert((c1 != c2));36 }37 {38 typedef std::unordered_set<int> C;39 typedef int P;40 P a[] = {P(10), P(20), P(30), P(40), P(50), P(60), P(70), P(80)};41 const C c1(std::begin(a), std::end(a));42 const C c2 = c1;43 assert((c1 == c2));44 assert(!(c1 != c2));45 }46 {47 typedef std::unordered_set<int> C;48 typedef int P;49 P a[] = {P(10), P(20), P(30), P(40), P(50), P(60), P(70), P(80)};50 C c1(std::begin(a), std::end(a));51 C c2 = c1;52 c2.rehash(30);53 assert((c1 == c2));54 assert(!(c1 != c2));55 c2.insert(P(90));56 assert(!(c1 == c2));57 assert((c1 != c2));58 c1.insert(P(90));59 assert((c1 == c2));60 assert(!(c1 != c2));61 }62#if TEST_STD_VER >= 1163 {64 typedef std::unordered_set<int, std::hash<int>, std::equal_to<int>, min_allocator<int>> C;65 typedef int P;66 P a[] = {P(10), P(20), P(30), P(40), P(50), P(60), P(70), P(80)};67 const C c1(std::begin(a), std::end(a));68 const C c2;69 assert(!(c1 == c2));70 assert((c1 != c2));71 }72 {73 typedef std::unordered_set<int, std::hash<int>, std::equal_to<int>, min_allocator<int>> C;74 typedef int P;75 P a[] = {P(10), P(20), P(30), P(40), P(50), P(60), P(70), P(80)};76 const C c1(std::begin(a), std::end(a));77 const C c2 = c1;78 assert((c1 == c2));79 assert(!(c1 != c2));80 }81 {82 typedef std::unordered_set<int, std::hash<int>, std::equal_to<int>, min_allocator<int>> C;83 typedef int P;84 P a[] = {P(10), P(20), P(30), P(40), P(50), P(60), P(70), P(80)};85 C c1(std::begin(a), std::end(a));86 C c2 = c1;87 c2.rehash(30);88 assert((c1 == c2));89 assert(!(c1 != c2));90 c2.insert(P(90));91 assert(!(c1 == c2));92 assert((c1 != c2));93 c1.insert(P(90));94 assert((c1 == c2));95 assert(!(c1 != c2));96 }97#endif98 99 return 0;100}101