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