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

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