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 //===----------------------------------------------------------------------===//
13 // template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
14 // class Alloc = allocator<Value>>
15 // class unordered_set
17 // unordered_set(unordered_set&& u);
19 #include <unordered_set>
25 #include "test_macros.h"
26 #include "../../../test_compare.h"
27 #include "../../../test_hash.h"
28 #include "test_allocator.h"
29 #include "min_allocator.h"
34 typedef std::unordered_set
<int,
41 test_equal_to
<int>(9),
42 test_allocator
<int>(10)
45 LIBCPP_ASSERT(c
.bucket_count() == 7);
46 assert(c
.size() == 0);
47 assert(c
.hash_function() == test_hash
<int>(8));
48 assert(c
.key_eq() == test_equal_to
<int>(9));
49 assert(c
.get_allocator() == test_allocator
<int>(10));
51 assert(static_cast<std::size_t>(std::distance(c
.begin(), c
.end())) == c
.size());
52 assert(static_cast<std::size_t>(std::distance(c
.cbegin(), c
.cend())) == c
.size());
53 assert(c
.load_factor() == 0);
54 assert(c
.max_load_factor() == 1);
59 typedef std::unordered_set
<int,
74 C
c0(a
, a
+ sizeof(a
)/sizeof(a
[0]),
77 test_equal_to
<int>(9),
78 test_allocator
<int>(10)
80 C::iterator it0
= c0
.begin();
82 assert(it0
== c
.begin()); // Iterators remain valid
83 LIBCPP_ASSERT(c
.bucket_count() == 7);
84 assert(c
.size() == 4);
85 assert(c
.count(1) == 1);
86 assert(c
.count(2) == 1);
87 assert(c
.count(3) == 1);
88 assert(c
.count(4) == 1);
89 assert(c
.hash_function() == test_hash
<int>(8));
90 assert(c
.key_eq() == test_equal_to
<int>(9));
91 assert(c
.get_allocator() == test_allocator
<int>(10));
93 assert(static_cast<std::size_t>(std::distance(c
.begin(), c
.end())) == c
.size());
94 assert(static_cast<std::size_t>(std::distance(c
.cbegin(), c
.cend())) == c
.size());
95 assert(std::fabs(c
.load_factor() - (float)c
.size()/c
.bucket_count()) < FLT_EPSILON
);
96 assert(c
.max_load_factor() == 1);
101 typedef std::unordered_set
<int,
108 test_equal_to
<int>(9),
112 LIBCPP_ASSERT(c
.bucket_count() == 7);
113 assert(c
.size() == 0);
114 assert(c
.hash_function() == test_hash
<int>(8));
115 assert(c
.key_eq() == test_equal_to
<int>(9));
116 assert(c
.get_allocator() == min_allocator
<int>());
118 assert(static_cast<std::size_t>(std::distance(c
.begin(), c
.end())) == c
.size());
119 assert(static_cast<std::size_t>(std::distance(c
.cbegin(), c
.cend())) == c
.size());
120 assert(c
.load_factor() == 0);
121 assert(c
.max_load_factor() == 1);
126 typedef std::unordered_set
<int,
141 C
c0(a
, a
+ sizeof(a
)/sizeof(a
[0]),
144 test_equal_to
<int>(9),
147 C::iterator it0
= c0
.begin();
149 assert(it0
== c
.begin()); // Iterators remain valid
150 LIBCPP_ASSERT(c
.bucket_count() == 7);
151 assert(c
.size() == 4);
152 assert(c
.count(1) == 1);
153 assert(c
.count(2) == 1);
154 assert(c
.count(3) == 1);
155 assert(c
.count(4) == 1);
156 assert(c
.hash_function() == test_hash
<int>(8));
157 assert(c
.key_eq() == test_equal_to
<int>(9));
158 assert(c
.get_allocator() == min_allocator
<int>());
160 assert(static_cast<std::size_t>(std::distance(c
.begin(), c
.end())) == c
.size());
161 assert(static_cast<std::size_t>(std::distance(c
.cbegin(), c
.cend())) == c
.size());
162 assert(std::fabs(c
.load_factor() - (float)c
.size()/c
.bucket_count()) < FLT_EPSILON
);
163 assert(c
.max_load_factor() == 1);