1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <unordered_set> 11 12 // template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, 13 // class Alloc = allocator<Value>> 14 // class unordered_multiset 15 16 // unordered_multiset& operator=(unordered_multiset&& u); 17 18 #include <unordered_set> 19 #include <cassert> 20 #include <cfloat> 21 22 #include "../../../test_compare.h" 23 #include "../../../test_hash.h" 24 #include "test_allocator.h" 25 #include "min_allocator.h" 26 27 int main() 28 { 29 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 30 { 31 typedef test_allocator<int> A; 32 typedef std::unordered_multiset<int, 33 test_hash<std::hash<int> >, 34 test_compare<std::equal_to<int> >, 35 A 36 > C; 37 typedef int P; 38 P a[] = 39 { 40 P(1), 41 P(2), 42 P(3), 43 P(4), 44 P(1), 45 P(2) 46 }; 47 C c0(a, a + sizeof(a)/sizeof(a[0]), 48 7, 49 test_hash<std::hash<int> >(8), 50 test_compare<std::equal_to<int> >(9), 51 A(10) 52 ); 53 C c(a, a + 2, 54 7, 55 test_hash<std::hash<int> >(2), 56 test_compare<std::equal_to<int> >(3), 57 A(4) 58 ); 59 c = std::move(c0); 60 assert(c.bucket_count() == 7); 61 assert(c.size() == 6); 62 C::const_iterator i = c.cbegin(); 63 assert(*i == 1); 64 ++i; 65 assert(*i == 1); 66 ++i; 67 assert(*i == 2); 68 ++i; 69 assert(*i == 2); 70 ++i; 71 assert(*i == 3); 72 ++i; 73 assert(*i == 4); 74 assert(c.hash_function() == test_hash<std::hash<int> >(8)); 75 assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); 76 assert(c.get_allocator() == A(4)); 77 assert(!c.empty()); 78 assert(std::distance(c.begin(), c.end()) == c.size()); 79 assert(std::distance(c.cbegin(), c.cend()) == c.size()); 80 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); 81 assert(c.max_load_factor() == 1); 82 } 83 { 84 typedef test_allocator<int> A; 85 typedef std::unordered_multiset<int, 86 test_hash<std::hash<int> >, 87 test_compare<std::equal_to<int> >, 88 A 89 > C; 90 typedef int P; 91 P a[] = 92 { 93 P(1), 94 P(2), 95 P(3), 96 P(4), 97 P(1), 98 P(2) 99 }; 100 C c0(a, a + sizeof(a)/sizeof(a[0]), 101 7, 102 test_hash<std::hash<int> >(8), 103 test_compare<std::equal_to<int> >(9), 104 A(10) 105 ); 106 C c(a, a + 2, 107 7, 108 test_hash<std::hash<int> >(2), 109 test_compare<std::equal_to<int> >(3), 110 A(10) 111 ); 112 c = std::move(c0); 113 assert(c.bucket_count() == 7); 114 assert(c.size() == 6); 115 assert(c.count(1) == 2); 116 assert(c.count(2) == 2); 117 assert(c.count(3) == 1); 118 assert(c.count(4) == 1); 119 assert(c.hash_function() == test_hash<std::hash<int> >(8)); 120 assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); 121 assert(c.get_allocator() == A(10)); 122 assert(!c.empty()); 123 assert(std::distance(c.begin(), c.end()) == c.size()); 124 assert(std::distance(c.cbegin(), c.cend()) == c.size()); 125 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); 126 assert(c.max_load_factor() == 1); 127 } 128 { 129 typedef other_allocator<int> A; 130 typedef std::unordered_multiset<int, 131 test_hash<std::hash<int> >, 132 test_compare<std::equal_to<int> >, 133 A 134 > C; 135 typedef int P; 136 P a[] = 137 { 138 P(1), 139 P(2), 140 P(3), 141 P(4), 142 P(1), 143 P(2) 144 }; 145 C c0(a, a + sizeof(a)/sizeof(a[0]), 146 7, 147 test_hash<std::hash<int> >(8), 148 test_compare<std::equal_to<int> >(9), 149 A(10) 150 ); 151 C c(a, a + 2, 152 7, 153 test_hash<std::hash<int> >(2), 154 test_compare<std::equal_to<int> >(3), 155 A(4) 156 ); 157 c = std::move(c0); 158 assert(c.bucket_count() == 7); 159 assert(c.size() == 6); 160 assert(c.count(1) == 2); 161 assert(c.count(2) == 2); 162 assert(c.count(3) == 1); 163 assert(c.count(4) == 1); 164 assert(c.hash_function() == test_hash<std::hash<int> >(8)); 165 assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); 166 assert(c.get_allocator() == A(10)); 167 assert(!c.empty()); 168 assert(std::distance(c.begin(), c.end()) == c.size()); 169 assert(std::distance(c.cbegin(), c.cend()) == c.size()); 170 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); 171 assert(c.max_load_factor() == 1); 172 } 173 #if __cplusplus >= 201103L 174 { 175 typedef test_allocator<int> A; 176 typedef std::unordered_multiset<int, 177 test_hash<std::hash<int> >, 178 test_compare<std::equal_to<int> >, 179 A 180 > C; 181 typedef int P; 182 P a[] = 183 { 184 P(1), 185 P(2), 186 P(3), 187 P(4), 188 P(1), 189 P(2) 190 }; 191 C c0(a, a + sizeof(a)/sizeof(a[0]), 192 7, 193 test_hash<std::hash<int> >(8), 194 test_compare<std::equal_to<int> >(9), 195 A() 196 ); 197 C c(a, a + 2, 198 7, 199 test_hash<std::hash<int> >(2), 200 test_compare<std::equal_to<int> >(3), 201 A() 202 ); 203 c = std::move(c0); 204 assert(c.bucket_count() == 7); 205 assert(c.size() == 6); 206 C::const_iterator i = c.cbegin(); 207 assert(*i == 4); 208 ++i; 209 assert(*i == 3); 210 ++i; 211 assert(*i == 2); 212 ++i; 213 assert(*i == 2); 214 ++i; 215 assert(*i == 1); 216 ++i; 217 assert(*i == 1); 218 assert(c.hash_function() == test_hash<std::hash<int> >(8)); 219 assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); 220 assert(c.get_allocator() == A()); 221 assert(!c.empty()); 222 assert(std::distance(c.begin(), c.end()) == c.size()); 223 assert(std::distance(c.cbegin(), c.cend()) == c.size()); 224 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); 225 assert(c.max_load_factor() == 1); 226 } 227 { 228 typedef min_allocator<int> A; 229 typedef std::unordered_multiset<int, 230 test_hash<std::hash<int> >, 231 test_compare<std::equal_to<int> >, 232 A 233 > C; 234 typedef int P; 235 P a[] = 236 { 237 P(1), 238 P(2), 239 P(3), 240 P(4), 241 P(1), 242 P(2) 243 }; 244 C c0(a, a + sizeof(a)/sizeof(a[0]), 245 7, 246 test_hash<std::hash<int> >(8), 247 test_compare<std::equal_to<int> >(9), 248 A() 249 ); 250 C c(a, a + 2, 251 7, 252 test_hash<std::hash<int> >(2), 253 test_compare<std::equal_to<int> >(3), 254 A() 255 ); 256 c = std::move(c0); 257 assert(c.bucket_count() == 7); 258 assert(c.size() == 6); 259 assert(c.count(1) == 2); 260 assert(c.count(2) == 2); 261 assert(c.count(3) == 1); 262 assert(c.count(4) == 1); 263 assert(c.hash_function() == test_hash<std::hash<int> >(8)); 264 assert(c.key_eq() == test_compare<std::equal_to<int> >(9)); 265 assert(c.get_allocator() == A()); 266 assert(!c.empty()); 267 assert(std::distance(c.begin(), c.end()) == c.size()); 268 assert(std::distance(c.cbegin(), c.cend()) == c.size()); 269 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); 270 assert(c.max_load_factor() == 1); 271 } 272 #endif 273 #if _LIBCPP_DEBUG >= 1 274 { 275 std::unordered_multiset<int> s1 = {1, 2, 3}; 276 std::unordered_multiset<int>::iterator i = s1.begin(); 277 int k = *i; 278 std::unordered_multiset<int> s2; 279 s2 = std::move(s1); 280 assert(*i == k); 281 s2.erase(i); 282 assert(s2.size() == 2); 283 } 284 #endif 285 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 286 } 287