26 #include <boost/mpl/list.hpp>
27 #include <boost/test/unit_test.hpp>
36 #include <type_traits>
42 BOOST_AUTO_TEST_SUITE(test_robin_map)
57 std::equal_to<move_only_test>,
62 std::equal_to<move_only_test>,
67 std::equal_to<copy_only_test>,
72 std::equal_to<copy_only_test>,
81 using key_t =
typename HMap::key_type;
82 using value_t =
typename HMap::mapped_type;
84 const std::size_t nb_values = 1000;
86 BOOST_CHECK_EQUAL(map.bucket_count(), 0);
88 typename HMap::iterator it;
91 for (std::size_t i = 0; i < nb_values; i++) {
92 std::tie(it, inserted) =
93 map.insert({utils::get_key<key_t>(i), utils::get_value<value_t>(i)});
95 BOOST_CHECK_EQUAL(it->first, utils::get_key<key_t>(i));
96 BOOST_CHECK_EQUAL(it->second, utils::get_value<value_t>(i));
97 BOOST_CHECK(inserted);
99 BOOST_CHECK_EQUAL(map.size(), nb_values);
101 for (std::size_t i = 0; i < nb_values; i++) {
102 std::tie(it, inserted) = map.insert(
103 {utils::get_key<key_t>(i), utils::get_value<value_t>(i + 1)});
105 BOOST_CHECK_EQUAL(it->first, utils::get_key<key_t>(i));
106 BOOST_CHECK_EQUAL(it->second, utils::get_value<value_t>(i));
107 BOOST_CHECK(!inserted);
110 for (std::size_t i = 0; i < nb_values; i++) {
111 it = map.find(utils::get_key<key_t>(i));
113 BOOST_CHECK_EQUAL(it->first, utils::get_key<key_t>(i));
114 BOOST_CHECK_EQUAL(it->second, utils::get_value<value_t>(i));
121 const int nb_values = 1000;
122 std::vector<std::pair<int, int>> values_to_insert(nb_values);
123 for (
int i = 0; i < nb_values; i++) {
124 values_to_insert[i] = std::make_pair(i, i + 1);
128 map.
insert(std::next(values_to_insert.begin(), 10),
129 values_to_insert.end() - 5);
131 BOOST_CHECK_EQUAL(map.
size(), 987);
133 BOOST_CHECK_EQUAL(map.
at(-1), 1);
134 BOOST_CHECK_EQUAL(map.
at(-2), 2);
136 for (
int i = 10; i < nb_values - 5; i++) {
137 BOOST_CHECK_EQUAL(map.
at(i), i + 1);
152 BOOST_CHECK(map.insert(map.find(2), std::make_pair(3, 4)) == map.find(3));
155 BOOST_CHECK(map.insert(map.find(2), std::make_pair(2, 4)) == map.find(2));
158 BOOST_CHECK(map.insert(map.find(10), std::make_pair(2, 4)) == map.find(2));
160 BOOST_CHECK_EQUAL(map.size(), 3);
163 BOOST_CHECK_EQUAL(map.insert(map.find(10), std::make_pair(4, 3))->first, 4);
166 BOOST_CHECK_EQUAL(map.insert(map.find(2), std::make_pair(5, 4))->first, 5);
168 BOOST_CHECK_EQUAL(map.size(), 5);
178 BOOST_CHECK(map.emplace_hint(map.find(2), std::piecewise_construct,
179 std::forward_as_tuple(3),
180 std::forward_as_tuple(4)) == map.find(3));
183 BOOST_CHECK(map.emplace_hint(map.find(2), std::piecewise_construct,
184 std::forward_as_tuple(2),
185 std::forward_as_tuple(4)) == map.find(2));
188 BOOST_CHECK(map.emplace_hint(map.find(10), std::piecewise_construct,
189 std::forward_as_tuple(2),
190 std::forward_as_tuple(4)) == map.find(2));
192 BOOST_CHECK_EQUAL(map.size(), 3);
196 map.emplace_hint(map.find(10), std::piecewise_construct,
197 std::forward_as_tuple(4), std::forward_as_tuple(3))
203 map.emplace_hint(map.find(2), std::piecewise_construct,
204 std::forward_as_tuple(5), std::forward_as_tuple(4))
208 BOOST_CHECK_EQUAL(map.size(), 5);
219 std::tie(it, inserted) =
220 map.
emplace(std::piecewise_construct, std::forward_as_tuple(10),
221 std::forward_as_tuple(1));
222 BOOST_CHECK_EQUAL(it->first, 10);
224 BOOST_CHECK(inserted);
226 std::tie(it, inserted) =
227 map.
emplace(std::piecewise_construct, std::forward_as_tuple(10),
228 std::forward_as_tuple(3));
229 BOOST_CHECK_EQUAL(it->first, 10);
231 BOOST_CHECK(!inserted);
243 BOOST_CHECK_EQUAL(it->first, 10);
245 BOOST_CHECK(inserted);
248 BOOST_CHECK_EQUAL(it->first, 10);
250 BOOST_CHECK(!inserted);
259 const std::size_t nb_values = 1000;
260 for (std::size_t i = 0; i < nb_values; i++) {
261 std::tie(it, inserted) = map.
try_emplace(utils::get_key<std::string>(i), i);
263 BOOST_CHECK_EQUAL(it->first, utils::get_key<std::string>(i));
265 BOOST_CHECK(inserted);
267 BOOST_CHECK_EQUAL(map.
size(), nb_values);
269 for (std::size_t i = 0; i < nb_values; i++) {
270 std::tie(it, inserted) =
271 map.
try_emplace(utils::get_key<std::string>(i), i + 1);
273 BOOST_CHECK_EQUAL(it->first, utils::get_key<std::string>(i));
275 BOOST_CHECK(!inserted);
278 for (std::size_t i = 0; i < nb_values; i++) {
279 it = map.
find(utils::get_key<std::string>(i));
281 BOOST_CHECK_EQUAL(it->first, utils::get_key<std::string>(i));
291 BOOST_CHECK_EQUAL(it->first, 10);
296 BOOST_CHECK_EQUAL(it->first, 10);
301 BOOST_CHECK_EQUAL(it->first, 1);
314 BOOST_CHECK_EQUAL(it->first, 10);
316 BOOST_CHECK(inserted);
319 BOOST_CHECK_EQUAL(it->first, 10);
321 BOOST_CHECK(!inserted);
329 BOOST_CHECK_EQUAL(it->first, 10);
334 BOOST_CHECK_EQUAL(it->first, 10);
339 BOOST_CHECK_EQUAL(it->first, 1);
350 const std::size_t nb_values = 1000;
351 HMap map = utils::get_filled_hash_map<HMap>(nb_values);
353 auto it = map.erase(map.begin(), map.end());
354 BOOST_CHECK(it == map.end());
355 BOOST_CHECK(map.empty());
363 const std::size_t nb_values = 1000;
364 HMap map = utils::get_filled_hash_map<HMap>(nb_values);
366 auto it_first = std::next(map.begin(), 10);
367 auto it_last = std::next(map.begin(), 220);
369 auto it = map.erase(it_first, it_last);
370 BOOST_CHECK_EQUAL(std::distance(it, map.end()), 780);
371 BOOST_CHECK_EQUAL(map.size(), 790);
372 BOOST_CHECK_EQUAL(std::distance(map.begin(), map.end()), 790);
374 for (
auto& val : map) {
375 BOOST_CHECK_EQUAL(map.count(val.first), 1);
381 std::size_t nb_values = 1000;
383 HMap map = utils::get_filled_hash_map<HMap>(nb_values);
384 HMap map2 = utils::get_filled_hash_map<HMap>(nb_values);
386 auto it = map.begin();
389 auto it2 = map2.begin();
390 while (it != map.end()) {
394 BOOST_CHECK_EQUAL(map.count(it2->first), 0);
395 BOOST_CHECK_EQUAL(map.size(), nb_values);
399 BOOST_CHECK(map.empty());
404 const std::size_t hop = 5;
405 std::size_t nb_values = 1000;
407 BOOST_REQUIRE_EQUAL(nb_values % hop, 0);
409 HMap map = utils::get_filled_hash_map<HMap>(nb_values);
411 auto it = map.begin();
412 while (it != map.end()) {
413 it = map.erase(it, std::next(it, hop));
416 BOOST_CHECK_EQUAL(map.size(), nb_values);
419 BOOST_CHECK(map.empty());
424 using key_t =
typename HMap::key_type;
425 using value_t =
typename HMap::mapped_type;
427 const std::size_t nb_values = 2000;
429 typename HMap::iterator it;
433 for (std::size_t i = 0; i < nb_values / 2; i++) {
434 std::tie(it, inserted) =
435 map.insert({utils::get_key<key_t>(i), utils::get_value<value_t>(i)});
437 BOOST_CHECK_EQUAL(it->first, utils::get_key<key_t>(i));
438 BOOST_CHECK_EQUAL(it->second, utils::get_value<value_t>(i));
439 BOOST_CHECK(inserted);
441 BOOST_CHECK_EQUAL(map.size(), nb_values / 2);
444 for (std::size_t i = 0; i < nb_values / 2; i++) {
446 BOOST_CHECK_EQUAL(map.erase(utils::get_key<key_t>(i)), 1);
449 BOOST_CHECK_EQUAL(map.size(), nb_values / 4);
452 for (std::size_t i = nb_values / 2; i < nb_values; i++) {
453 std::tie(it, inserted) =
454 map.insert({utils::get_key<key_t>(i), utils::get_value<value_t>(i)});
456 BOOST_CHECK_EQUAL(it->first, utils::get_key<key_t>(i));
457 BOOST_CHECK_EQUAL(it->second, utils::get_value<value_t>(i));
458 BOOST_CHECK(inserted);
460 BOOST_CHECK_EQUAL(map.size(), nb_values - nb_values / 4);
463 for (std::size_t i = 0; i < nb_values; i++) {
464 if (i % 2 == 0 && i < nb_values / 2) {
465 it = map.find(utils::get_key<key_t>(i));
467 BOOST_CHECK(it == map.end());
469 it = map.find(utils::get_key<key_t>(i));
471 BOOST_REQUIRE(it != map.end());
472 BOOST_CHECK_EQUAL(it->first, utils::get_key<key_t>(i));
473 BOOST_CHECK_EQUAL(it->second, utils::get_value<value_t>(i));
481 const std::size_t nb_values = 100;
483 utils::get_filled_hash_map<tsl::robin_map<std::int64_t, std::int64_t>>(
488 std::advance(it_const, 10);
491 map.erase(it_const, it_const);
492 BOOST_CHECK(it_const == it_mutable);
493 BOOST_CHECK(map.mutable_iterator(it_const) == it_mutable);
494 BOOST_CHECK_EQUAL(map.size(), 100);
496 it_mutable.value() = -100;
497 BOOST_CHECK_EQUAL(it_const.value(), -100);
537 const std::size_t nb_values = 50;
546 map.
rehash(nb_values * 2);
547 for (std::size_t i = 0; i < nb_values; i++) {
549 {utils::get_key<std::int64_t>(i), utils::get_value<std::int64_t>(i)});
567 const std::size_t nb_values = 50;
568 const std::size_t nb_values_erase = 40;
577 map.
rehash(nb_values * 2);
578 for (std::size_t i = 0; i < nb_values; i++) {
580 {utils::get_key<std::int64_t>(i), utils::get_value<std::int64_t>(i)});
584 map.
erase(std::next(map.
begin(), nb_values - nb_values_erase), map.
end());
598 const std::size_t nb_values = 100;
600 utils::get_filled_hash_map<tsl::robin_map<std::int64_t, std::int64_t>>(
603 const std::size_t bucket_count = map.bucket_count();
604 BOOST_CHECK(bucket_count >= nb_values);
607 BOOST_CHECK_EQUAL(map.bucket_count(), bucket_count);
608 BOOST_CHECK(map.empty());
611 BOOST_CHECK_EQUAL(map.bucket_count(), 0);
612 BOOST_CHECK(map.empty());
614 BOOST_CHECK(map.find(1) == map.end());
615 BOOST_CHECK_EQUAL(map.erase(1), 0);
616 BOOST_CHECK(map.insert({1, 10}).second);
617 BOOST_CHECK_EQUAL(map.at(1), 10);
625 {
"a", 1}, {
"e", 5}, {
"d", 4}, {
"c", 3}, {
"b", 2}};
627 {
"e", 5}, {
"c", 3}, {
"b", 2}, {
"a", 1}, {
"d", 4}};
629 {
"e", 5}, {
"c", 3}, {
"b", 2}, {
"a", 1}, {
"d", 4}, {
"f", 6}};
631 {
"e", 5}, {
"c", 3}, {
"b", 2}, {
"a", 1}};
633 {
"a", 1}, {
"e", 5}, {
"d", 4}, {
"c", 3}, {
"b", 26}};
635 {
"a", 1}, {
"e", 5}, {
"d", 4}, {
"c", 3}, {
"z", 2}};
637 BOOST_CHECK(map1 == map1_copy);
638 BOOST_CHECK(map1_copy == map1);
640 BOOST_CHECK(map1 != map2);
641 BOOST_CHECK(map2 != map1);
643 BOOST_CHECK(map1 != map3);
644 BOOST_CHECK(map3 != map1);
646 BOOST_CHECK(map1 != map4);
647 BOOST_CHECK(map4 != map1);
649 BOOST_CHECK(map1 != map5);
650 BOOST_CHECK(map5 != map1);
652 BOOST_CHECK(map2 != map3);
653 BOOST_CHECK(map3 != map2);
655 BOOST_CHECK(map2 != map4);
656 BOOST_CHECK(map4 != map2);
658 BOOST_CHECK(map2 != map5);
659 BOOST_CHECK(map5 != map2);
661 BOOST_CHECK(map3 != map4);
662 BOOST_CHECK(map4 != map3);
664 BOOST_CHECK(map3 != map5);
665 BOOST_CHECK(map5 != map3);
667 BOOST_CHECK(map4 != map5);
668 BOOST_CHECK(map5 != map4);
678 const std::size_t nb_values = 1000;
679 auto map = utils::get_filled_hash_map<HMap>(nb_values);
682 BOOST_CHECK_EQUAL(map.size(), 0);
683 BOOST_CHECK_EQUAL(std::distance(map.begin(), map.end()), 0);
686 map.insert({{1, -1}, {2, -1}, {4, -4}, {3, -3}});
688 BOOST_CHECK(map == (HMap({{5, -5}, {1, -1}, {2, -1}, {4, -4}, {3, -3}})));
695 const std::size_t nb_values = 1000;
696 auto map = utils::get_filled_hash_map<HMap>(nb_values);
697 map.min_load_factor(0.1
f);
700 BOOST_CHECK_EQUAL(map.bucket_count(), 0);
701 BOOST_CHECK_EQUAL(map.size(), 0);
702 BOOST_CHECK_EQUAL(std::distance(map.begin(), map.end()), 0);
705 map.insert({{1, -1}, {2, -1}, {4, -4}, {3, -3}});
707 BOOST_CHECK(map == (HMap({{5, -5}, {1, -1}, {2, -1}, {4, -4}, {3, -3}})));
715 const std::size_t nb_values = 100;
717 utils::get_filled_hash_map<tsl::robin_map<std::int64_t, std::int64_t>>(
720 for (
auto it = map.begin(); it != map.end(); it++) {
721 if (it.key() % 2 == 0) {
726 for (
auto& val : map) {
727 if (val.first % 2 == 0) {
728 BOOST_CHECK_EQUAL(val.second, -1);
730 BOOST_CHECK_NE(val.second, -1);
737 const auto it = map.
begin();
739 BOOST_CHECK_EQUAL(it->second, 1);
741 BOOST_CHECK_EQUAL(it->second, 11);
755 std::numeric_limits<std::size_t>::max())),
756 std::bad_alloc, std::length_error);
762 std::numeric_limits<std::size_t>::max() / 2 + 1)),
763 std::bad_alloc, std::length_error);
769 std::numeric_limits<std::size_t>::max())),
770 std::bad_alloc, std::length_error);
776 std::numeric_limits<std::size_t>::max() / 2)),
777 std::bad_alloc, std::length_error);
783 std::numeric_limits<std::size_t>::max())),
784 std::bad_alloc, std::length_error);
799 BOOST_CHECK_EQUAL(map.
size(), 2);
801 map = {{1, 3}, {2, 4}};
802 BOOST_CHECK_EQUAL(map.
size(), 2);
803 BOOST_CHECK_EQUAL(map.
at(1), 3);
804 BOOST_CHECK_EQUAL(map.
at(2), 4);
805 BOOST_CHECK(map.
find(0) == map.
end());
808 BOOST_CHECK(map.
empty());
819 const std::size_t nb_values = 100;
820 HMap map = utils::get_filled_hash_map<HMap>(nb_values);
821 HMap map_move(std::move(map));
823 BOOST_CHECK(map_move == utils::get_filled_hash_map<HMap>(nb_values));
824 BOOST_CHECK(map == (HMap()));
826 for (std::size_t i = nb_values; i < nb_values * 2; i++) {
828 {utils::get_key<std::string>(i), utils::get_value<move_only_test>(i)});
831 BOOST_CHECK_EQUAL(map_move.size(), nb_values * 2);
832 BOOST_CHECK(map_move == utils::get_filled_hash_map<HMap>(nb_values * 2));
839 BOOST_CHECK(map.
empty());
840 BOOST_CHECK(map_move.
empty());
842 BOOST_CHECK(map.
find(
"") == map.
end());
843 BOOST_CHECK(map_move.
find(
"") == map_move.
end());
851 const std::size_t nb_values = 100;
852 HMap map = utils::get_filled_hash_map<HMap>(nb_values);
853 HMap map_move = utils::get_filled_hash_map<HMap>(1);
854 map_move = std::move(map);
856 BOOST_CHECK(map_move == utils::get_filled_hash_map<HMap>(nb_values));
857 BOOST_CHECK(map == (HMap()));
859 for (std::size_t i = nb_values; i < nb_values * 2; i++) {
861 {utils::get_key<std::string>(i), utils::get_value<move_only_test>(i)});
864 BOOST_CHECK_EQUAL(map_move.size(), nb_values * 2);
865 BOOST_CHECK(map_move == utils::get_filled_hash_map<HMap>(nb_values * 2));
871 map_move = (std::move(map));
873 BOOST_CHECK(map.
empty());
874 BOOST_CHECK(map_move.
empty());
876 BOOST_CHECK(map.
find(
"") == map.
end());
877 BOOST_CHECK(map_move.
find(
"") == map_move.
end());
883 HMap map = {{
"Key1",
"Value1"}, {
"Key2",
"Value2"}, {
"Key3",
"Value3"}};
884 HMap map_move(std::move(map));
886 BOOST_CHECK_EQUAL(map_move.size(), 3);
887 BOOST_CHECK_EQUAL(map.size(), 0);
889 map = {{
"Key4",
"Value4"}, {
"Key5",
"Value5"}};
890 BOOST_CHECK(map == (HMap({{
"Key4",
"Value4"}, {
"Key5",
"Value5"}})));
896 HMap map = {{
"Key1",
"Value1"}, {
"Key2",
"Value2"}, {
"Key3",
"Value3"}};
897 HMap map_move = std::move(map);
899 BOOST_CHECK_EQUAL(map_move.size(), 3);
900 BOOST_CHECK_EQUAL(map.size(), 0);
902 map = {{
"Key4",
"Value4"}, {
"Key5",
"Value5"}};
903 BOOST_CHECK(map == (HMap({{
"Key4",
"Value4"}, {
"Key5",
"Value5"}})));
909 const std::size_t nb_values = 100;
910 HMap map = utils::get_filled_hash_map<HMap>(nb_values);
911 HMap map_move(std::move(map));
913 BOOST_CHECK(map == (HMap()));
914 BOOST_CHECK_EQUAL(map.size(), 0);
915 BOOST_CHECK_EQUAL(map.bucket_count(), 0);
916 BOOST_CHECK_EQUAL(map.erase(
"a"), 0);
917 BOOST_CHECK(map.find(
"a") == map.end());
919 for (std::size_t i = 0; i < nb_values; i++) {
921 {utils::get_key<std::string>(i), utils::get_value<move_only_test>(i)});
924 BOOST_CHECK_EQUAL(map.size(), nb_values);
925 BOOST_CHECK(map == map_move);
931 const std::size_t nb_values = 100;
932 HMap map = utils::get_filled_hash_map<HMap>(nb_values);
934 map_move = std::move(map);
936 BOOST_CHECK(map == (HMap()));
937 BOOST_CHECK_EQUAL(map.size(), 0);
938 BOOST_CHECK_EQUAL(map.bucket_count(), 0);
939 BOOST_CHECK_EQUAL(map.erase(
"a"), 0);
940 BOOST_CHECK(map.find(
"a") == map.end());
942 for (std::size_t i = 0; i < nb_values; i++) {
944 {utils::get_key<std::string>(i), utils::get_value<move_only_test>(i)});
947 BOOST_CHECK_EQUAL(map.size(), nb_values);
948 BOOST_CHECK(map == map_move);
954 const std::size_t nb_values = 100;
955 HMap map = utils::get_filled_hash_map<HMap>(nb_values);
959 HMap map_copy3 = utils::get_filled_hash_map<HMap>(1);
962 BOOST_CHECK(map == map_copy);
965 BOOST_CHECK(map_copy == map_copy2);
966 BOOST_CHECK(map_copy == map_copy3);
973 BOOST_CHECK(map.
empty());
974 BOOST_CHECK(map_copy.
empty());
976 BOOST_CHECK(map.
find(
"") == map.
end());
977 BOOST_CHECK(map_copy.
find(
"") == map_copy.
end());
985 BOOST_CHECK(map.
empty());
986 BOOST_CHECK(map_copy.
empty());
988 BOOST_CHECK(map.
find(
"") == map.
end());
989 BOOST_CHECK(map_copy.
find(
"") == map_copy.
end());
999 BOOST_CHECK_EQUAL(map.
at(0), 10);
1000 BOOST_CHECK_EQUAL(map.
at(-2), 20);
1022 BOOST_REQUIRE_EQUAL(std::distance(it_pair.first, it_pair.second), 1);
1023 BOOST_CHECK_EQUAL(it_pair.first->second, 10);
1026 BOOST_CHECK(it_pair.first == it_pair.second);
1027 BOOST_CHECK(it_pair.first == map.
end());
1037 BOOST_CHECK_EQUAL(map[0], 10);
1038 BOOST_CHECK_EQUAL(map[-2], 20);
1039 BOOST_CHECK_EQUAL(map[2], std::int64_t());
1041 BOOST_CHECK_EQUAL(map.
size(), 3);
1057 {1, 10}, {8, 80}, {3, 30}}));
1063 {4, 40}, {5, 50}, {6, 60}}));
1065 {1, 10}, {8, 80}, {3, 30}, {4, 40}}));
1077 {1, 10}, {8, 80}, {3, 30}}));
1084 {1, 10}, {8, 80}, {3, 30}, {4, 40}}));
1099 auto empty_map_deserialized = decltype(empty_map)::
deserialize(dserial,
true);
1100 BOOST_CHECK(empty_map_deserialized == empty_map);
1103 empty_map_deserialized = decltype(empty_map)::
deserialize(dserial2,
false);
1104 BOOST_CHECK(empty_map_deserialized == empty_map);
1111 const std::size_t nb_values = 1000;
1114 for (std::size_t i = 0; i < nb_values + 40; i++) {
1116 {utils::get_key<std::int32_t>(i), utils::get_value<move_only_test>(i)});
1119 for (std::size_t i = nb_values; i < nb_values + 40; i++) {
1120 map.
erase(utils::get_key<std::int32_t>(i));
1122 BOOST_CHECK_EQUAL(map.
size(), nb_values);
1128 auto map_deserialized = decltype(map)::
deserialize(dserial,
true);
1129 BOOST_CHECK(map == map_deserialized);
1132 map_deserialized = decltype(map)::
deserialize(dserial2,
false);
1133 BOOST_CHECK(map_deserialized == map);
1140 std::equal_to<std::int32_t>,
1143 std::runtime_error);
1150 const std::size_t nb_values = 1000;
1153 std::equal_to<std::int32_t>,
1156 for (std::size_t i = 0; i < nb_values + 40; i++) {
1158 {utils::get_key<std::int32_t>(i), utils::get_value<move_only_test>(i)});
1161 for (std::size_t i = nb_values; i < nb_values + 40; i++) {
1162 map.
erase(utils::get_key<std::int32_t>(i));
1164 BOOST_CHECK_EQUAL(map.
size(), nb_values);
1170 auto map_deserialized = decltype(map)::
deserialize(dserial,
true);
1171 BOOST_CHECK(map == map_deserialized);
1174 map_deserialized = decltype(map)::
deserialize(dserial2,
false);
1175 BOOST_CHECK(map_deserialized == map);
1182 std::runtime_error);
1188 struct hash_str_diff {
1189 std::size_t operator()(
const std::string& str)
const {
1190 return std::hash<std::string>()(str) + 123;
1194 const std::size_t nb_values = 1000;
1197 for (std::size_t i = 0; i < nb_values; i++) {
1199 {utils::get_key<std::string>(i), utils::get_value<move_only_test>(i)});
1201 BOOST_CHECK_EQUAL(map.
size(), nb_values);
1207 auto map_deserialized =
1211 BOOST_CHECK_EQUAL(map_deserialized.size(), map.
size());
1212 for (
const auto& val : map) {
1213 BOOST_CHECK(map_deserialized.find(val.first) != map_deserialized.end());
1224 std::size_t operator()(std::uint64_t v)
const {
1226 return std::hash<std::uint64_t>()(v - 1);
1228 return std::hash<std::uint64_t>()(v);
1234 bool operator()(std::uint64_t lhs, std::uint64_t rhs)
const {
1235 if (lhs % 2u == 1u) {
1239 if (rhs % 2u == 1u) {
1248 BOOST_CHECK(map.
insert({2, 10}).second);
1249 BOOST_CHECK_EQUAL(map.
at(2), 10);
1250 BOOST_CHECK_EQUAL(map.
at(3), 10);
1251 BOOST_CHECK(!map.
insert({3, 10}).second);
1253 BOOST_CHECK_EQUAL(map.
size(), 1);
1261 std::size_t operator()(
const std::unique_ptr<int>& p)
const {
1262 return std::hash<std::uintptr_t>()(
1263 reinterpret_cast<std::uintptr_t
>(p.get()));
1266 std::size_t operator()(std::uintptr_t p)
const {
1267 return std::hash<std::uintptr_t>()(p);
1270 std::size_t operator()(
const int*
const& p)
const {
1271 return std::hash<std::uintptr_t>()(
reinterpret_cast<std::uintptr_t
>(p));
1275 struct equal_to_ptr {
1278 bool operator()(
const std::unique_ptr<int>& p1,
1279 const std::unique_ptr<int>& p2)
const {
1283 bool operator()(
const std::unique_ptr<int>& p1, std::uintptr_t p2)
const {
1284 return reinterpret_cast<std::uintptr_t
>(p1.get()) == p2;
1287 bool operator()(std::uintptr_t p1,
const std::unique_ptr<int>& p2)
const {
1288 return p1 ==
reinterpret_cast<std::uintptr_t
>(p2.get());
1291 bool operator()(
const std::unique_ptr<int>& p1,
1292 const int*
const& p2)
const {
1293 return p1.get() == p2;
1296 bool operator()(
const int*
const& p1,
1297 const std::unique_ptr<int>& p2)
const {
1298 return p1 == p2.get();
1302 std::unique_ptr<int> ptr1(
new int(1));
1303 std::unique_ptr<int> ptr2(
new int(2));
1304 std::unique_ptr<int> ptr3(
new int(3));
1307 const std::uintptr_t addr1 =
reinterpret_cast<std::uintptr_t
>(ptr1.get());
1308 const int*
const addr2 = ptr2.get();
1309 const int*
const addr_unknown = &other;
1312 map.
insert({std::move(ptr1), 4});
1313 map.
insert({std::move(ptr2), 5});
1314 map.
insert({std::move(ptr3), 6});
1316 BOOST_CHECK_EQUAL(map.
size(), 3);
1318 BOOST_CHECK_EQUAL(map.
at(addr1), 4);
1319 BOOST_CHECK_EQUAL(map.
at(addr2), 5);
1322 BOOST_REQUIRE(map.
find(addr1) != map.
end());
1323 BOOST_CHECK_EQUAL(*map.
find(addr1)->first, 1);
1325 BOOST_REQUIRE(map.
find(addr2) != map.
end());
1326 BOOST_CHECK_EQUAL(*map.
find(addr2)->first, 2);
1328 BOOST_CHECK(map.
find(addr_unknown) == map.
end());
1330 BOOST_CHECK_EQUAL(map.
count(addr1), 1);
1331 BOOST_CHECK_EQUAL(map.
count(addr2), 1);
1332 BOOST_CHECK_EQUAL(map.
count(addr_unknown), 0);
1334 BOOST_CHECK_EQUAL(map.
erase(addr1), 1);
1335 BOOST_CHECK_EQUAL(map.
erase(addr2), 1);
1336 BOOST_CHECK_EQUAL(map.
erase(addr_unknown), 0);
1338 BOOST_CHECK_EQUAL(map.
size(), 1);
1348 BOOST_CHECK_EQUAL(map.
size(), 0);
1350 BOOST_CHECK(map.
empty());
1352 BOOST_CHECK(map.
begin() == map.
end());
1356 BOOST_CHECK(map.
find(
"") == map.
end());
1357 BOOST_CHECK(map.
find(
"test") == map.
end());
1359 BOOST_CHECK_EQUAL(map.
count(
""), 0);
1360 BOOST_CHECK_EQUAL(map.
count(
"test"), 0);
1363 BOOST_CHECK(!map.
contains(
"test"));
1369 BOOST_CHECK(range.first == range.second);
1371 BOOST_CHECK_EQUAL(map.
erase(
"test"), 0);
1374 BOOST_CHECK_EQUAL(map[
"new value"],
int{});
1382 {1, -1}, {2, -2}, {3, -3}, {4, -4}, {5, -5}, {6, -6}};
1430 BOOST_REQUIRE_EQUAL(std::distance(it_range.first, it_range.second), 1);
1431 BOOST_CHECK_EQUAL(it_range.first->second, -3);
1434 BOOST_REQUIRE_EQUAL(
1435 std::distance(it_range_const.first, it_range_const.second), 1);
1436 BOOST_CHECK_EQUAL(it_range_const.first->second, -3);
1440 BOOST_CHECK_EQUAL(std::distance(it_range.first, it_range.second), 0);
1455 auto it = map.find(4);
1456 BOOST_CHECK(it != map.end());
1458 BOOST_CHECK(map.size() == 0);
1462 BOOST_AUTO_TEST_SUITE_END()