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// UNSUPPORTED: c++03
10
11// <unordered_set>
12
13// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
14// class Alloc = allocator<Value>>
15// class unordered_set
16
17// unordered_set(unordered_set&& u, const allocator_type& a);
18
19#include <unordered_set>
20#include <cassert>
21#include <cfloat>
22#include <cmath>
23#include <cstddef>
24
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"
30
31int main(int, char**)
32{
33 {
34 typedef int P;
35 typedef test_allocator<int> A;
36 typedef std::unordered_set<int,
37 test_hash<int>,
38 test_equal_to<int>,
39 A
40 > C;
41 P a[] =
42 {
43 P(1),
44 P(2),
45 P(3),
46 P(4),
47 P(1),
48 P(2)
49 };
50 C c0(a, a + sizeof(a)/sizeof(a[0]),
51 7,
52 test_hash<int>(8),
53 test_equal_to<int>(9),
54 A(10)
55 );
56 C c(std::move(c0), A(12));
57 assert(c.bucket_count() >= 5);
58 assert(c.size() == 4);
59 assert(c.count(1) == 1);
60 assert(c.count(2) == 1);
61 assert(c.count(3) == 1);
62 assert(c.count(4) == 1);
63 assert(c.hash_function() == test_hash<int>(8));
64 assert(c.key_eq() == test_equal_to<int>(9));
65 assert(c.get_allocator() == A(12));
66 assert(!c.empty());
67 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
68 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
69 assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
70 assert(c.max_load_factor() == 1);
71
72 assert(c0.empty());
73 }
74 {
75 typedef int P;
76 typedef test_allocator<int> A;
77 typedef std::unordered_set<int,
78 test_hash<int>,
79 test_equal_to<int>,
80 A
81 > C;
82 P a[] =
83 {
84 P(1),
85 P(2),
86 P(3),
87 P(4),
88 P(1),
89 P(2)
90 };
91 C c0(a, a + sizeof(a)/sizeof(a[0]),
92 7,
93 test_hash<int>(8),
94 test_equal_to<int>(9),
95 A(10)
96 );
97 C c(std::move(c0), A(10));
98 assert(c.bucket_count() >= 5);
99 assert(c.size() == 4);
100 assert(c.count(1) == 1);
101 assert(c.count(2) == 1);
102 assert(c.count(3) == 1);
103 assert(c.count(4) == 1);
104 assert(c.hash_function() == test_hash<int>(8));
105 assert(c.key_eq() == test_equal_to<int>(9));
106 assert(c.get_allocator() == A(10));
107 assert(!c.empty());
108 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
109 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
110 assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
111 assert(c.max_load_factor() == 1);
112
113 assert(c0.empty());
114 }
115 {
116 typedef int P;
117 typedef min_allocator<int> A;
118 typedef std::unordered_set<int,
119 test_hash<int>,
120 test_equal_to<int>,
121 A
122 > C;
123 P a[] =
124 {
125 P(1),
126 P(2),
127 P(3),
128 P(4),
129 P(1),
130 P(2)
131 };
132 C c0(a, a + sizeof(a)/sizeof(a[0]),
133 7,
134 test_hash<int>(8),
135 test_equal_to<int>(9),
136 A()
137 );
138 C c(std::move(c0), A());
139 assert(c.bucket_count() >= 5);
140 assert(c.size() == 4);
141 assert(c.count(1) == 1);
142 assert(c.count(2) == 1);
143 assert(c.count(3) == 1);
144 assert(c.count(4) == 1);
145 assert(c.hash_function() == test_hash<int>(8));
146 assert(c.key_eq() == test_equal_to<int>(9));
147 assert(c.get_allocator() == A());
148 assert(!c.empty());
149 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
150 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
151 assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
152 assert(c.max_load_factor() == 1);
153
154 assert(c0.empty());
155 }
156
157 return 0;
158}
159

source code of libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/move_alloc.pass.cpp