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 = hash<Key>, class Pred = equal_to<Key>, 12 // class Alloc = allocator<pair<const Key, T>>> 13 // class unordered_multimap 14 15 // void swap(unordered_multimap& __u); 16 17 #include <unordered_map> 18 #include <string> 19 #include <set> 20 #include <cassert> 21 #include <cstddef> 22 23 #include "test_macros.h" 24 #include "../../../check_consecutive.h" 25 #include "../../../test_compare.h" 26 #include "../../../test_hash.h" 27 #include "test_allocator.h" 28 #include "min_allocator.h" 29 30 int main(int, char**) 31 { 32 { main(int,char **)33 typedef test_hash<int> Hash; 34 typedef test_equal_to<int> Compare; 35 typedef test_allocator<std::pair<const int, std::string> > Alloc; 36 typedef std::unordered_multimap<int, std::string, Hash, Compare, Alloc> C; 37 C c1(0, Hash(1), Compare(1), Alloc(1, 1)); 38 C c2(0, Hash(2), Compare(2), Alloc(1, 2)); 39 c2.max_load_factor(2); 40 swap(c1, c2); 41 42 LIBCPP_ASSERT(c1.bucket_count() == 0); 43 assert(c1.size() == 0); 44 assert(c1.hash_function() == Hash(2)); 45 assert(c1.key_eq() == Compare(2)); 46 assert(c1.get_allocator().get_id() == 1); 47 assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size()); 48 assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size()); 49 assert(c1.max_load_factor() == 2); 50 51 LIBCPP_ASSERT(c2.bucket_count() == 0); 52 assert(c2.size() == 0); 53 assert(c2.hash_function() == Hash(1)); 54 assert(c2.key_eq() == Compare(1)); 55 assert(c2.get_allocator().get_id() == 2); 56 assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size()); 57 assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size()); 58 assert(c2.max_load_factor() == 1); 59 } 60 { 61 typedef test_hash<int> Hash; 62 typedef test_equal_to<int> Compare; 63 typedef test_allocator<std::pair<const int, std::string> > Alloc; 64 typedef std::unordered_multimap<int, std::string, Hash, Compare, Alloc> C; 65 typedef std::pair<int, std::string> P; 66 P a2[] = 67 { 68 P(10, "ten"), 69 P(20, "twenty"), 70 P(30, "thirty"), 71 P(40, "forty"), 72 P(50, "fifty"), 73 P(60, "sixty"), 74 P(70, "seventy"), 75 P(80, "eighty"), 76 }; 77 C c1(0, Hash(1), Compare(1), Alloc(1, 1)); 78 C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(1, 2)); 79 c2.max_load_factor(2); 80 C::iterator it2 = c2.begin(); 81 swap(c1, c2); 82 83 assert(c1.bucket_count() >= 8); 84 assert(c1.size() == 8); 85 assert(c1.find(10)->second == "ten"); 86 assert(c1.find(20)->second == "twenty"); 87 assert(c1.find(30)->second == "thirty"); 88 assert(c1.find(40)->second == "forty"); 89 assert(c1.find(50)->second == "fifty"); 90 assert(c1.find(60)->second == "sixty"); 91 assert(c1.find(70)->second == "seventy"); 92 assert(c1.find(80)->second == "eighty"); 93 assert(c1.hash_function() == Hash(2)); 94 assert(c1.key_eq() == Compare(2)); 95 assert(c1.get_allocator().get_id() == 1); 96 assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size()); 97 assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size()); 98 assert(c1.max_load_factor() == 2); 99 assert(it2 == c1.begin()); // Iterators are not invalidated 100 101 LIBCPP_ASSERT(c2.bucket_count() == 0); 102 assert(c2.size() == 0); 103 assert(c2.hash_function() == Hash(1)); 104 assert(c2.key_eq() == Compare(1)); 105 assert(c2.get_allocator().get_id() == 2); 106 assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size()); 107 assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size()); 108 assert(c2.max_load_factor() == 1); 109 } 110 { 111 typedef test_hash<int> Hash; 112 typedef test_equal_to<int> Compare; 113 typedef test_allocator<std::pair<const int, std::string> > Alloc; 114 typedef std::unordered_multimap<int, std::string, Hash, Compare, Alloc> C; 115 typedef std::pair<int, std::string> P; 116 P a1[] = 117 { 118 P(1, "one"), 119 P(2, "two"), 120 P(3, "three"), 121 P(4, "four"), 122 P(1, "four"), 123 P(2, "four"), 124 }; 125 C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1, 1)); 126 C c2(0, Hash(2), Compare(2), Alloc(1, 2)); 127 c2.max_load_factor(2); 128 C::iterator it1 = c1.begin(); 129 swap(c1, c2); 130 131 LIBCPP_ASSERT(c1.bucket_count() == 0); 132 assert(c1.size() == 0); 133 assert(c1.hash_function() == Hash(2)); 134 assert(c1.key_eq() == Compare(2)); 135 assert(c1.get_allocator().get_id() == 1); 136 assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size()); 137 assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size()); 138 assert(c1.max_load_factor() == 2); 139 140 assert(c2.bucket_count() >= 6); 141 assert(c2.size() == 6); 142 std::multiset<std::string> s; 143 s.insert("one"); 144 s.insert("four"); 145 CheckConsecutiveKeys<C::const_iterator>(c2.find(1), c2.end(), 1, s); 146 s.insert("two"); 147 s.insert("four"); 148 CheckConsecutiveKeys<C::const_iterator>(c2.find(2), c2.end(), 2, s); 149 assert(c2.find(3)->second == "three"); 150 assert(c2.find(4)->second == "four"); 151 assert(c2.hash_function() == Hash(1)); 152 assert(c2.key_eq() == Compare(1)); 153 assert(c2.get_allocator().get_id() == 2); 154 assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size()); 155 assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size()); 156 assert(c2.max_load_factor() == 1); 157 assert(it1 == c2.begin()); // Iterators are not invalidated 158 } 159 { 160 typedef test_hash<int> Hash; 161 typedef test_equal_to<int> Compare; 162 typedef test_allocator<std::pair<const int, std::string> > Alloc; 163 typedef std::unordered_multimap<int, std::string, Hash, Compare, Alloc> C; 164 typedef std::pair<int, std::string> P; 165 P a1[] = 166 { 167 P(1, "one"), 168 P(2, "two"), 169 P(3, "three"), 170 P(4, "four"), 171 P(1, "four"), 172 P(2, "four"), 173 }; 174 P a2[] = 175 { 176 P(10, "ten"), 177 P(20, "twenty"), 178 P(30, "thirty"), 179 P(40, "forty"), 180 P(50, "fifty"), 181 P(60, "sixty"), 182 P(70, "seventy"), 183 P(80, "eighty"), 184 }; 185 C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1, 1)); 186 C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(1, 2)); 187 c2.max_load_factor(2); 188 C::iterator it1 = c1.begin(); 189 C::iterator it2 = c2.begin(); 190 swap(c1, c2); 191 192 assert(c1.bucket_count() >= 8); 193 assert(c1.size() == 8); 194 assert(c1.find(10)->second == "ten"); 195 assert(c1.find(20)->second == "twenty"); 196 assert(c1.find(30)->second == "thirty"); 197 assert(c1.find(40)->second == "forty"); 198 assert(c1.find(50)->second == "fifty"); 199 assert(c1.find(60)->second == "sixty"); 200 assert(c1.find(70)->second == "seventy"); 201 assert(c1.find(80)->second == "eighty"); 202 assert(c1.hash_function() == Hash(2)); 203 assert(c1.key_eq() == Compare(2)); 204 assert(c1.get_allocator().get_id() == 1); 205 assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size()); 206 assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size()); 207 assert(c1.max_load_factor() == 2); 208 assert(it2 == c1.begin()); // Iterators are not invalidated 209 210 assert(c2.bucket_count() >= 6); 211 assert(c2.size() == 6); 212 std::multiset<std::string> s; 213 s.insert("one"); 214 s.insert("four"); 215 CheckConsecutiveKeys<C::const_iterator>(c2.find(1), c2.end(), 1, s); 216 s.insert("two"); 217 s.insert("four"); 218 CheckConsecutiveKeys<C::const_iterator>(c2.find(2), c2.end(), 2, s); 219 assert(c2.find(3)->second == "three"); 220 assert(c2.find(4)->second == "four"); 221 assert(c2.hash_function() == Hash(1)); 222 assert(c2.key_eq() == Compare(1)); 223 assert(c2.get_allocator().get_id() == 2); 224 assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size()); 225 assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size()); 226 assert(c2.max_load_factor() == 1); 227 assert(it1 == c2.begin()); // Iterators are not invalidated 228 } 229 230 { 231 typedef test_hash<int> Hash; 232 typedef test_equal_to<int> Compare; 233 typedef other_allocator<std::pair<const int, std::string> > Alloc; 234 typedef std::unordered_multimap<int, std::string, Hash, Compare, Alloc> C; 235 C c1(0, Hash(1), Compare(1), Alloc(1)); 236 C c2(0, Hash(2), Compare(2), Alloc(2)); 237 c2.max_load_factor(2); 238 swap(c1, c2); 239 240 LIBCPP_ASSERT(c1.bucket_count() == 0); 241 assert(c1.size() == 0); 242 assert(c1.hash_function() == Hash(2)); 243 assert(c1.key_eq() == Compare(2)); 244 assert(c1.get_allocator() == Alloc(2)); 245 assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size()); 246 assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size()); 247 assert(c1.max_load_factor() == 2); 248 249 LIBCPP_ASSERT(c2.bucket_count() == 0); 250 assert(c2.size() == 0); 251 assert(c2.hash_function() == Hash(1)); 252 assert(c2.key_eq() == Compare(1)); 253 assert(c2.get_allocator() == Alloc(1)); 254 assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size()); 255 assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size()); 256 assert(c2.max_load_factor() == 1); 257 } 258 { 259 typedef test_hash<int> Hash; 260 typedef test_equal_to<int> Compare; 261 typedef other_allocator<std::pair<const int, std::string> > Alloc; 262 typedef std::unordered_multimap<int, std::string, Hash, Compare, Alloc> C; 263 typedef std::pair<int, std::string> P; 264 P a2[] = 265 { 266 P(10, "ten"), 267 P(20, "twenty"), 268 P(30, "thirty"), 269 P(40, "forty"), 270 P(50, "fifty"), 271 P(60, "sixty"), 272 P(70, "seventy"), 273 P(80, "eighty"), 274 }; 275 C c1(0, Hash(1), Compare(1), Alloc(1)); 276 C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); 277 c2.max_load_factor(2); 278 swap(c1, c2); 279 280 assert(c1.bucket_count() >= 8); 281 assert(c1.size() == 8); 282 assert(c1.find(10)->second == "ten"); 283 assert(c1.find(20)->second == "twenty"); 284 assert(c1.find(30)->second == "thirty"); 285 assert(c1.find(40)->second == "forty"); 286 assert(c1.find(50)->second == "fifty"); 287 assert(c1.find(60)->second == "sixty"); 288 assert(c1.find(70)->second == "seventy"); 289 assert(c1.find(80)->second == "eighty"); 290 assert(c1.hash_function() == Hash(2)); 291 assert(c1.key_eq() == Compare(2)); 292 assert(c1.get_allocator() == Alloc(2)); 293 assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size()); 294 assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size()); 295 assert(c1.max_load_factor() == 2); 296 297 LIBCPP_ASSERT(c2.bucket_count() == 0); 298 assert(c2.size() == 0); 299 assert(c2.hash_function() == Hash(1)); 300 assert(c2.key_eq() == Compare(1)); 301 assert(c2.get_allocator() == Alloc(1)); 302 assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size()); 303 assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size()); 304 assert(c2.max_load_factor() == 1); 305 } 306 { 307 typedef test_hash<int> Hash; 308 typedef test_equal_to<int> Compare; 309 typedef other_allocator<std::pair<const int, std::string> > Alloc; 310 typedef std::unordered_multimap<int, std::string, Hash, Compare, Alloc> C; 311 typedef std::pair<int, std::string> P; 312 P a1[] = 313 { 314 P(1, "one"), 315 P(2, "two"), 316 P(3, "three"), 317 P(4, "four"), 318 P(1, "four"), 319 P(2, "four"), 320 }; 321 C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); 322 C c2(0, Hash(2), Compare(2), Alloc(2)); 323 c2.max_load_factor(2); 324 swap(c1, c2); 325 326 LIBCPP_ASSERT(c1.bucket_count() == 0); 327 assert(c1.size() == 0); 328 assert(c1.hash_function() == Hash(2)); 329 assert(c1.key_eq() == Compare(2)); 330 assert(c1.get_allocator() == Alloc(2)); 331 assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size()); 332 assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size()); 333 assert(c1.max_load_factor() == 2); 334 335 assert(c2.bucket_count() >= 6); 336 assert(c2.size() == 6); 337 std::multiset<std::string> s; 338 s.insert("one"); 339 s.insert("four"); 340 CheckConsecutiveKeys<C::const_iterator>(c2.find(1), c2.end(), 1, s); 341 s.insert("two"); 342 s.insert("four"); 343 CheckConsecutiveKeys<C::const_iterator>(c2.find(2), c2.end(), 2, s); 344 assert(c2.find(3)->second == "three"); 345 assert(c2.find(4)->second == "four"); 346 assert(c2.hash_function() == Hash(1)); 347 assert(c2.key_eq() == Compare(1)); 348 assert(c2.get_allocator() == Alloc(1)); 349 assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size()); 350 assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size()); 351 assert(c2.max_load_factor() == 1); 352 } 353 { 354 typedef test_hash<int> Hash; 355 typedef test_equal_to<int> Compare; 356 typedef other_allocator<std::pair<const int, std::string> > Alloc; 357 typedef std::unordered_multimap<int, std::string, Hash, Compare, Alloc> C; 358 typedef std::pair<int, std::string> P; 359 P a1[] = 360 { 361 P(1, "one"), 362 P(2, "two"), 363 P(3, "three"), 364 P(4, "four"), 365 P(1, "four"), 366 P(2, "four"), 367 }; 368 P a2[] = 369 { 370 P(10, "ten"), 371 P(20, "twenty"), 372 P(30, "thirty"), 373 P(40, "forty"), 374 P(50, "fifty"), 375 P(60, "sixty"), 376 P(70, "seventy"), 377 P(80, "eighty"), 378 }; 379 C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); 380 C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); 381 c2.max_load_factor(2); 382 swap(c1, c2); 383 384 assert(c1.bucket_count() >= 8); 385 assert(c1.size() == 8); 386 assert(c1.find(10)->second == "ten"); 387 assert(c1.find(20)->second == "twenty"); 388 assert(c1.find(30)->second == "thirty"); 389 assert(c1.find(40)->second == "forty"); 390 assert(c1.find(50)->second == "fifty"); 391 assert(c1.find(60)->second == "sixty"); 392 assert(c1.find(70)->second == "seventy"); 393 assert(c1.find(80)->second == "eighty"); 394 assert(c1.hash_function() == Hash(2)); 395 assert(c1.key_eq() == Compare(2)); 396 assert(c1.get_allocator() == Alloc(2)); 397 assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size()); 398 assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size()); 399 assert(c1.max_load_factor() == 2); 400 401 assert(c2.bucket_count() >= 6); 402 assert(c2.size() == 6); 403 std::multiset<std::string> s; 404 s.insert("one"); 405 s.insert("four"); 406 CheckConsecutiveKeys<C::const_iterator>(c2.find(1), c2.end(), 1, s); 407 s.insert("two"); 408 s.insert("four"); 409 CheckConsecutiveKeys<C::const_iterator>(c2.find(2), c2.end(), 2, s); 410 assert(c2.find(3)->second == "three"); 411 assert(c2.find(4)->second == "four"); 412 assert(c2.hash_function() == Hash(1)); 413 assert(c2.key_eq() == Compare(1)); 414 assert(c2.get_allocator() == Alloc(1)); 415 assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size()); 416 assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size()); 417 assert(c2.max_load_factor() == 1); 418 } 419 #if TEST_STD_VER >= 11 420 { 421 typedef test_hash<int> Hash; 422 typedef test_equal_to<int> Compare; 423 typedef min_allocator<std::pair<const int, std::string> > Alloc; 424 typedef std::unordered_multimap<int, std::string, Hash, Compare, Alloc> C; 425 C c1(0, Hash(1), Compare(1), Alloc()); 426 C c2(0, Hash(2), Compare(2), Alloc()); 427 c2.max_load_factor(2); 428 swap(c1, c2); 429 430 LIBCPP_ASSERT(c1.bucket_count() == 0); 431 assert(c1.size() == 0); 432 assert(c1.hash_function() == Hash(2)); 433 assert(c1.key_eq() == Compare(2)); 434 assert(c1.get_allocator() == Alloc()); 435 assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size()); 436 assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size()); 437 assert(c1.max_load_factor() == 2); 438 439 LIBCPP_ASSERT(c2.bucket_count() == 0); 440 assert(c2.size() == 0); 441 assert(c2.hash_function() == Hash(1)); 442 assert(c2.key_eq() == Compare(1)); 443 assert(c2.get_allocator() == Alloc()); 444 assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size()); 445 assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size()); 446 assert(c2.max_load_factor() == 1); 447 } 448 { 449 typedef test_hash<int> Hash; 450 typedef test_equal_to<int> Compare; 451 typedef min_allocator<std::pair<const int, std::string> > Alloc; 452 typedef std::unordered_multimap<int, std::string, Hash, Compare, Alloc> C; 453 typedef std::pair<int, std::string> P; 454 P a2[] = 455 { 456 P(10, "ten"), 457 P(20, "twenty"), 458 P(30, "thirty"), 459 P(40, "forty"), 460 P(50, "fifty"), 461 P(60, "sixty"), 462 P(70, "seventy"), 463 P(80, "eighty"), 464 }; 465 C c1(0, Hash(1), Compare(1), Alloc()); 466 C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc()); 467 c2.max_load_factor(2); 468 swap(c1, c2); 469 470 assert(c1.bucket_count() >= 8); 471 assert(c1.size() == 8); 472 assert(c1.find(10)->second == "ten"); 473 assert(c1.find(20)->second == "twenty"); 474 assert(c1.find(30)->second == "thirty"); 475 assert(c1.find(40)->second == "forty"); 476 assert(c1.find(50)->second == "fifty"); 477 assert(c1.find(60)->second == "sixty"); 478 assert(c1.find(70)->second == "seventy"); 479 assert(c1.find(80)->second == "eighty"); 480 assert(c1.hash_function() == Hash(2)); 481 assert(c1.key_eq() == Compare(2)); 482 assert(c1.get_allocator() == Alloc()); 483 assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size()); 484 assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size()); 485 assert(c1.max_load_factor() == 2); 486 487 LIBCPP_ASSERT(c2.bucket_count() == 0); 488 assert(c2.size() == 0); 489 assert(c2.hash_function() == Hash(1)); 490 assert(c2.key_eq() == Compare(1)); 491 assert(c2.get_allocator() == Alloc()); 492 assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size()); 493 assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size()); 494 assert(c2.max_load_factor() == 1); 495 } 496 { 497 typedef test_hash<int> Hash; 498 typedef test_equal_to<int> Compare; 499 typedef min_allocator<std::pair<const int, std::string> > Alloc; 500 typedef std::unordered_multimap<int, std::string, Hash, Compare, Alloc> C; 501 typedef std::pair<int, std::string> P; 502 P a1[] = 503 { 504 P(1, "one"), 505 P(2, "two"), 506 P(3, "three"), 507 P(4, "four"), 508 P(1, "four"), 509 P(2, "four"), 510 }; 511 C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc()); 512 C c2(0, Hash(2), Compare(2), Alloc()); 513 c2.max_load_factor(2); 514 swap(c1, c2); 515 516 LIBCPP_ASSERT(c1.bucket_count() == 0); 517 assert(c1.size() == 0); 518 assert(c1.hash_function() == Hash(2)); 519 assert(c1.key_eq() == Compare(2)); 520 assert(c1.get_allocator() == Alloc()); 521 assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size()); 522 assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size()); 523 assert(c1.max_load_factor() == 2); 524 525 assert(c2.bucket_count() >= 6); 526 assert(c2.size() == 6); 527 std::multiset<std::string> s; 528 s.insert("one"); 529 s.insert("four"); 530 CheckConsecutiveKeys<C::const_iterator>(c2.find(1), c2.end(), 1, s); 531 s.insert("two"); 532 s.insert("four"); 533 CheckConsecutiveKeys<C::const_iterator>(c2.find(2), c2.end(), 2, s); 534 assert(c2.find(3)->second == "three"); 535 assert(c2.find(4)->second == "four"); 536 assert(c2.hash_function() == Hash(1)); 537 assert(c2.key_eq() == Compare(1)); 538 assert(c2.get_allocator() == Alloc()); 539 assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size()); 540 assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size()); 541 assert(c2.max_load_factor() == 1); 542 } 543 { 544 typedef test_hash<int> Hash; 545 typedef test_equal_to<int> Compare; 546 typedef min_allocator<std::pair<const int, std::string> > Alloc; 547 typedef std::unordered_multimap<int, std::string, Hash, Compare, Alloc> C; 548 typedef std::pair<int, std::string> P; 549 P a1[] = 550 { 551 P(1, "one"), 552 P(2, "two"), 553 P(3, "three"), 554 P(4, "four"), 555 P(1, "four"), 556 P(2, "four"), 557 }; 558 P a2[] = 559 { 560 P(10, "ten"), 561 P(20, "twenty"), 562 P(30, "thirty"), 563 P(40, "forty"), 564 P(50, "fifty"), 565 P(60, "sixty"), 566 P(70, "seventy"), 567 P(80, "eighty"), 568 }; 569 C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc()); 570 C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc()); 571 c2.max_load_factor(2); 572 swap(c1, c2); 573 574 assert(c1.bucket_count() >= 8); 575 assert(c1.size() == 8); 576 assert(c1.find(10)->second == "ten"); 577 assert(c1.find(20)->second == "twenty"); 578 assert(c1.find(30)->second == "thirty"); 579 assert(c1.find(40)->second == "forty"); 580 assert(c1.find(50)->second == "fifty"); 581 assert(c1.find(60)->second == "sixty"); 582 assert(c1.find(70)->second == "seventy"); 583 assert(c1.find(80)->second == "eighty"); 584 assert(c1.hash_function() == Hash(2)); 585 assert(c1.key_eq() == Compare(2)); 586 assert(c1.get_allocator() == Alloc()); 587 assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size()); 588 assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size()); 589 assert(c1.max_load_factor() == 2); 590 591 assert(c2.bucket_count() >= 6); 592 assert(c2.size() == 6); 593 std::multiset<std::string> s; 594 s.insert("one"); 595 s.insert("four"); 596 CheckConsecutiveKeys<C::const_iterator>(c2.find(1), c2.end(), 1, s); 597 s.insert("two"); 598 s.insert("four"); 599 CheckConsecutiveKeys<C::const_iterator>(c2.find(2), c2.end(), 2, s); 600 assert(c2.find(3)->second == "three"); 601 assert(c2.find(4)->second == "four"); 602 assert(c2.hash_function() == Hash(1)); 603 assert(c2.key_eq() == Compare(1)); 604 assert(c2.get_allocator() == Alloc()); 605 assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size()); 606 assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size()); 607 assert(c2.max_load_factor() == 1); 608 } 609 #endif 610 611 return 0; 612 } 613