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_set
15 // unordered_set(const unordered_set& u);
17 #include <unordered_set>
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"
32 typedef std::unordered_set
<int,
47 C
c0(a
, a
+ sizeof(a
)/sizeof(a
[0]),
50 test_equal_to
<int>(9),
51 test_allocator
<int>(10)
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));
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,
86 C
c0(a
, a
+ sizeof(a
)/sizeof(a
[0]),
89 test_equal_to
<int>(9),
90 other_allocator
<int>(10)
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));
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,
124 C
c0(a
, a
+ sizeof(a
)/sizeof(a
[0]),
127 test_equal_to
<int>(9),
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>());
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);