1//===----------------------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// UNSUPPORTED: c++98, c++03
11
12// <map>
13
14// class multimap
15
16// multimap& operator=(multimap&& m);
17
18#include <map>
19#include <cassert>
20
21#include "MoveOnly.h"
22#include "../../../test_compare.h"
23#include "test_allocator.h"
24#include "min_allocator.h"
25
26int main()
27{
28    {
29        typedef std::pair<MoveOnly, MoveOnly> V;
30        typedef std::pair<const MoveOnly, MoveOnly> VC;
31        typedef test_compare<std::less<MoveOnly> > C;
32        typedef test_allocator<VC> A;
33        typedef std::multimap<MoveOnly, MoveOnly, C, A> M;
34        typedef std::move_iterator<V*> I;
35        V a1[] =
36        {
37            V(1, 1),
38            V(1, 2),
39            V(1, 3),
40            V(2, 1),
41            V(2, 2),
42            V(2, 3),
43            V(3, 1),
44            V(3, 2),
45            V(3, 3)
46        };
47        M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7));
48        V a2[] =
49        {
50            V(1, 1),
51            V(1, 2),
52            V(1, 3),
53            V(2, 1),
54            V(2, 2),
55            V(2, 3),
56            V(3, 1),
57            V(3, 2),
58            V(3, 3)
59        };
60        M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7));
61        M m3(C(3), A(7));
62        m3 = std::move(m1);
63        assert(m3 == m2);
64        assert(m3.get_allocator() == A(7));
65        assert(m3.key_comp() == C(5));
66        assert(m1.empty());
67    }
68    {
69        typedef std::pair<MoveOnly, MoveOnly> V;
70        typedef std::pair<const MoveOnly, MoveOnly> VC;
71        typedef test_compare<std::less<MoveOnly> > C;
72        typedef test_allocator<VC> A;
73        typedef std::multimap<MoveOnly, MoveOnly, C, A> M;
74        typedef std::move_iterator<V*> I;
75        V a1[] =
76        {
77            V(1, 1),
78            V(1, 2),
79            V(1, 3),
80            V(2, 1),
81            V(2, 2),
82            V(2, 3),
83            V(3, 1),
84            V(3, 2),
85            V(3, 3)
86        };
87        M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7));
88        V a2[] =
89        {
90            V(1, 1),
91            V(1, 2),
92            V(1, 3),
93            V(2, 1),
94            V(2, 2),
95            V(2, 3),
96            V(3, 1),
97            V(3, 2),
98            V(3, 3)
99        };
100        M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7));
101        M m3(C(3), A(5));
102        m3 = std::move(m1);
103        assert(m3 == m2);
104        assert(m3.get_allocator() == A(5));
105        assert(m3.key_comp() == C(5));
106        assert(m1.empty());
107    }
108    {
109        typedef std::pair<MoveOnly, MoveOnly> V;
110        typedef std::pair<const MoveOnly, MoveOnly> VC;
111        typedef test_compare<std::less<MoveOnly> > C;
112        typedef other_allocator<VC> A;
113        typedef std::multimap<MoveOnly, MoveOnly, C, A> M;
114        typedef std::move_iterator<V*> I;
115        V a1[] =
116        {
117            V(1, 1),
118            V(1, 2),
119            V(1, 3),
120            V(2, 1),
121            V(2, 2),
122            V(2, 3),
123            V(3, 1),
124            V(3, 2),
125            V(3, 3)
126        };
127        M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7));
128        V a2[] =
129        {
130            V(1, 1),
131            V(1, 2),
132            V(1, 3),
133            V(2, 1),
134            V(2, 2),
135            V(2, 3),
136            V(3, 1),
137            V(3, 2),
138            V(3, 3)
139        };
140        M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7));
141        M m3(C(3), A(5));
142        m3 = std::move(m1);
143        assert(m3 == m2);
144        assert(m3.get_allocator() == A(7));
145        assert(m3.key_comp() == C(5));
146        assert(m1.empty());
147    }
148    {
149        typedef std::pair<MoveOnly, MoveOnly> V;
150        typedef std::pair<const MoveOnly, MoveOnly> VC;
151        typedef test_compare<std::less<MoveOnly> > C;
152        typedef min_allocator<VC> A;
153        typedef std::multimap<MoveOnly, MoveOnly, C, A> M;
154        typedef std::move_iterator<V*> I;
155        V a1[] =
156        {
157            V(1, 1),
158            V(1, 2),
159            V(1, 3),
160            V(2, 1),
161            V(2, 2),
162            V(2, 3),
163            V(3, 1),
164            V(3, 2),
165            V(3, 3)
166        };
167        M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A());
168        V a2[] =
169        {
170            V(1, 1),
171            V(1, 2),
172            V(1, 3),
173            V(2, 1),
174            V(2, 2),
175            V(2, 3),
176            V(3, 1),
177            V(3, 2),
178            V(3, 3)
179        };
180        M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A());
181        M m3(C(3), A());
182        m3 = std::move(m1);
183        assert(m3 == m2);
184        assert(m3.get_allocator() == A());
185        assert(m3.key_comp() == C(5));
186        assert(m1.empty());
187    }
188}
189