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
1018293116SEric Fiselier 
115a83710eSEric Fiselier // <map>
125a83710eSEric Fiselier 
135a83710eSEric Fiselier // class map
145a83710eSEric Fiselier 
155a83710eSEric Fiselier // map(map&& m, const allocator_type& a);
165a83710eSEric Fiselier 
175a83710eSEric Fiselier #include <map>
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"
255a83710eSEric Fiselier #include "min_allocator.h"
26d5f461caSMarshall Clow #include "Counter.h"
275a83710eSEric Fiselier 
main(int,char **)282df59c50SJF Bastien int main(int, char**)
295a83710eSEric Fiselier {
305a83710eSEric Fiselier     {
315a83710eSEric Fiselier         typedef std::pair<MoveOnly, MoveOnly> V;
325a83710eSEric Fiselier         typedef std::pair<const MoveOnly, MoveOnly> VC;
335cc55fdbSArthur O'Dwyer         typedef test_less<MoveOnly> C;
345a83710eSEric Fiselier         typedef test_allocator<VC> A;
355a83710eSEric Fiselier         typedef std::map<MoveOnly, MoveOnly, C, A> M;
365a83710eSEric Fiselier         typedef std::move_iterator<V*> I;
375a83710eSEric Fiselier         V a1[] =
385a83710eSEric Fiselier         {
395a83710eSEric Fiselier             V(1, 1),
405a83710eSEric Fiselier             V(1, 2),
415a83710eSEric Fiselier             V(1, 3),
425a83710eSEric Fiselier             V(2, 1),
435a83710eSEric Fiselier             V(2, 2),
445a83710eSEric Fiselier             V(2, 3),
455a83710eSEric Fiselier             V(3, 1),
465a83710eSEric Fiselier             V(3, 2),
475a83710eSEric Fiselier             V(3, 3)
485a83710eSEric Fiselier         };
495a83710eSEric Fiselier         M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7));
505a83710eSEric Fiselier         V a2[] =
515a83710eSEric Fiselier         {
525a83710eSEric Fiselier             V(1, 1),
535a83710eSEric Fiselier             V(1, 2),
545a83710eSEric Fiselier             V(1, 3),
555a83710eSEric Fiselier             V(2, 1),
565a83710eSEric Fiselier             V(2, 2),
575a83710eSEric Fiselier             V(2, 3),
585a83710eSEric Fiselier             V(3, 1),
595a83710eSEric Fiselier             V(3, 2),
605a83710eSEric Fiselier             V(3, 3)
615a83710eSEric Fiselier         };
625a83710eSEric Fiselier         M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7));
635a83710eSEric Fiselier         M m3(std::move(m1), A(7));
645a83710eSEric Fiselier         assert(m3 == m2);
655a83710eSEric Fiselier         assert(m3.get_allocator() == A(7));
665a83710eSEric Fiselier         assert(m3.key_comp() == C(5));
67c02236b6SMarshall Clow         LIBCPP_ASSERT(m1.empty());
685a83710eSEric Fiselier     }
695a83710eSEric Fiselier     {
705a83710eSEric Fiselier         typedef std::pair<MoveOnly, MoveOnly> V;
715a83710eSEric Fiselier         typedef std::pair<const MoveOnly, MoveOnly> VC;
725cc55fdbSArthur O'Dwyer         typedef test_less<MoveOnly> C;
735a83710eSEric Fiselier         typedef test_allocator<VC> A;
745a83710eSEric Fiselier         typedef std::map<MoveOnly, MoveOnly, C, A> M;
755a83710eSEric Fiselier         typedef std::move_iterator<V*> I;
765a83710eSEric Fiselier         V a1[] =
775a83710eSEric Fiselier         {
785a83710eSEric Fiselier             V(1, 1),
795a83710eSEric Fiselier             V(1, 2),
805a83710eSEric Fiselier             V(1, 3),
815a83710eSEric Fiselier             V(2, 1),
825a83710eSEric Fiselier             V(2, 2),
835a83710eSEric Fiselier             V(2, 3),
845a83710eSEric Fiselier             V(3, 1),
855a83710eSEric Fiselier             V(3, 2),
865a83710eSEric Fiselier             V(3, 3)
875a83710eSEric Fiselier         };
885a83710eSEric Fiselier         M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7));
895a83710eSEric Fiselier         V a2[] =
905a83710eSEric Fiselier         {
915a83710eSEric Fiselier             V(1, 1),
925a83710eSEric Fiselier             V(1, 2),
935a83710eSEric Fiselier             V(1, 3),
945a83710eSEric Fiselier             V(2, 1),
955a83710eSEric Fiselier             V(2, 2),
965a83710eSEric Fiselier             V(2, 3),
975a83710eSEric Fiselier             V(3, 1),
985a83710eSEric Fiselier             V(3, 2),
995a83710eSEric Fiselier             V(3, 3)
1005a83710eSEric Fiselier         };
1015a83710eSEric Fiselier         M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7));
1025a83710eSEric Fiselier         M m3(std::move(m1), A(5));
1035a83710eSEric Fiselier         assert(m3 == m2);
1045a83710eSEric Fiselier         assert(m3.get_allocator() == A(5));
1055a83710eSEric Fiselier         assert(m3.key_comp() == C(5));
106c02236b6SMarshall Clow         LIBCPP_ASSERT(m1.empty());
1075a83710eSEric Fiselier     }
1085a83710eSEric Fiselier     {
1095a83710eSEric Fiselier         typedef std::pair<MoveOnly, MoveOnly> V;
1105a83710eSEric Fiselier         typedef std::pair<const MoveOnly, MoveOnly> VC;
1115cc55fdbSArthur O'Dwyer         typedef test_less<MoveOnly> C;
1125a83710eSEric Fiselier         typedef other_allocator<VC> A;
1135a83710eSEric Fiselier         typedef std::map<MoveOnly, MoveOnly, C, A> M;
1145a83710eSEric Fiselier         typedef std::move_iterator<V*> I;
1155a83710eSEric Fiselier         V a1[] =
1165a83710eSEric Fiselier         {
1175a83710eSEric Fiselier             V(1, 1),
1185a83710eSEric Fiselier             V(1, 2),
1195a83710eSEric Fiselier             V(1, 3),
1205a83710eSEric Fiselier             V(2, 1),
1215a83710eSEric Fiselier             V(2, 2),
1225a83710eSEric Fiselier             V(2, 3),
1235a83710eSEric Fiselier             V(3, 1),
1245a83710eSEric Fiselier             V(3, 2),
1255a83710eSEric Fiselier             V(3, 3)
1265a83710eSEric Fiselier         };
1275a83710eSEric Fiselier         M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7));
1285a83710eSEric Fiselier         V a2[] =
1295a83710eSEric Fiselier         {
1305a83710eSEric Fiselier             V(1, 1),
1315a83710eSEric Fiselier             V(1, 2),
1325a83710eSEric Fiselier             V(1, 3),
1335a83710eSEric Fiselier             V(2, 1),
1345a83710eSEric Fiselier             V(2, 2),
1355a83710eSEric Fiselier             V(2, 3),
1365a83710eSEric Fiselier             V(3, 1),
1375a83710eSEric Fiselier             V(3, 2),
1385a83710eSEric Fiselier             V(3, 3)
1395a83710eSEric Fiselier         };
1405a83710eSEric Fiselier         M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7));
1415a83710eSEric Fiselier         M m3(std::move(m1), A(5));
1425a83710eSEric Fiselier         assert(m3 == m2);
1435a83710eSEric Fiselier         assert(m3.get_allocator() == A(5));
1445a83710eSEric Fiselier         assert(m3.key_comp() == C(5));
145c02236b6SMarshall Clow         LIBCPP_ASSERT(m1.empty());
1465a83710eSEric Fiselier     }
147d5f461caSMarshall Clow     {
148d5f461caSMarshall Clow         typedef Counter<int> T;
149d5f461caSMarshall Clow         typedef std::pair<int, T> V;
150d5f461caSMarshall Clow         typedef std::pair<const int, T> VC;
151d5f461caSMarshall Clow         typedef test_allocator<VC> A;
152d5f461caSMarshall Clow         typedef std::less<int> C;
153d5f461caSMarshall Clow         typedef std::map<const int, T, C, A> M;
154d5f461caSMarshall Clow         typedef V* I;
155d5f461caSMarshall Clow         Counter_base::gConstructed = 0;
156d5f461caSMarshall Clow         {
157d5f461caSMarshall Clow             V a1[] =
158d5f461caSMarshall Clow             {
159d5f461caSMarshall Clow                 V(1, 1),
160d5f461caSMarshall Clow                 V(1, 2),
161d5f461caSMarshall Clow                 V(1, 3),
162d5f461caSMarshall Clow                 V(2, 1),
163d5f461caSMarshall Clow                 V(2, 2),
164d5f461caSMarshall Clow                 V(2, 3),
165d5f461caSMarshall Clow                 V(3, 1),
166d5f461caSMarshall Clow                 V(3, 2),
167d5f461caSMarshall Clow                 V(3, 3)
168d5f461caSMarshall Clow             };
169d5f461caSMarshall Clow             const size_t num = sizeof(a1)/sizeof(a1[0]);
170d5f461caSMarshall Clow             assert(Counter_base::gConstructed == num);
171d5f461caSMarshall Clow 
172d5f461caSMarshall Clow             M m1(I(a1), I(a1+num), C(), A());
173d5f461caSMarshall Clow             assert(Counter_base::gConstructed == num+3);
174d5f461caSMarshall Clow 
175d5f461caSMarshall Clow             M m2(m1);
176d5f461caSMarshall Clow             assert(m2 == m1);
177d5f461caSMarshall Clow             assert(Counter_base::gConstructed == num+6);
178d5f461caSMarshall Clow 
179d5f461caSMarshall Clow             M m3(std::move(m1), A());
180d5f461caSMarshall Clow             assert(m3 == m2);
181c02236b6SMarshall Clow             LIBCPP_ASSERT(m1.empty());
18295601bddSLouis Dionne             assert(Counter_base::gConstructed >= (int)(num+6));
18395601bddSLouis Dionne             assert(Counter_base::gConstructed <= (int)(num+6+m1.size()));
184d5f461caSMarshall Clow 
185d5f461caSMarshall Clow             {
186d5f461caSMarshall Clow             M m4(std::move(m2), A(5));
18795601bddSLouis Dionne             assert(Counter_base::gConstructed >= (int)(num+6));
18895601bddSLouis Dionne             assert(Counter_base::gConstructed <= (int)(num+6+m1.size()+m2.size()));
189d5f461caSMarshall Clow             assert(m4 == m3);
190c02236b6SMarshall Clow             LIBCPP_ASSERT(m2.empty());
191d5f461caSMarshall Clow             }
19295601bddSLouis Dionne             assert(Counter_base::gConstructed >= (int)(num+3));
19395601bddSLouis Dionne             assert(Counter_base::gConstructed <= (int)(num+3+m1.size()+m2.size()));
194d5f461caSMarshall Clow         }
195d5f461caSMarshall Clow         assert(Counter_base::gConstructed == 0);
196d5f461caSMarshall Clow     }
1975a83710eSEric Fiselier     {
1985a83710eSEric Fiselier         typedef std::pair<MoveOnly, MoveOnly> V;
1995a83710eSEric Fiselier         typedef std::pair<const MoveOnly, MoveOnly> VC;
2005cc55fdbSArthur O'Dwyer         typedef test_less<MoveOnly> C;
2015a83710eSEric Fiselier         typedef min_allocator<VC> A;
2025a83710eSEric Fiselier         typedef std::map<MoveOnly, MoveOnly, C, A> M;
2035a83710eSEric Fiselier         typedef std::move_iterator<V*> I;
2045a83710eSEric Fiselier         V a1[] =
2055a83710eSEric Fiselier         {
2065a83710eSEric Fiselier             V(1, 1),
2075a83710eSEric Fiselier             V(1, 2),
2085a83710eSEric Fiselier             V(1, 3),
2095a83710eSEric Fiselier             V(2, 1),
2105a83710eSEric Fiselier             V(2, 2),
2115a83710eSEric Fiselier             V(2, 3),
2125a83710eSEric Fiselier             V(3, 1),
2135a83710eSEric Fiselier             V(3, 2),
2145a83710eSEric Fiselier             V(3, 3)
2155a83710eSEric Fiselier         };
2165a83710eSEric Fiselier         M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A());
2175a83710eSEric Fiselier         V a2[] =
2185a83710eSEric Fiselier         {
2195a83710eSEric Fiselier             V(1, 1),
2205a83710eSEric Fiselier             V(1, 2),
2215a83710eSEric Fiselier             V(1, 3),
2225a83710eSEric Fiselier             V(2, 1),
2235a83710eSEric Fiselier             V(2, 2),
2245a83710eSEric Fiselier             V(2, 3),
2255a83710eSEric Fiselier             V(3, 1),
2265a83710eSEric Fiselier             V(3, 2),
2275a83710eSEric Fiselier             V(3, 3)
2285a83710eSEric Fiselier         };
2295a83710eSEric Fiselier         M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A());
2305a83710eSEric Fiselier         M m3(std::move(m1), A());
2315a83710eSEric Fiselier         assert(m3 == m2);
2325a83710eSEric Fiselier         assert(m3.get_allocator() == A());
2335a83710eSEric Fiselier         assert(m3.key_comp() == C(5));
234c02236b6SMarshall Clow         LIBCPP_ASSERT(m1.empty());
2355a83710eSEric Fiselier     }
2362a10c960SMarshall Clow     {
2372a10c960SMarshall Clow         typedef std::pair<MoveOnly, MoveOnly> V;
2382a10c960SMarshall Clow         typedef std::pair<const MoveOnly, MoveOnly> VC;
2395cc55fdbSArthur O'Dwyer         typedef test_less<MoveOnly> C;
2402a10c960SMarshall Clow         typedef explicit_allocator<VC> A;
2412a10c960SMarshall Clow         typedef std::map<MoveOnly, MoveOnly, C, A> M;
2422a10c960SMarshall Clow         typedef std::move_iterator<V*> I;
2432a10c960SMarshall Clow         V a1[] =
2442a10c960SMarshall Clow         {
2452a10c960SMarshall Clow             V(1, 1),
2462a10c960SMarshall Clow             V(1, 2),
2472a10c960SMarshall Clow             V(1, 3),
2482a10c960SMarshall Clow             V(2, 1),
2492a10c960SMarshall Clow             V(2, 2),
2502a10c960SMarshall Clow             V(2, 3),
2512a10c960SMarshall Clow             V(3, 1),
2522a10c960SMarshall Clow             V(3, 2),
2532a10c960SMarshall Clow             V(3, 3)
2542a10c960SMarshall Clow         };
2552a10c960SMarshall Clow         M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A{});
2562a10c960SMarshall Clow         V a2[] =
2572a10c960SMarshall Clow         {
2582a10c960SMarshall Clow             V(1, 1),
2592a10c960SMarshall Clow             V(1, 2),
2602a10c960SMarshall Clow             V(1, 3),
2612a10c960SMarshall Clow             V(2, 1),
2622a10c960SMarshall Clow             V(2, 2),
2632a10c960SMarshall Clow             V(2, 3),
2642a10c960SMarshall Clow             V(3, 1),
2652a10c960SMarshall Clow             V(3, 2),
2662a10c960SMarshall Clow             V(3, 3)
2672a10c960SMarshall Clow         };
2682a10c960SMarshall Clow         M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A{});
2692a10c960SMarshall Clow         M m3(std::move(m1), A{});
2702a10c960SMarshall Clow         assert(m3 == m2);
2712a10c960SMarshall Clow         assert(m3.get_allocator() == A{});
2722a10c960SMarshall Clow         assert(m3.key_comp() == C(5));
273c02236b6SMarshall Clow         LIBCPP_ASSERT(m1.empty());
2742a10c960SMarshall Clow     }
2752df59c50SJF Bastien 
2762df59c50SJF Bastien   return 0;
2775a83710eSEric Fiselier }
278