1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
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
15 // unordered_multimap(const unordered_multimap& u);
17 #include <unordered_map>
25 #include "test_macros.h"
26 #include "../../../check_consecutive.h"
27 #include "../../../test_compare.h"
28 #include "../../../test_hash.h"
29 #include "test_allocator.h"
30 #include "min_allocator.h"
35 typedef std::unordered_multimap
<int, std::string
,
38 test_allocator
<std::pair
<const int, std::string
> >
40 typedef std::pair
<int, std::string
> P
;
50 C
c0(a
, a
+ sizeof(a
)/sizeof(a
[0]),
53 test_equal_to
<int>(9),
54 test_allocator
<std::pair
<const int, std::string
> >(10)
57 LIBCPP_ASSERT(c
.bucket_count() == 7);
58 assert(c
.size() == 6);
59 std::multiset
<std::string
> s
;
62 CheckConsecutiveKeys
<C::const_iterator
>(c
.find(1), c
.end(), 1, s
);
65 CheckConsecutiveKeys
<C::const_iterator
>(c
.find(2), c
.end(), 2, s
);
67 CheckConsecutiveKeys
<C::const_iterator
>(c
.find(3), c
.end(), 3, s
);
69 CheckConsecutiveKeys
<C::const_iterator
>(c
.find(4), c
.end(), 4, s
);
70 assert(c
.hash_function() == test_hash
<int>(8));
71 assert(c
.key_eq() == test_equal_to
<int>(9));
72 assert(c
.get_allocator() ==
73 (test_allocator
<std::pair
<const int, std::string
> >(10)));
75 assert(static_cast<std::size_t>(std::distance(c
.begin(), c
.end())) == c
.size());
76 assert(static_cast<std::size_t>(std::distance(c
.cbegin(), c
.cend())) == c
.size());
77 assert(std::fabs(c
.load_factor() - (float)c
.size()/c
.bucket_count()) < FLT_EPSILON
);
78 assert(c
.max_load_factor() == 1);
80 #if TEST_STD_VER >= 11
82 typedef std::unordered_multimap
<int, std::string
,
85 other_allocator
<std::pair
<const int, std::string
> >
87 typedef std::pair
<int, std::string
> P
;
97 C
c0(a
, a
+ sizeof(a
)/sizeof(a
[0]),
100 test_equal_to
<int>(9),
101 other_allocator
<std::pair
<const int, std::string
> >(10)
104 LIBCPP_ASSERT(c
.bucket_count() == 7);
105 assert(c
.size() == 6);
106 std::multiset
<std::string
> s
;
109 CheckConsecutiveKeys
<C::const_iterator
>(c
.find(1), c
.end(), 1, s
);
112 CheckConsecutiveKeys
<C::const_iterator
>(c
.find(2), c
.end(), 2, s
);
114 CheckConsecutiveKeys
<C::const_iterator
>(c
.find(3), c
.end(), 3, s
);
116 CheckConsecutiveKeys
<C::const_iterator
>(c
.find(4), c
.end(), 4, s
);
117 assert(c
.hash_function() == test_hash
<int>(8));
118 assert(c
.key_eq() == test_equal_to
<int>(9));
119 assert(c
.get_allocator() ==
120 (other_allocator
<std::pair
<const int, std::string
> >(-2)));
122 assert(static_cast<std::size_t>(std::distance(c
.begin(), c
.end())) == c
.size());
123 assert(static_cast<std::size_t>(std::distance(c
.cbegin(), c
.cend())) == c
.size());
124 assert(std::fabs(c
.load_factor() - (float)c
.size()/c
.bucket_count()) < FLT_EPSILON
);
125 assert(c
.max_load_factor() == 1);
128 typedef std::unordered_multimap
<int, std::string
,
131 min_allocator
<std::pair
<const int, std::string
> >
133 typedef std::pair
<int, std::string
> P
;
143 C
c0(a
, a
+ sizeof(a
)/sizeof(a
[0]),
146 test_equal_to
<int>(9),
147 min_allocator
<std::pair
<const int, std::string
> >()
150 LIBCPP_ASSERT(c
.bucket_count() == 7);
151 assert(c
.size() == 6);
152 std::multiset
<std::string
> s
;
155 CheckConsecutiveKeys
<C::const_iterator
>(c
.find(1), c
.end(), 1, s
);
158 CheckConsecutiveKeys
<C::const_iterator
>(c
.find(2), c
.end(), 2, s
);
160 CheckConsecutiveKeys
<C::const_iterator
>(c
.find(3), c
.end(), 3, s
);
162 CheckConsecutiveKeys
<C::const_iterator
>(c
.find(4), c
.end(), 4, s
);
163 assert(c
.hash_function() == test_hash
<int>(8));
164 assert(c
.key_eq() == test_equal_to
<int>(9));
165 assert(c
.get_allocator() ==
166 (min_allocator
<std::pair
<const int, std::string
> >()));
168 assert(static_cast<std::size_t>(std::distance(c
.begin(), c
.end())) == c
.size());
169 assert(static_cast<std::size_t>(std::distance(c
.cbegin(), c
.cend())) == c
.size());
170 assert(std::fabs(c
.load_factor() - (float)c
.size()/c
.bucket_count()) < FLT_EPSILON
);
171 assert(c
.max_load_factor() == 1);