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-exception
6//
7//===----------------------------------------------------------------------===//
8
9// <unordered_map>
10
11// template <class Key, class T, class Hash, class Pred, class Alloc>
12// bool
13// operator==(const unordered_map<Key, T, Hash, Pred, Alloc>& x,
14// const unordered_map<Key, T, Hash, Pred, Alloc>& y);
15//
16// template <class Key, class T, class Hash, class Pred, class Alloc>
17// bool
18// operator!=(const unordered_map<Key, T, Hash, Pred, Alloc>& x,
19// const unordered_map<Key, T, Hash, Pred, Alloc>& y);
20
21#include <unordered_map>
22#include <string>
23#include <cassert>
24#include <iterator>
25
26#include "test_macros.h"
27#include "min_allocator.h"
28
29#include "test_comparisons.h"
30
31int main(int, char**)
32{
33 {
34 typedef std::unordered_map<int, std::string> C;
35 typedef std::pair<int, std::string> P;
36 P a[] =
37 {
38 P(10, "ten"),
39 P(20, "twenty"),
40 P(30, "thirty"),
41 P(40, "forty"),
42 P(50, "fifty"),
43 P(60, "sixty"),
44 P(70, "seventy"),
45 P(80, "eighty"),
46 };
47 const C c1(std::begin(arr&: a), std::end(arr&: a));
48 const C c2;
49 assert(testEquality(c1, c2, false));
50 }
51 {
52 typedef std::unordered_map<int, std::string> C;
53 typedef std::pair<int, std::string> P;
54 P a[] =
55 {
56 P(10, "ten"),
57 P(20, "twenty"),
58 P(30, "thirty"),
59 P(40, "forty"),
60 P(50, "fifty"),
61 P(60, "sixty"),
62 P(70, "seventy"),
63 P(80, "eighty"),
64 };
65 const C c1(std::begin(arr&: a), std::end(arr&: a));
66 const C c2 = c1;
67 assert(testEquality(c1, c2, true));
68 }
69 {
70 typedef std::unordered_map<int, std::string> C;
71 typedef std::pair<int, std::string> P;
72 P a[] =
73 {
74 P(10, "ten"),
75 P(20, "twenty"),
76 P(30, "thirty"),
77 P(40, "forty"),
78 P(50, "fifty"),
79 P(60, "sixty"),
80 P(70, "seventy"),
81 P(80, "eighty"),
82 };
83 C c1(std::begin(arr&: a), std::end(arr&: a));
84 C c2 = c1;
85 c2.rehash(n: 30);
86 assert(testEquality(c1, c2, true));
87 c2.insert(x: P(90, "ninety"));
88 assert(testEquality(c1, c2, false));
89 c1.insert(x: P(90, "ninety"));
90 assert(testEquality(c1, c2, true));
91 }
92 {
93 typedef std::unordered_map<int, std::string> C;
94 typedef std::pair<int, std::string> P;
95 P a[] =
96 {
97 P(10, "ten"),
98 P(20, "twenty"),
99 P(30, "thirty"),
100 P(40, "forty"),
101 P(50, "fifty"),
102 P(60, "sixty"),
103 P(70, "seventy"),
104 P(80, "eighty"),
105 };
106 C c1(std::begin(arr&: a), std::end(arr&: a));
107 C c2 = c1;
108 assert(testEquality(c1, c2, true));
109 c1.insert(x: P(90, "ninety"));
110 c2.insert(x: P(100, "onehundred"));
111 assert(testEquality(c1, c2, false));
112 }
113#if TEST_STD_VER >= 11
114 {
115 typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>,
116 min_allocator<std::pair<const int, std::string>>> C;
117 typedef std::pair<int, std::string> P;
118 P a[] =
119 {
120 P(10, "ten"),
121 P(20, "twenty"),
122 P(30, "thirty"),
123 P(40, "forty"),
124 P(50, "fifty"),
125 P(60, "sixty"),
126 P(70, "seventy"),
127 P(80, "eighty"),
128 };
129 const C c1(std::begin(a), std::end(a));
130 const C c2;
131 assert(testEquality(c1, c2, false));
132 }
133 {
134 typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>,
135 min_allocator<std::pair<const int, std::string>>> C;
136 typedef std::pair<int, std::string> P;
137 P a[] =
138 {
139 P(10, "ten"),
140 P(20, "twenty"),
141 P(30, "thirty"),
142 P(40, "forty"),
143 P(50, "fifty"),
144 P(60, "sixty"),
145 P(70, "seventy"),
146 P(80, "eighty"),
147 };
148 const C c1(std::begin(a), std::end(a));
149 const C c2 = c1;
150 assert(testEquality(c1, c2, true));
151 }
152 {
153 typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>,
154 min_allocator<std::pair<const int, std::string>>> C;
155 typedef std::pair<int, std::string> P;
156 P a[] =
157 {
158 P(10, "ten"),
159 P(20, "twenty"),
160 P(30, "thirty"),
161 P(40, "forty"),
162 P(50, "fifty"),
163 P(60, "sixty"),
164 P(70, "seventy"),
165 P(80, "eighty"),
166 };
167 C c1(std::begin(a), std::end(a));
168 C c2 = c1;
169 c2.rehash(30);
170 assert(testEquality(c1, c2, true));
171 c2.insert(P(90, "ninety"));
172 assert(testEquality(c1, c2, false));
173 c1.insert(P(90, "ninety"));
174 assert(testEquality(c1, c2, true));
175 }
176 {
177 typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>,
178 min_allocator<std::pair<const int, std::string>>> C;
179 typedef std::pair<int, std::string> P;
180 P a[] =
181 {
182 P(10, "ten"),
183 P(20, "twenty"),
184 P(30, "thirty"),
185 P(40, "forty"),
186 P(50, "fifty"),
187 P(60, "sixty"),
188 P(70, "seventy"),
189 P(80, "eighty"),
190 };
191 C c1(std::begin(a), std::end(a));
192 C c2 = c1;
193 assert(testEquality(c1, c2, true));
194 c1.insert(P(90, "ninety"));
195 c2.insert(P(100, "onehundred"));
196 assert(testEquality(c1, c2, false));
197 }
198#endif
199
200 return 0;
201}
202

source code of libcxx/test/std/containers/unord/unord.map/eq.pass.cpp