[Utils] Identity map module-level debug info on first use in CloneFunction* (#118627)
[llvm-project.git] / libcxx / test / std / containers / unord / unord.set / unord.set.cnstr / copy.pass.cpp
blob8a675950d9baa04cb9983d573a54923750ec45e8
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 //===----------------------------------------------------------------------===//
9 // <unordered_set>
11 // template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
12 // class Alloc = allocator<Value>>
13 // class unordered_set
15 // unordered_set(const unordered_set& u);
17 #include <unordered_set>
18 #include <cassert>
19 #include <cfloat>
20 #include <cmath>
21 #include <cstddef>
23 #include "test_macros.h"
24 #include "../../../test_compare.h"
25 #include "../../../test_hash.h"
26 #include "test_allocator.h"
27 #include "min_allocator.h"
29 int main(int, char**)
32 typedef std::unordered_set<int,
33 test_hash<int>,
34 test_equal_to<int>,
35 test_allocator<int>
36 > C;
37 typedef int P;
38 P a[] =
40 P(1),
41 P(2),
42 P(3),
43 P(4),
44 P(1),
45 P(2)
47 C c0(a, a + sizeof(a)/sizeof(a[0]),
49 test_hash<int>(8),
50 test_equal_to<int>(9),
51 test_allocator<int>(10)
53 C c = c0;
54 LIBCPP_ASSERT(c.bucket_count() == 7);
55 assert(c.size() == 4);
56 assert(c.count(1) == 1);
57 assert(c.count(2) == 1);
58 assert(c.count(3) == 1);
59 assert(c.count(4) == 1);
60 assert(c.hash_function() == test_hash<int>(8));
61 assert(c.key_eq() == test_equal_to<int>(9));
62 assert(c.get_allocator() == test_allocator<int>(10));
63 assert(!c.empty());
64 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
65 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
66 assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
67 assert(c.max_load_factor() == 1);
69 #if TEST_STD_VER >= 11
71 typedef std::unordered_set<int,
72 test_hash<int>,
73 test_equal_to<int>,
74 other_allocator<int>
75 > C;
76 typedef int P;
77 P a[] =
79 P(1),
80 P(2),
81 P(3),
82 P(4),
83 P(1),
84 P(2)
86 C c0(a, a + sizeof(a)/sizeof(a[0]),
88 test_hash<int>(8),
89 test_equal_to<int>(9),
90 other_allocator<int>(10)
92 C c = c0;
93 LIBCPP_ASSERT(c.bucket_count() == 7);
94 assert(c.size() == 4);
95 assert(c.count(1) == 1);
96 assert(c.count(2) == 1);
97 assert(c.count(3) == 1);
98 assert(c.count(4) == 1);
99 assert(c.hash_function() == test_hash<int>(8));
100 assert(c.key_eq() == test_equal_to<int>(9));
101 assert(c.get_allocator() == other_allocator<int>(-2));
102 assert(!c.empty());
103 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
104 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
105 assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
106 assert(c.max_load_factor() == 1);
109 typedef std::unordered_set<int,
110 test_hash<int>,
111 test_equal_to<int>,
112 min_allocator<int>
113 > C;
114 typedef int P;
115 P a[] =
117 P(1),
118 P(2),
119 P(3),
120 P(4),
121 P(1),
122 P(2)
124 C c0(a, a + sizeof(a)/sizeof(a[0]),
126 test_hash<int>(8),
127 test_equal_to<int>(9),
128 min_allocator<int>()
130 C c = c0;
131 LIBCPP_ASSERT(c.bucket_count() == 7);
132 assert(c.size() == 4);
133 assert(c.count(1) == 1);
134 assert(c.count(2) == 1);
135 assert(c.count(3) == 1);
136 assert(c.count(4) == 1);
137 assert(c.hash_function() == test_hash<int>(8));
138 assert(c.key_eq() == test_equal_to<int>(9));
139 assert(c.get_allocator() == min_allocator<int>());
140 assert(!c.empty());
141 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
142 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
143 assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
144 assert(c.max_load_factor() == 1);
146 #endif
148 return 0;