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_multiset
16
17// unordered_multiset& operator=(unordered_multiset&& 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 "../../../check_consecutive.h"
27#include "../../../test_compare.h"
28#include "../../../test_hash.h"
29#include "test_allocator.h"
30#include "min_allocator.h"
31
32int main(int, char**) {
33 {
34 typedef test_allocator<int> A;
35 typedef std::unordered_multiset<int, test_hash<int>, test_equal_to<int>, A > C;
36 typedef int P;
37 P a[] = {P(1), P(2), P(3), P(4), P(1), P(2)};
38 C c0(a, a + sizeof(a) / sizeof(a[0]), 7, test_hash<int>(8), test_equal_to<int>(9), A(10));
39 C c(a, a + 2, 7, test_hash<int>(2), test_equal_to<int>(3), A(4));
40 c = std::move(c0);
41 LIBCPP_ASSERT(c.bucket_count() == 7);
42 assert(c.size() == 6);
43 CheckConsecutiveValues<C::const_iterator>(pos: c.find(x: 1), end: c.end(), value: 1, count: 2);
44 CheckConsecutiveValues<C::const_iterator>(pos: c.find(x: 2), end: c.end(), value: 2, count: 2);
45 CheckConsecutiveValues<C::const_iterator>(pos: c.find(x: 3), end: c.end(), value: 3, count: 1);
46 CheckConsecutiveValues<C::const_iterator>(pos: c.find(x: 4), end: c.end(), value: 4, count: 1);
47 assert(c.hash_function() == test_hash<int>(8));
48 assert(c.key_eq() == test_equal_to<int>(9));
49 assert(c.get_allocator() == A(4));
50 assert(!c.empty());
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(fabs(c.load_factor() - (float)c.size() / c.bucket_count()) < FLT_EPSILON);
54 assert(c.max_load_factor() == 1);
55 }
56 {
57 typedef test_allocator<int> A;
58 typedef std::unordered_multiset<int, test_hash<int>, test_equal_to<int>, A > C;
59 typedef int P;
60 P a[] = {P(1), P(2), P(3), P(4), P(1), P(2)};
61 C c0(a, a + sizeof(a) / sizeof(a[0]), 7, test_hash<int>(8), test_equal_to<int>(9), A(10));
62 C c(a, a + 2, 7, test_hash<int>(2), test_equal_to<int>(3), A(10));
63 C::iterator it0 = c0.begin();
64 c = std::move(c0);
65 LIBCPP_ASSERT(c.bucket_count() == 7);
66 assert(c.size() == 6);
67 assert(c.count(1) == 2);
68 assert(c.count(2) == 2);
69 assert(c.count(3) == 1);
70 assert(c.count(4) == 1);
71 assert(c.hash_function() == test_hash<int>(8));
72 assert(c.key_eq() == test_equal_to<int>(9));
73 assert(c.get_allocator() == A(10));
74 assert(!c.empty());
75 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
76 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
77 assert(fabs(c.load_factor() - (float)c.size() / c.bucket_count()) < FLT_EPSILON);
78 assert(c.max_load_factor() == 1);
79 assert(it0 == c.begin()); // Iterators remain valid
80 }
81 {
82 typedef other_allocator<int> A;
83 typedef std::unordered_multiset<int, test_hash<int>, test_equal_to<int>, A > C;
84 typedef int P;
85 P a[] = {P(1), P(2), P(3), P(4), P(1), P(2)};
86 C c0(a, a + sizeof(a) / sizeof(a[0]), 7, test_hash<int>(8), test_equal_to<int>(9), A(10));
87 C c(a, a + 2, 7, test_hash<int>(2), test_equal_to<int>(3), A(4));
88 C::iterator it0 = c0.begin();
89 c = std::move(c0);
90 LIBCPP_ASSERT(c.bucket_count() == 7);
91 assert(c.size() == 6);
92 assert(c.count(1) == 2);
93 assert(c.count(2) == 2);
94 assert(c.count(3) == 1);
95 assert(c.count(4) == 1);
96 assert(c.hash_function() == test_hash<int>(8));
97 assert(c.key_eq() == test_equal_to<int>(9));
98 assert(c.get_allocator() == A(10));
99 assert(!c.empty());
100 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
101 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
102 assert(fabs(c.load_factor() - (float)c.size() / c.bucket_count()) < FLT_EPSILON);
103 assert(c.max_load_factor() == 1);
104 assert(it0 == c.begin()); // Iterators remain valid
105 }
106 {
107 typedef test_allocator<int> A;
108 typedef std::unordered_multiset<int, test_hash<int>, test_equal_to<int>, A > C;
109 typedef int P;
110 P a[] = {P(1), P(2), P(3), P(4), P(1), P(2)};
111 C c0(a, a + sizeof(a) / sizeof(a[0]), 7, test_hash<int>(8), test_equal_to<int>(9), A());
112 C c(a, a + 2, 7, test_hash<int>(2), test_equal_to<int>(3), A());
113 C::iterator it0 = c0.begin();
114 c = std::move(c0);
115 LIBCPP_ASSERT(c.bucket_count() == 7);
116 assert(c.size() == 6);
117 assert(c.count(1) == 2);
118 assert(c.count(2) == 2);
119 assert(c.count(3) == 1);
120 assert(c.count(4) == 1);
121 assert(c.hash_function() == test_hash<int>(8));
122 assert(c.key_eq() == test_equal_to<int>(9));
123 assert(c.get_allocator() == A());
124 assert(!c.empty());
125 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
126 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
127 assert(fabs(c.load_factor() - (float)c.size() / c.bucket_count()) < FLT_EPSILON);
128 assert(c.max_load_factor() == 1);
129 assert(it0 == c.begin()); // Iterators remain valid
130 }
131 {
132 typedef min_allocator<int> A;
133 typedef std::unordered_multiset<int, test_hash<int>, test_equal_to<int>, A > C;
134 typedef int P;
135 P a[] = {P(1), P(2), P(3), P(4), P(1), P(2)};
136 C c0(a, a + sizeof(a) / sizeof(a[0]), 7, test_hash<int>(8), test_equal_to<int>(9), A());
137 C c(a, a + 2, 7, test_hash<int>(2), test_equal_to<int>(3), A());
138 C::iterator it0 = c0.begin();
139 c = std::move(c0);
140 LIBCPP_ASSERT(c.bucket_count() == 7);
141 assert(c.size() == 6);
142 assert(c.count(1) == 2);
143 assert(c.count(2) == 2);
144 assert(c.count(3) == 1);
145 assert(c.count(4) == 1);
146 assert(c.hash_function() == test_hash<int>(8));
147 assert(c.key_eq() == test_equal_to<int>(9));
148 assert(c.get_allocator() == A());
149 assert(!c.empty());
150 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
151 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
152 assert(fabs(c.load_factor() - (float)c.size() / c.bucket_count()) < FLT_EPSILON);
153 assert(c.max_load_factor() == 1);
154 assert(it0 == c.begin()); // Iterators remain valid
155 }
156
157 return 0;
158}
159

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