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& operator=(unordered_set&& u);
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 typedef test_allocator<int> A;
34 typedef std::unordered_set<int, test_hash<int>, test_equal_to<int>, A > C;
35 typedef int P;
36 P a[] = {P(1), P(2), P(3), P(4), P(1), P(2)};
37 C c0(a, a + sizeof(a) / sizeof(a[0]), 7, test_hash<int>(8), test_equal_to<int>(9), A(10));
38 C c(a, a + 2, 7, test_hash<int>(2), test_equal_to<int>(3), A(4));
39 c = std::move(c0);
40 LIBCPP_ASSERT(c.bucket_count() == 7);
41 assert(c.size() == 4);
42 assert(c.count(1) == 1);
43 assert(c.count(2) == 1);
44 assert(c.count(3) == 1);
45 assert(c.count(4) == 1);
46 assert(c.hash_function() == test_hash<int>(8));
47 assert(c.key_eq() == test_equal_to<int>(9));
48 assert(c.get_allocator() == A(4));
49 assert(!c.empty());
50 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
51 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
52 assert(fabs(c.load_factor() - (float)c.size() / c.bucket_count()) < FLT_EPSILON);
53 assert(c.max_load_factor() == 1);
54 }
55 {
56 typedef test_allocator<int> A;
57 typedef std::unordered_set<int, test_hash<int>, test_equal_to<int>, A > C;
58 typedef int P;
59 P a[] = {P(1), P(2), P(3), P(4), P(1), P(2)};
60 C c0(a, a + sizeof(a) / sizeof(a[0]), 7, test_hash<int>(8), test_equal_to<int>(9), A(10));
61 C c(a, a + 2, 7, test_hash<int>(2), test_equal_to<int>(3), A(10));
62 C::iterator it0 = c0.begin();
63 c = std::move(c0);
64 LIBCPP_ASSERT(c.bucket_count() == 7);
65 assert(c.size() == 4);
66 assert(c.count(1) == 1);
67 assert(c.count(2) == 1);
68 assert(c.count(3) == 1);
69 assert(c.count(4) == 1);
70 assert(c.hash_function() == test_hash<int>(8));
71 assert(c.key_eq() == test_equal_to<int>(9));
72 assert(c.get_allocator() == A(10));
73 assert(!c.empty());
74 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
75 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
76 assert(fabs(c.load_factor() - (float)c.size() / c.bucket_count()) < FLT_EPSILON);
77 assert(c.max_load_factor() == 1);
78 assert(it0 == c.begin()); // Iterators remain valid
79 }
80 {
81 typedef other_allocator<int> A;
82 typedef std::unordered_set<int, test_hash<int>, test_equal_to<int>, A > C;
83 typedef int P;
84 P a[] = {P(1), P(2), P(3), P(4), P(1), P(2)};
85 C c0(a, a + sizeof(a) / sizeof(a[0]), 7, test_hash<int>(8), test_equal_to<int>(9), A(10));
86 C c(a, a + 2, 7, test_hash<int>(2), test_equal_to<int>(3), A(4));
87 C::iterator it0 = c0.begin();
88 c = std::move(c0);
89 LIBCPP_ASSERT(c.bucket_count() == 7);
90 assert(c.size() == 4);
91 assert(c.count(1) == 1);
92 assert(c.count(2) == 1);
93 assert(c.count(3) == 1);
94 assert(c.count(4) == 1);
95 assert(c.hash_function() == test_hash<int>(8));
96 assert(c.key_eq() == test_equal_to<int>(9));
97 assert(c.get_allocator() == A(10));
98 assert(!c.empty());
99 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
100 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
101 assert(fabs(c.load_factor() - (float)c.size() / c.bucket_count()) < FLT_EPSILON);
102 assert(c.max_load_factor() == 1);
103 assert(it0 == c.begin()); // Iterators remain valid
104 }
105 {
106 typedef min_allocator<int> A;
107 typedef std::unordered_set<int, test_hash<int>, test_equal_to<int>, A > C;
108 typedef int P;
109 P a[] = {P(1), P(2), P(3), P(4), P(1), P(2)};
110 C c0(a, a + sizeof(a) / sizeof(a[0]), 7, test_hash<int>(8), test_equal_to<int>(9), A());
111 C c(a, a + 2, 7, test_hash<int>(2), test_equal_to<int>(3), A());
112 C::iterator it0 = c0.begin();
113 c = std::move(c0);
114 LIBCPP_ASSERT(c.bucket_count() == 7);
115 assert(c.size() == 4);
116 assert(c.count(1) == 1);
117 assert(c.count(2) == 1);
118 assert(c.count(3) == 1);
119 assert(c.count(4) == 1);
120 assert(c.hash_function() == test_hash<int>(8));
121 assert(c.key_eq() == test_equal_to<int>(9));
122 assert(c.get_allocator() == A());
123 assert(!c.empty());
124 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
125 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
126 assert(fabs(c.load_factor() - (float)c.size() / c.bucket_count()) < FLT_EPSILON);
127 assert(c.max_load_factor() == 1);
128 assert(it0 == c.begin()); // Iterators remain valid
129 }
130
131 return 0;
132}
133

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