]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/containers/unord/unord.set/unord.set.cnstr/assign_copy.pass.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / std / containers / unord / unord.set / unord.set.cnstr / assign_copy.pass.cpp
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <unordered_set>
11
12 // template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
13 //           class Alloc = allocator<Value>>
14 // class unordered_set
15
16 // unordered_set& operator=(const unordered_set& u);
17
18 #include <unordered_set>
19 #include <cassert>
20 #include <cfloat>
21 #include <cstddef>
22
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"
28
29 int main()
30 {
31     {
32         typedef test_allocator<int> A;
33         typedef std::unordered_set<int,
34                                    test_hash<std::hash<int> >,
35                                    test_compare<std::equal_to<int> >,
36                                    A
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<std::hash<int> >(8),
51             test_compare<std::equal_to<int> >(9),
52             A(10)
53            );
54         C c(a, a + 2,
55             7,
56             test_hash<std::hash<int> >(2),
57             test_compare<std::equal_to<int> >(3),
58             A(4)
59            );
60         c = c0;
61         LIBCPP_ASSERT(c.bucket_count() == 7);
62         assert(c.size() == 4);
63         assert(c.count(1) == 1);
64         assert(c.count(2) == 1);
65         assert(c.count(3) == 1);
66         assert(c.count(4) == 1);
67         assert(c.hash_function() == test_hash<std::hash<int> >(8));
68         assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
69         assert(c.get_allocator() == A(4));
70         assert(!c.empty());
71         assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
72         assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
73         assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
74         assert(c.max_load_factor() == 1);
75     }
76     {
77         typedef std::unordered_set<int> C;
78         typedef int P;
79         P a[] =
80         {
81             P(1),
82             P(2),
83             P(3),
84             P(4),
85             P(1),
86             P(2)
87         };
88         C c(a, a + sizeof(a)/sizeof(a[0]));
89         C *p = &c;
90         c = *p;
91         assert(c.size() == 4);
92         assert(std::is_permutation(c.begin(), c.end(), a));
93     }
94     {
95         typedef other_allocator<int> A;
96         typedef std::unordered_set<int,
97                                    test_hash<std::hash<int> >,
98                                    test_compare<std::equal_to<int> >,
99                                    A
100                                    > C;
101         typedef int P;
102         P a[] =
103         {
104             P(1),
105             P(2),
106             P(3),
107             P(4),
108             P(1),
109             P(2)
110         };
111         C c0(a, a + sizeof(a)/sizeof(a[0]),
112             7,
113             test_hash<std::hash<int> >(8),
114             test_compare<std::equal_to<int> >(9),
115             A(10)
116            );
117         C c(a, a + 2,
118             7,
119             test_hash<std::hash<int> >(2),
120             test_compare<std::equal_to<int> >(3),
121             A(4)
122            );
123         c = c0;
124         assert(c.bucket_count() >= 5);
125         assert(c.size() == 4);
126         assert(c.count(1) == 1);
127         assert(c.count(2) == 1);
128         assert(c.count(3) == 1);
129         assert(c.count(4) == 1);
130         assert(c.hash_function() == test_hash<std::hash<int> >(8));
131         assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
132         assert(c.get_allocator() == A(10));
133         assert(!c.empty());
134         assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
135         assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
136         assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
137         assert(c.max_load_factor() == 1);
138     }
139 #if TEST_STD_VER >= 11
140     {
141         typedef min_allocator<int> A;
142         typedef std::unordered_set<int,
143                                    test_hash<std::hash<int> >,
144                                    test_compare<std::equal_to<int> >,
145                                    A
146                                    > C;
147         typedef int P;
148         P a[] =
149         {
150             P(1),
151             P(2),
152             P(3),
153             P(4),
154             P(1),
155             P(2)
156         };
157         C c0(a, a + sizeof(a)/sizeof(a[0]),
158             7,
159             test_hash<std::hash<int> >(8),
160             test_compare<std::equal_to<int> >(9),
161             A()
162            );
163         C c(a, a + 2,
164             7,
165             test_hash<std::hash<int> >(2),
166             test_compare<std::equal_to<int> >(3),
167             A()
168            );
169         c = c0;
170         LIBCPP_ASSERT(c.bucket_count() == 7);
171         assert(c.size() == 4);
172         assert(c.count(1) == 1);
173         assert(c.count(2) == 1);
174         assert(c.count(3) == 1);
175         assert(c.count(4) == 1);
176         assert(c.hash_function() == test_hash<std::hash<int> >(8));
177         assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
178         assert(c.get_allocator() == A());
179         assert(!c.empty());
180         assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
181         assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
182         assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
183         assert(c.max_load_factor() == 1);
184     }
185 #endif
186 }