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_set |
14 | |
15 | // explicit unordered_set(const allocator_type& __a); |
16 | |
17 | #include <unordered_set> |
18 | #include <cassert> |
19 | |
20 | #include "test_macros.h" |
21 | #include "../../../NotConstructible.h" |
22 | #include "../../../test_compare.h" |
23 | #include "../../../test_hash.h" |
24 | #include "test_allocator.h" |
25 | #include "min_allocator.h" |
26 | |
27 | int main(int, char**) |
28 | { |
29 | { |
30 | typedef std::unordered_set<NotConstructible, |
31 | test_hash<NotConstructible>, |
32 | test_equal_to<NotConstructible>, |
33 | test_allocator<NotConstructible> |
34 | > C; |
35 | C c(test_allocator<NotConstructible>(10)); |
36 | LIBCPP_ASSERT(c.bucket_count() == 0); |
37 | assert(c.hash_function() == test_hash<NotConstructible>()); |
38 | assert(c.key_eq() == test_equal_to<NotConstructible>()); |
39 | assert(c.get_allocator() == test_allocator<NotConstructible>(10)); |
40 | assert(c.size() == 0); |
41 | assert(c.empty()); |
42 | assert(std::distance(c.begin(), c.end()) == 0); |
43 | assert(c.load_factor() == 0); |
44 | assert(c.max_load_factor() == 1); |
45 | } |
46 | #if TEST_STD_VER >= 11 |
47 | { |
48 | typedef std::unordered_set<NotConstructible, |
49 | test_hash<NotConstructible>, |
50 | test_equal_to<NotConstructible>, |
51 | min_allocator<NotConstructible> |
52 | > C; |
53 | C c(min_allocator<NotConstructible>{}); |
54 | LIBCPP_ASSERT(c.bucket_count() == 0); |
55 | assert(c.hash_function() == test_hash<NotConstructible>()); |
56 | assert(c.key_eq() == test_equal_to<NotConstructible>()); |
57 | assert(c.get_allocator() == min_allocator<NotConstructible>()); |
58 | assert(c.size() == 0); |
59 | assert(c.empty()); |
60 | assert(std::distance(c.begin(), c.end()) == 0); |
61 | assert(c.load_factor() == 0); |
62 | assert(c.max_load_factor() == 1); |
63 | } |
64 | #if TEST_STD_VER > 11 |
65 | { |
66 | typedef NotConstructible T; |
67 | typedef test_hash<T> HF; |
68 | typedef test_equal_to<T> Comp; |
69 | typedef test_allocator<T> A; |
70 | typedef std::unordered_set<T, HF, Comp, A> C; |
71 | |
72 | A a(43); |
73 | C c(3, a); |
74 | LIBCPP_ASSERT(c.bucket_count() == 3); |
75 | assert(c.hash_function() == HF()); |
76 | assert(c.key_eq() == Comp ()); |
77 | assert(c.get_allocator() == a); |
78 | assert(!(c.get_allocator() == A())); |
79 | assert(c.size() == 0); |
80 | assert(c.empty()); |
81 | assert(std::distance(c.begin(), c.end()) == 0); |
82 | assert(c.load_factor() == 0); |
83 | assert(c.max_load_factor() == 1); |
84 | } |
85 | { |
86 | typedef NotConstructible T; |
87 | typedef test_hash<T> HF; |
88 | typedef test_equal_to<T> Comp; |
89 | typedef test_allocator<T> A; |
90 | typedef std::unordered_set<T, HF, Comp, A> C; |
91 | |
92 | HF hf(42); |
93 | A a(43); |
94 | C c(4, hf, a); |
95 | LIBCPP_ASSERT(c.bucket_count() == 4); |
96 | assert(c.hash_function() == hf); |
97 | assert(!(c.hash_function() == HF())); |
98 | assert(c.key_eq() == Comp ()); |
99 | assert(c.get_allocator() == a); |
100 | assert(!(c.get_allocator() == A())); |
101 | assert(c.size() == 0); |
102 | assert(c.empty()); |
103 | assert(std::distance(c.begin(), c.end()) == 0); |
104 | assert(c.load_factor() == 0); |
105 | assert(c.max_load_factor() == 1); |
106 | } |
107 | #endif |
108 | #endif |
109 | |
110 | return 0; |
111 | } |
112 | |