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 multimap
145a83710eSEric Fiselier
155a83710eSEric Fiselier // multimap(multimap&& m, const allocator_type& a);
165a83710eSEric Fiselier
175a83710eSEric Fiselier #include <map>
185a83710eSEric Fiselier #include <cassert>
195a83710eSEric Fiselier
20c02236b6SMarshall Clow #include "test_macros.h"
21949389c3SMarshall Clow #include "MoveOnly.h"
225a83710eSEric Fiselier #include "../../../test_compare.h"
235a83710eSEric Fiselier #include "test_allocator.h"
245a83710eSEric Fiselier #include "min_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 std::pair<MoveOnly, MoveOnly> V;
315a83710eSEric Fiselier typedef std::pair<const MoveOnly, MoveOnly> VC;
32*5cc55fdbSArthur O'Dwyer typedef test_less<MoveOnly> C;
335a83710eSEric Fiselier typedef test_allocator<VC> A;
345a83710eSEric Fiselier typedef std::multimap<MoveOnly, MoveOnly, C, A> M;
355a83710eSEric Fiselier typedef std::move_iterator<V*> I;
365a83710eSEric Fiselier V a1[] =
375a83710eSEric Fiselier {
385a83710eSEric Fiselier V(1, 1),
395a83710eSEric Fiselier V(1, 2),
405a83710eSEric Fiselier V(1, 3),
415a83710eSEric Fiselier V(2, 1),
425a83710eSEric Fiselier V(2, 2),
435a83710eSEric Fiselier V(2, 3),
445a83710eSEric Fiselier V(3, 1),
455a83710eSEric Fiselier V(3, 2),
465a83710eSEric Fiselier V(3, 3)
475a83710eSEric Fiselier };
485a83710eSEric Fiselier M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7));
495a83710eSEric Fiselier V a2[] =
505a83710eSEric Fiselier {
515a83710eSEric Fiselier V(1, 1),
525a83710eSEric Fiselier V(1, 2),
535a83710eSEric Fiselier V(1, 3),
545a83710eSEric Fiselier V(2, 1),
555a83710eSEric Fiselier V(2, 2),
565a83710eSEric Fiselier V(2, 3),
575a83710eSEric Fiselier V(3, 1),
585a83710eSEric Fiselier V(3, 2),
595a83710eSEric Fiselier V(3, 3)
605a83710eSEric Fiselier };
615a83710eSEric Fiselier M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7));
625a83710eSEric Fiselier M m3(std::move(m1), A(7));
635a83710eSEric Fiselier assert(m3 == m2);
645a83710eSEric Fiselier assert(m3.get_allocator() == A(7));
655a83710eSEric Fiselier assert(m3.key_comp() == C(5));
66c02236b6SMarshall Clow LIBCPP_ASSERT(m1.empty());
675a83710eSEric Fiselier }
685a83710eSEric Fiselier {
695a83710eSEric Fiselier typedef std::pair<MoveOnly, MoveOnly> V;
705a83710eSEric Fiselier typedef std::pair<const MoveOnly, MoveOnly> VC;
71*5cc55fdbSArthur O'Dwyer typedef test_less<MoveOnly> C;
725a83710eSEric Fiselier typedef test_allocator<VC> A;
735a83710eSEric Fiselier typedef std::multimap<MoveOnly, MoveOnly, C, A> M;
745a83710eSEric Fiselier typedef std::move_iterator<V*> I;
755a83710eSEric Fiselier V a1[] =
765a83710eSEric Fiselier {
775a83710eSEric Fiselier V(1, 1),
785a83710eSEric Fiselier V(1, 2),
795a83710eSEric Fiselier V(1, 3),
805a83710eSEric Fiselier V(2, 1),
815a83710eSEric Fiselier V(2, 2),
825a83710eSEric Fiselier V(2, 3),
835a83710eSEric Fiselier V(3, 1),
845a83710eSEric Fiselier V(3, 2),
855a83710eSEric Fiselier V(3, 3)
865a83710eSEric Fiselier };
875a83710eSEric Fiselier M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7));
885a83710eSEric Fiselier V a2[] =
895a83710eSEric Fiselier {
905a83710eSEric Fiselier V(1, 1),
915a83710eSEric Fiselier V(1, 2),
925a83710eSEric Fiselier V(1, 3),
935a83710eSEric Fiselier V(2, 1),
945a83710eSEric Fiselier V(2, 2),
955a83710eSEric Fiselier V(2, 3),
965a83710eSEric Fiselier V(3, 1),
975a83710eSEric Fiselier V(3, 2),
985a83710eSEric Fiselier V(3, 3)
995a83710eSEric Fiselier };
1005a83710eSEric Fiselier M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7));
1015a83710eSEric Fiselier M m3(std::move(m1), A(5));
1025a83710eSEric Fiselier assert(m3 == m2);
1035a83710eSEric Fiselier assert(m3.get_allocator() == A(5));
1045a83710eSEric Fiselier assert(m3.key_comp() == C(5));
105c02236b6SMarshall Clow LIBCPP_ASSERT(m1.empty());
1065a83710eSEric Fiselier }
1075a83710eSEric Fiselier {
1085a83710eSEric Fiselier typedef std::pair<MoveOnly, MoveOnly> V;
1095a83710eSEric Fiselier typedef std::pair<const MoveOnly, MoveOnly> VC;
110*5cc55fdbSArthur O'Dwyer typedef test_less<MoveOnly> C;
1115a83710eSEric Fiselier typedef other_allocator<VC> A;
1125a83710eSEric Fiselier typedef std::multimap<MoveOnly, MoveOnly, C, A> M;
1135a83710eSEric Fiselier typedef std::move_iterator<V*> I;
1145a83710eSEric Fiselier V a1[] =
1155a83710eSEric Fiselier {
1165a83710eSEric Fiselier V(1, 1),
1175a83710eSEric Fiselier V(1, 2),
1185a83710eSEric Fiselier V(1, 3),
1195a83710eSEric Fiselier V(2, 1),
1205a83710eSEric Fiselier V(2, 2),
1215a83710eSEric Fiselier V(2, 3),
1225a83710eSEric Fiselier V(3, 1),
1235a83710eSEric Fiselier V(3, 2),
1245a83710eSEric Fiselier V(3, 3)
1255a83710eSEric Fiselier };
1265a83710eSEric Fiselier M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7));
1275a83710eSEric Fiselier V a2[] =
1285a83710eSEric Fiselier {
1295a83710eSEric Fiselier V(1, 1),
1305a83710eSEric Fiselier V(1, 2),
1315a83710eSEric Fiselier V(1, 3),
1325a83710eSEric Fiselier V(2, 1),
1335a83710eSEric Fiselier V(2, 2),
1345a83710eSEric Fiselier V(2, 3),
1355a83710eSEric Fiselier V(3, 1),
1365a83710eSEric Fiselier V(3, 2),
1375a83710eSEric Fiselier V(3, 3)
1385a83710eSEric Fiselier };
1395a83710eSEric Fiselier M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7));
1405a83710eSEric Fiselier M m3(std::move(m1), A(5));
1415a83710eSEric Fiselier assert(m3 == m2);
1425a83710eSEric Fiselier assert(m3.get_allocator() == A(5));
1435a83710eSEric Fiselier assert(m3.key_comp() == C(5));
144c02236b6SMarshall Clow LIBCPP_ASSERT(m1.empty());
1455a83710eSEric Fiselier }
146d5f461caSMarshall Clow {
147d5f461caSMarshall Clow typedef Counter<int> T;
148d5f461caSMarshall Clow typedef std::pair<int, T> V;
149d5f461caSMarshall Clow typedef std::pair<const int, T> VC;
150d5f461caSMarshall Clow typedef test_allocator<VC> A;
151d5f461caSMarshall Clow typedef std::less<int> C;
152d5f461caSMarshall Clow typedef std::multimap<const int, T, C, A> M;
153d5f461caSMarshall Clow typedef V* I;
154d5f461caSMarshall Clow Counter_base::gConstructed = 0;
155d5f461caSMarshall Clow {
156d5f461caSMarshall Clow V a1[] =
157d5f461caSMarshall Clow {
158d5f461caSMarshall Clow V(1, 1),
159d5f461caSMarshall Clow V(1, 2),
160d5f461caSMarshall Clow V(1, 3),
161d5f461caSMarshall Clow V(2, 1),
162d5f461caSMarshall Clow V(2, 2),
163d5f461caSMarshall Clow V(2, 3),
164d5f461caSMarshall Clow V(3, 1),
165d5f461caSMarshall Clow V(3, 2),
166d5f461caSMarshall Clow V(3, 3)
167d5f461caSMarshall Clow };
168d5f461caSMarshall Clow const size_t num = sizeof(a1)/sizeof(a1[0]);
169d5f461caSMarshall Clow assert(Counter_base::gConstructed == num);
170d5f461caSMarshall Clow
171d5f461caSMarshall Clow M m1(I(a1), I(a1+num), C(), A());
172d5f461caSMarshall Clow assert(Counter_base::gConstructed == 2*num);
173d5f461caSMarshall Clow
174d5f461caSMarshall Clow M m2(m1);
175d5f461caSMarshall Clow assert(m2 == m1);
176d5f461caSMarshall Clow assert(Counter_base::gConstructed == 3*num);
177d5f461caSMarshall Clow
178d5f461caSMarshall Clow M m3(std::move(m1), A());
179d5f461caSMarshall Clow assert(m3 == m2);
180c02236b6SMarshall Clow LIBCPP_ASSERT(m1.empty());
18195601bddSLouis Dionne assert(Counter_base::gConstructed >= (int)(3*num));
18295601bddSLouis Dionne assert(Counter_base::gConstructed <= (int)(4*num));
183d5f461caSMarshall Clow
184d5f461caSMarshall Clow {
185d5f461caSMarshall Clow M m4(std::move(m2), A(5));
18695601bddSLouis Dionne assert(Counter_base::gConstructed >= (int)(3*num));
18795601bddSLouis Dionne assert(Counter_base::gConstructed <= (int)(5*num));
188d5f461caSMarshall Clow assert(m4 == m3);
189c02236b6SMarshall Clow LIBCPP_ASSERT(m2.empty());
190d5f461caSMarshall Clow }
19195601bddSLouis Dionne assert(Counter_base::gConstructed >= (int)(2*num));
19295601bddSLouis Dionne assert(Counter_base::gConstructed <= (int)(4*num));
193d5f461caSMarshall Clow }
194d5f461caSMarshall Clow assert(Counter_base::gConstructed == 0);
195d5f461caSMarshall Clow }
1965a83710eSEric Fiselier {
1975a83710eSEric Fiselier typedef std::pair<MoveOnly, MoveOnly> V;
1985a83710eSEric Fiselier typedef std::pair<const MoveOnly, MoveOnly> VC;
199*5cc55fdbSArthur O'Dwyer typedef test_less<MoveOnly> C;
2005a83710eSEric Fiselier typedef min_allocator<VC> A;
2015a83710eSEric Fiselier typedef std::multimap<MoveOnly, MoveOnly, C, A> M;
2025a83710eSEric Fiselier typedef std::move_iterator<V*> I;
2035a83710eSEric Fiselier V a1[] =
2045a83710eSEric Fiselier {
2055a83710eSEric Fiselier V(1, 1),
2065a83710eSEric Fiselier V(1, 2),
2075a83710eSEric Fiselier V(1, 3),
2085a83710eSEric Fiselier V(2, 1),
2095a83710eSEric Fiselier V(2, 2),
2105a83710eSEric Fiselier V(2, 3),
2115a83710eSEric Fiselier V(3, 1),
2125a83710eSEric Fiselier V(3, 2),
2135a83710eSEric Fiselier V(3, 3)
2145a83710eSEric Fiselier };
2155a83710eSEric Fiselier M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A());
2165a83710eSEric Fiselier V a2[] =
2175a83710eSEric Fiselier {
2185a83710eSEric Fiselier V(1, 1),
2195a83710eSEric Fiselier V(1, 2),
2205a83710eSEric Fiselier V(1, 3),
2215a83710eSEric Fiselier V(2, 1),
2225a83710eSEric Fiselier V(2, 2),
2235a83710eSEric Fiselier V(2, 3),
2245a83710eSEric Fiselier V(3, 1),
2255a83710eSEric Fiselier V(3, 2),
2265a83710eSEric Fiselier V(3, 3)
2275a83710eSEric Fiselier };
2285a83710eSEric Fiselier M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A());
2295a83710eSEric Fiselier M m3(std::move(m1), A());
2305a83710eSEric Fiselier assert(m3 == m2);
2315a83710eSEric Fiselier assert(m3.get_allocator() == A());
2325a83710eSEric Fiselier assert(m3.key_comp() == C(5));
233c02236b6SMarshall Clow LIBCPP_ASSERT(m1.empty());
2345a83710eSEric Fiselier }
2352a10c960SMarshall Clow {
2362a10c960SMarshall Clow typedef std::pair<MoveOnly, MoveOnly> V;
2372a10c960SMarshall Clow typedef std::pair<const MoveOnly, MoveOnly> VC;
238*5cc55fdbSArthur O'Dwyer typedef test_less<MoveOnly> C;
2392a10c960SMarshall Clow typedef explicit_allocator<VC> A;
2402a10c960SMarshall Clow typedef std::multimap<MoveOnly, MoveOnly, C, A> M;
2412a10c960SMarshall Clow typedef std::move_iterator<V*> I;
2422a10c960SMarshall Clow V a1[] =
2432a10c960SMarshall Clow {
2442a10c960SMarshall Clow V(1, 1),
2452a10c960SMarshall Clow V(1, 2),
2462a10c960SMarshall Clow V(1, 3),
2472a10c960SMarshall Clow V(2, 1),
2482a10c960SMarshall Clow V(2, 2),
2492a10c960SMarshall Clow V(2, 3),
2502a10c960SMarshall Clow V(3, 1),
2512a10c960SMarshall Clow V(3, 2),
2522a10c960SMarshall Clow V(3, 3)
2532a10c960SMarshall Clow };
2542a10c960SMarshall Clow M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A{});
2552a10c960SMarshall Clow V a2[] =
2562a10c960SMarshall Clow {
2572a10c960SMarshall Clow V(1, 1),
2582a10c960SMarshall Clow V(1, 2),
2592a10c960SMarshall Clow V(1, 3),
2602a10c960SMarshall Clow V(2, 1),
2612a10c960SMarshall Clow V(2, 2),
2622a10c960SMarshall Clow V(2, 3),
2632a10c960SMarshall Clow V(3, 1),
2642a10c960SMarshall Clow V(3, 2),
2652a10c960SMarshall Clow V(3, 3)
2662a10c960SMarshall Clow };
2672a10c960SMarshall Clow M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A{});
2682a10c960SMarshall Clow M m3(std::move(m1), A{});
2692a10c960SMarshall Clow assert(m3 == m2);
2702a10c960SMarshall Clow assert(m3.get_allocator() == A{});
2712a10c960SMarshall Clow assert(m3.key_comp() == C(5));
272c02236b6SMarshall Clow LIBCPP_ASSERT(m1.empty());
2732a10c960SMarshall Clow }
2742df59c50SJF Bastien
2752df59c50SJF Bastien return 0;
2765a83710eSEric Fiselier }
277