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 // <set>
12
13 // class multiset
14
15 // multiset(multiset&& s, const allocator_type& a);
16
17 #include <set>
18 #include <cassert>
19
20 #include "test_macros.h"
21 #include "MoveOnly.h"
22 #include "../../../test_compare.h"
23 #include "test_allocator.h"
24 #include "Counter.h"
25
main(int,char **)26 int main(int, char**)
27 {
28 {
29 typedef MoveOnly V;
30 typedef test_compare<std::less<MoveOnly> > C;
31 typedef test_allocator<V> A;
32 typedef std::multiset<MoveOnly, C, A> M;
33 typedef std::move_iterator<V*> I;
34 V a1[] =
35 {
36 V(1),
37 V(1),
38 V(1),
39 V(2),
40 V(2),
41 V(2),
42 V(3),
43 V(3),
44 V(3)
45 };
46 M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7));
47 V a2[] =
48 {
49 V(1),
50 V(1),
51 V(1),
52 V(2),
53 V(2),
54 V(2),
55 V(3),
56 V(3),
57 V(3)
58 };
59 M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7));
60 M m3(std::move(m1), A(7));
61 assert(m3 == m2);
62 assert(m3.get_allocator() == A(7));
63 assert(m3.key_comp() == C(5));
64 LIBCPP_ASSERT(m1.empty());
65 }
66 {
67 typedef MoveOnly V;
68 typedef test_compare<std::less<MoveOnly> > C;
69 typedef test_allocator<V> A;
70 typedef std::multiset<MoveOnly, C, A> M;
71 typedef std::move_iterator<V*> I;
72 V a1[] =
73 {
74 V(1),
75 V(1),
76 V(1),
77 V(2),
78 V(2),
79 V(2),
80 V(3),
81 V(3),
82 V(3)
83 };
84 M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7));
85 V a2[] =
86 {
87 V(1),
88 V(1),
89 V(1),
90 V(2),
91 V(2),
92 V(2),
93 V(3),
94 V(3),
95 V(3)
96 };
97 M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7));
98 M m3(std::move(m1), A(5));
99 assert(m3 == m2);
100 assert(m3.get_allocator() == A(5));
101 assert(m3.key_comp() == C(5));
102 LIBCPP_ASSERT(m1.empty());
103 }
104 {
105 typedef MoveOnly V;
106 typedef test_compare<std::less<MoveOnly> > C;
107 typedef other_allocator<V> A;
108 typedef std::multiset<MoveOnly, C, A> M;
109 typedef std::move_iterator<V*> I;
110 V a1[] =
111 {
112 V(1),
113 V(1),
114 V(1),
115 V(2),
116 V(2),
117 V(2),
118 V(3),
119 V(3),
120 V(3)
121 };
122 M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7));
123 V a2[] =
124 {
125 V(1),
126 V(1),
127 V(1),
128 V(2),
129 V(2),
130 V(2),
131 V(3),
132 V(3),
133 V(3)
134 };
135 M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7));
136 M m3(std::move(m1), A(5));
137 assert(m3 == m2);
138 assert(m3.get_allocator() == A(5));
139 assert(m3.key_comp() == C(5));
140 LIBCPP_ASSERT(m1.empty());
141 }
142 {
143 typedef Counter<int> V;
144 typedef std::less<V> C;
145 typedef test_allocator<V> A;
146 typedef std::multiset<V, C, A> M;
147 typedef V* I;
148 Counter_base::gConstructed = 0;
149 {
150 V a1[] =
151 {
152 V(1),
153 V(1),
154 V(1),
155 V(2),
156 V(2),
157 V(2),
158 V(3),
159 V(3),
160 V(3)
161 };
162 const size_t num = sizeof(a1)/sizeof(a1[0]);
163 assert(Counter_base::gConstructed == num);
164
165 M m1(I(a1), I(a1+num), C(), A());
166 assert(Counter_base::gConstructed == 2*num);
167
168 M m2(m1);
169 assert(m2 == m1);
170 assert(Counter_base::gConstructed == 3*num);
171
172 M m3(std::move(m1), A());
173 assert(m3 == m2);
174 LIBCPP_ASSERT(m1.empty());
175 assert(Counter_base::gConstructed >= (int)(3*num));
176 assert(Counter_base::gConstructed <= (int)(4*num));
177
178 {
179 M m4(std::move(m2), A(5));
180 assert(Counter_base::gConstructed >= (int)(3*num));
181 assert(Counter_base::gConstructed <= (int)(5*num));
182 assert(m4 == m3);
183 LIBCPP_ASSERT(m2.empty());
184 }
185 assert(Counter_base::gConstructed >= (int)(2*num));
186 assert(Counter_base::gConstructed <= (int)(4*num));
187 }
188 assert(Counter_base::gConstructed == 0);
189 }
190
191 return 0;
192 }
193