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 Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
12 // class Alloc = allocator<Value>>
13 // class unordered_multiset
15 // unordered_multiset(const unordered_multiset& u);
17 #include <unordered_set>
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"
33 typedef std::unordered_multiset
<int,
48 C
c0(a
, a
+ sizeof(a
)/sizeof(a
[0]),
51 test_equal_to
<int>(9),
52 test_allocator
<int>(10)
55 LIBCPP_ASSERT(c
.bucket_count() == 7);
56 assert(c
.size() == 6);
57 CheckConsecutiveValues
<C::const_iterator
>(c
.find(1), c
.end(), 1, 2);
58 CheckConsecutiveValues
<C::const_iterator
>(c
.find(2), c
.end(), 2, 2);
59 CheckConsecutiveValues
<C::const_iterator
>(c
.find(3), c
.end(), 3, 1);
60 CheckConsecutiveValues
<C::const_iterator
>(c
.find(4), c
.end(), 4, 1);
61 assert(c
.hash_function() == test_hash
<int>(8));
62 assert(c
.key_eq() == test_equal_to
<int>(9));
63 assert(c
.get_allocator() == test_allocator
<int>(10));
65 assert(static_cast<std::size_t>(std::distance(c
.begin(), c
.end())) == c
.size());
66 assert(static_cast<std::size_t>(std::distance(c
.cbegin(), c
.cend())) == c
.size());
67 assert(std::fabs(c
.load_factor() - (float)c
.size()/c
.bucket_count()) < FLT_EPSILON
);
68 assert(c
.max_load_factor() == 1);
70 #if TEST_STD_VER >= 11
72 typedef std::unordered_multiset
<int,
87 C
c0(a
, a
+ sizeof(a
)/sizeof(a
[0]),
90 test_equal_to
<int>(9),
91 other_allocator
<int>(10)
94 LIBCPP_ASSERT(c
.bucket_count() == 7);
95 assert(c
.size() == 6);
96 CheckConsecutiveValues
<C::const_iterator
>(c
.find(1), c
.end(), 1, 2);
97 CheckConsecutiveValues
<C::const_iterator
>(c
.find(2), c
.end(), 2, 2);
98 CheckConsecutiveValues
<C::const_iterator
>(c
.find(3), c
.end(), 3, 1);
99 CheckConsecutiveValues
<C::const_iterator
>(c
.find(4), c
.end(), 4, 1);
100 assert(c
.hash_function() == test_hash
<int>(8));
101 assert(c
.key_eq() == test_equal_to
<int>(9));
102 assert(c
.get_allocator() == other_allocator
<int>(-2));
104 assert(static_cast<std::size_t>(std::distance(c
.begin(), c
.end())) == c
.size());
105 assert(static_cast<std::size_t>(std::distance(c
.cbegin(), c
.cend())) == c
.size());
106 assert(std::fabs(c
.load_factor() - (float)c
.size()/c
.bucket_count()) < FLT_EPSILON
);
107 assert(c
.max_load_factor() == 1);
110 typedef std::unordered_multiset
<int,
125 C
c0(a
, a
+ sizeof(a
)/sizeof(a
[0]),
128 test_equal_to
<int>(9),
132 LIBCPP_ASSERT(c
.bucket_count() == 7);
133 assert(c
.size() == 6);
134 CheckConsecutiveValues
<C::const_iterator
>(c
.find(1), c
.end(), 1, 2);
135 CheckConsecutiveValues
<C::const_iterator
>(c
.find(2), c
.end(), 2, 2);
136 CheckConsecutiveValues
<C::const_iterator
>(c
.find(3), c
.end(), 3, 1);
137 CheckConsecutiveValues
<C::const_iterator
>(c
.find(4), c
.end(), 4, 1);
138 assert(c
.hash_function() == test_hash
<int>(8));
139 assert(c
.key_eq() == test_equal_to
<int>(9));
140 assert(c
.get_allocator() == min_allocator
<int>());
142 assert(static_cast<std::size_t>(std::distance(c
.begin(), c
.end())) == c
.size());
143 assert(static_cast<std::size_t>(std::distance(c
.cbegin(), c
.cend())) == c
.size());
144 assert(std::fabs(c
.load_factor() - (float)c
.size()/c
.bucket_count()) < FLT_EPSILON
);
145 assert(c
.max_load_factor() == 1);