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_set> |
10 | |
11 | // template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, |
12 | // class Alloc = allocator<Value>> |
13 | // class unordered_multiset |
14 | |
15 | // unordered_multiset(const unordered_multiset& u, const allocator_type& a); |
16 | |
17 | #include <unordered_set> |
18 | #include <cassert> |
19 | #include <cfloat> |
20 | #include <cmath> |
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 | { |
33 | typedef std::unordered_multiset<int, |
34 | test_hash<int>, |
35 | test_equal_to<int>, |
36 | test_allocator<int> |
37 | > C; |
38 | typedef int P; |
39 | P a[] = |
40 | { |
41 | P(1), |
42 | P(2), |
43 | P(3), |
44 | P(4), |
45 | P(1), |
46 | P(2) |
47 | }; |
48 | C c0(a, a + sizeof(a)/sizeof(a[0]), |
49 | 7, |
50 | test_hash<int>(8), |
51 | test_equal_to<int>(9), |
52 | test_allocator<int>(10) |
53 | ); |
54 | C c(c0, test_allocator<int>(5)); |
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>(5)); |
64 | assert(!c.empty()); |
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); |
69 | } |
70 | #if TEST_STD_VER >= 11 |
71 | { |
72 | typedef std::unordered_multiset<int, |
73 | test_hash<int>, |
74 | test_equal_to<int>, |
75 | min_allocator<int> |
76 | > C; |
77 | typedef int P; |
78 | P a[] = |
79 | { |
80 | P(1), |
81 | P(2), |
82 | P(3), |
83 | P(4), |
84 | P(1), |
85 | P(2) |
86 | }; |
87 | C c0(a, a + sizeof(a)/sizeof(a[0]), |
88 | 7, |
89 | test_hash<int>(8), |
90 | test_equal_to<int>(9), |
91 | min_allocator<int>() |
92 | ); |
93 | C c(c0, min_allocator<int>()); |
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() == min_allocator<int>()); |
103 | assert(!c.empty()); |
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); |
108 | } |
109 | #endif |
110 | |
111 | return 0; |
112 | } |
113 | |