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 // <map>
11
12 // class multimap
13
14 // multimap& operator=(multimap&& m);
15
16 #include <map>
17 #include <cassert>
18
19 #include "../../../MoveOnly.h"
20 #include "../../../test_compare.h"
21 #include "test_allocator.h"
22 #include "min_allocator.h"
23
main()24 int main()
25 {
26 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
27 {
28 typedef std::pair<MoveOnly, MoveOnly> V;
29 typedef std::pair<const MoveOnly, MoveOnly> VC;
30 typedef test_compare<std::less<MoveOnly> > C;
31 typedef test_allocator<VC> A;
32 typedef std::multimap<MoveOnly, MoveOnly, C, A> M;
33 typedef std::move_iterator<V*> I;
34 V a1[] =
35 {
36 V(1, 1),
37 V(1, 2),
38 V(1, 3),
39 V(2, 1),
40 V(2, 2),
41 V(2, 3),
42 V(3, 1),
43 V(3, 2),
44 V(3, 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, 1),
50 V(1, 2),
51 V(1, 3),
52 V(2, 1),
53 V(2, 2),
54 V(2, 3),
55 V(3, 1),
56 V(3, 2),
57 V(3, 3)
58 };
59 M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7));
60 M m3(C(3), A(7));
61 m3 = std::move(m1);
62 assert(m3 == m2);
63 assert(m3.get_allocator() == A(7));
64 assert(m3.key_comp() == C(5));
65 assert(m1.empty());
66 }
67 {
68 typedef std::pair<MoveOnly, MoveOnly> V;
69 typedef std::pair<const MoveOnly, MoveOnly> VC;
70 typedef test_compare<std::less<MoveOnly> > C;
71 typedef test_allocator<VC> A;
72 typedef std::multimap<MoveOnly, MoveOnly, C, A> M;
73 typedef std::move_iterator<V*> I;
74 V a1[] =
75 {
76 V(1, 1),
77 V(1, 2),
78 V(1, 3),
79 V(2, 1),
80 V(2, 2),
81 V(2, 3),
82 V(3, 1),
83 V(3, 2),
84 V(3, 3)
85 };
86 M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7));
87 V a2[] =
88 {
89 V(1, 1),
90 V(1, 2),
91 V(1, 3),
92 V(2, 1),
93 V(2, 2),
94 V(2, 3),
95 V(3, 1),
96 V(3, 2),
97 V(3, 3)
98 };
99 M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7));
100 M m3(C(3), A(5));
101 m3 = std::move(m1);
102 assert(m3 == m2);
103 assert(m3.get_allocator() == A(5));
104 assert(m3.key_comp() == C(5));
105 assert(m1.empty());
106 }
107 {
108 typedef std::pair<MoveOnly, MoveOnly> V;
109 typedef std::pair<const MoveOnly, MoveOnly> VC;
110 typedef test_compare<std::less<MoveOnly> > C;
111 typedef other_allocator<VC> A;
112 typedef std::multimap<MoveOnly, MoveOnly, C, A> M;
113 typedef std::move_iterator<V*> I;
114 V a1[] =
115 {
116 V(1, 1),
117 V(1, 2),
118 V(1, 3),
119 V(2, 1),
120 V(2, 2),
121 V(2, 3),
122 V(3, 1),
123 V(3, 2),
124 V(3, 3)
125 };
126 M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7));
127 V a2[] =
128 {
129 V(1, 1),
130 V(1, 2),
131 V(1, 3),
132 V(2, 1),
133 V(2, 2),
134 V(2, 3),
135 V(3, 1),
136 V(3, 2),
137 V(3, 3)
138 };
139 M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7));
140 M m3(C(3), A(5));
141 m3 = std::move(m1);
142 assert(m3 == m2);
143 assert(m3.get_allocator() == A(7));
144 assert(m3.key_comp() == C(5));
145 assert(m1.empty());
146 }
147 #if __cplusplus >= 201103L
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 #endif
189 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
190 }
191