15a83710eSEric Fiselier //===----------------------------------------------------------------------===//
25a83710eSEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65a83710eSEric Fiselier //
75a83710eSEric Fiselier //===----------------------------------------------------------------------===//
85a83710eSEric Fiselier 
931cbe0f2SLouis Dionne // UNSUPPORTED: c++03
10922940b6SEric Fiselier 
115a83710eSEric Fiselier // <set>
125a83710eSEric Fiselier 
135a83710eSEric Fiselier // class multiset
145a83710eSEric Fiselier 
155a83710eSEric Fiselier // multiset(multiset&& s, const allocator_type& a);
165a83710eSEric Fiselier 
175a83710eSEric Fiselier #include <set>
185a83710eSEric Fiselier #include <cassert>
19*3cd4531bSNikolas Klauser #include <iterator>
205a83710eSEric Fiselier 
21c02236b6SMarshall Clow #include "test_macros.h"
22949389c3SMarshall Clow #include "MoveOnly.h"
235a83710eSEric Fiselier #include "../../../test_compare.h"
245a83710eSEric Fiselier #include "test_allocator.h"
25d5f461caSMarshall Clow #include "Counter.h"
265a83710eSEric Fiselier 
main(int,char **)272df59c50SJF Bastien int main(int, char**)
285a83710eSEric Fiselier {
295a83710eSEric Fiselier     {
305a83710eSEric Fiselier         typedef MoveOnly V;
315cc55fdbSArthur O'Dwyer         typedef test_less<MoveOnly> C;
325a83710eSEric Fiselier         typedef test_allocator<V> A;
335a83710eSEric Fiselier         typedef std::multiset<MoveOnly, C, A> M;
345a83710eSEric Fiselier         typedef std::move_iterator<V*> I;
355a83710eSEric Fiselier         V a1[] =
365a83710eSEric Fiselier         {
375a83710eSEric Fiselier             V(1),
385a83710eSEric Fiselier             V(1),
395a83710eSEric Fiselier             V(1),
405a83710eSEric Fiselier             V(2),
415a83710eSEric Fiselier             V(2),
425a83710eSEric Fiselier             V(2),
435a83710eSEric Fiselier             V(3),
445a83710eSEric Fiselier             V(3),
455a83710eSEric Fiselier             V(3)
465a83710eSEric Fiselier         };
475a83710eSEric Fiselier         M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7));
485a83710eSEric Fiselier         V a2[] =
495a83710eSEric Fiselier         {
505a83710eSEric Fiselier             V(1),
515a83710eSEric Fiselier             V(1),
525a83710eSEric Fiselier             V(1),
535a83710eSEric Fiselier             V(2),
545a83710eSEric Fiselier             V(2),
555a83710eSEric Fiselier             V(2),
565a83710eSEric Fiselier             V(3),
575a83710eSEric Fiselier             V(3),
585a83710eSEric Fiselier             V(3)
595a83710eSEric Fiselier         };
605a83710eSEric Fiselier         M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7));
615a83710eSEric Fiselier         M m3(std::move(m1), A(7));
625a83710eSEric Fiselier         assert(m3 == m2);
635a83710eSEric Fiselier         assert(m3.get_allocator() == A(7));
645a83710eSEric Fiselier         assert(m3.key_comp() == C(5));
65c02236b6SMarshall Clow         LIBCPP_ASSERT(m1.empty());
665a83710eSEric Fiselier     }
675a83710eSEric Fiselier     {
685a83710eSEric Fiselier         typedef MoveOnly V;
695cc55fdbSArthur O'Dwyer         typedef test_less<MoveOnly> C;
705a83710eSEric Fiselier         typedef test_allocator<V> A;
715a83710eSEric Fiselier         typedef std::multiset<MoveOnly, C, A> M;
725a83710eSEric Fiselier         typedef std::move_iterator<V*> I;
735a83710eSEric Fiselier         V a1[] =
745a83710eSEric Fiselier         {
755a83710eSEric Fiselier             V(1),
765a83710eSEric Fiselier             V(1),
775a83710eSEric Fiselier             V(1),
785a83710eSEric Fiselier             V(2),
795a83710eSEric Fiselier             V(2),
805a83710eSEric Fiselier             V(2),
815a83710eSEric Fiselier             V(3),
825a83710eSEric Fiselier             V(3),
835a83710eSEric Fiselier             V(3)
845a83710eSEric Fiselier         };
855a83710eSEric Fiselier         M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7));
865a83710eSEric Fiselier         V a2[] =
875a83710eSEric Fiselier         {
885a83710eSEric Fiselier             V(1),
895a83710eSEric Fiselier             V(1),
905a83710eSEric Fiselier             V(1),
915a83710eSEric Fiselier             V(2),
925a83710eSEric Fiselier             V(2),
935a83710eSEric Fiselier             V(2),
945a83710eSEric Fiselier             V(3),
955a83710eSEric Fiselier             V(3),
965a83710eSEric Fiselier             V(3)
975a83710eSEric Fiselier         };
985a83710eSEric Fiselier         M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7));
995a83710eSEric Fiselier         M m3(std::move(m1), A(5));
1005a83710eSEric Fiselier         assert(m3 == m2);
1015a83710eSEric Fiselier         assert(m3.get_allocator() == A(5));
1025a83710eSEric Fiselier         assert(m3.key_comp() == C(5));
103c02236b6SMarshall Clow         LIBCPP_ASSERT(m1.empty());
1045a83710eSEric Fiselier     }
1055a83710eSEric Fiselier     {
1065a83710eSEric Fiselier         typedef MoveOnly V;
1075cc55fdbSArthur O'Dwyer         typedef test_less<MoveOnly> C;
1085a83710eSEric Fiselier         typedef other_allocator<V> A;
1095a83710eSEric Fiselier         typedef std::multiset<MoveOnly, C, A> M;
1105a83710eSEric Fiselier         typedef std::move_iterator<V*> I;
1115a83710eSEric Fiselier         V a1[] =
1125a83710eSEric Fiselier         {
1135a83710eSEric Fiselier             V(1),
1145a83710eSEric Fiselier             V(1),
1155a83710eSEric Fiselier             V(1),
1165a83710eSEric Fiselier             V(2),
1175a83710eSEric Fiselier             V(2),
1185a83710eSEric Fiselier             V(2),
1195a83710eSEric Fiselier             V(3),
1205a83710eSEric Fiselier             V(3),
1215a83710eSEric Fiselier             V(3)
1225a83710eSEric Fiselier         };
1235a83710eSEric Fiselier         M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7));
1245a83710eSEric Fiselier         V a2[] =
1255a83710eSEric Fiselier         {
1265a83710eSEric Fiselier             V(1),
1275a83710eSEric Fiselier             V(1),
1285a83710eSEric Fiselier             V(1),
1295a83710eSEric Fiselier             V(2),
1305a83710eSEric Fiselier             V(2),
1315a83710eSEric Fiselier             V(2),
1325a83710eSEric Fiselier             V(3),
1335a83710eSEric Fiselier             V(3),
1345a83710eSEric Fiselier             V(3)
1355a83710eSEric Fiselier         };
1365a83710eSEric Fiselier         M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7));
1375a83710eSEric Fiselier         M m3(std::move(m1), A(5));
1385a83710eSEric Fiselier         assert(m3 == m2);
1395a83710eSEric Fiselier         assert(m3.get_allocator() == A(5));
1405a83710eSEric Fiselier         assert(m3.key_comp() == C(5));
141c02236b6SMarshall Clow         LIBCPP_ASSERT(m1.empty());
1425a83710eSEric Fiselier     }
143d5f461caSMarshall Clow     {
144d5f461caSMarshall Clow         typedef Counter<int> V;
145d5f461caSMarshall Clow         typedef std::less<V> C;
146d5f461caSMarshall Clow         typedef test_allocator<V> A;
147d5f461caSMarshall Clow         typedef std::multiset<V, C, A> M;
148d5f461caSMarshall Clow         typedef V* I;
149d5f461caSMarshall Clow         Counter_base::gConstructed = 0;
150d5f461caSMarshall Clow         {
151d5f461caSMarshall Clow             V a1[] =
152d5f461caSMarshall Clow             {
153d5f461caSMarshall Clow             V(1),
154d5f461caSMarshall Clow             V(1),
155d5f461caSMarshall Clow             V(1),
156d5f461caSMarshall Clow             V(2),
157d5f461caSMarshall Clow             V(2),
158d5f461caSMarshall Clow             V(2),
159d5f461caSMarshall Clow             V(3),
160d5f461caSMarshall Clow             V(3),
161d5f461caSMarshall Clow             V(3)
162d5f461caSMarshall Clow             };
163d5f461caSMarshall Clow             const size_t num = sizeof(a1)/sizeof(a1[0]);
164d5f461caSMarshall Clow             assert(Counter_base::gConstructed == num);
165d5f461caSMarshall Clow 
166d5f461caSMarshall Clow             M m1(I(a1), I(a1+num), C(), A());
167d5f461caSMarshall Clow             assert(Counter_base::gConstructed == 2*num);
168d5f461caSMarshall Clow 
169d5f461caSMarshall Clow             M m2(m1);
170d5f461caSMarshall Clow             assert(m2 == m1);
171d5f461caSMarshall Clow             assert(Counter_base::gConstructed == 3*num);
172d5f461caSMarshall Clow 
173d5f461caSMarshall Clow             M m3(std::move(m1), A());
174d5f461caSMarshall Clow             assert(m3 == m2);
175c02236b6SMarshall Clow             LIBCPP_ASSERT(m1.empty());
17695601bddSLouis Dionne             assert(Counter_base::gConstructed >= (int)(3*num));
17795601bddSLouis Dionne             assert(Counter_base::gConstructed <= (int)(4*num));
178d5f461caSMarshall Clow 
179d5f461caSMarshall Clow             {
180d5f461caSMarshall Clow             M m4(std::move(m2), A(5));
18195601bddSLouis Dionne             assert(Counter_base::gConstructed >= (int)(3*num));
18295601bddSLouis Dionne             assert(Counter_base::gConstructed <= (int)(5*num));
183d5f461caSMarshall Clow             assert(m4 == m3);
184c02236b6SMarshall Clow             LIBCPP_ASSERT(m2.empty());
185d5f461caSMarshall Clow             }
18695601bddSLouis Dionne             assert(Counter_base::gConstructed >= (int)(2*num));
18795601bddSLouis Dionne             assert(Counter_base::gConstructed <= (int)(4*num));
188d5f461caSMarshall Clow         }
189d5f461caSMarshall Clow         assert(Counter_base::gConstructed == 0);
190d5f461caSMarshall Clow     }
1912df59c50SJF Bastien 
1922df59c50SJF Bastien   return 0;
1935a83710eSEric Fiselier }
194