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(multimap&& m, const allocator_type& a);
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 #include "Counter.h"
24 
main()25 int main()
26 {
27 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
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(std::move(m1), A(7));
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(std::move(m1), A(5));
101         assert(m3 == m2);
102         assert(m3.get_allocator() == A(5));
103         assert(m3.key_comp() == C(5));
104         assert(m1.empty());
105     }
106     {
107         typedef std::pair<MoveOnly, MoveOnly> V;
108         typedef std::pair<const MoveOnly, MoveOnly> VC;
109         typedef test_compare<std::less<MoveOnly> > C;
110         typedef other_allocator<VC> A;
111         typedef std::multimap<MoveOnly, MoveOnly, C, A> M;
112         typedef std::move_iterator<V*> I;
113         V a1[] =
114         {
115             V(1, 1),
116             V(1, 2),
117             V(1, 3),
118             V(2, 1),
119             V(2, 2),
120             V(2, 3),
121             V(3, 1),
122             V(3, 2),
123             V(3, 3)
124         };
125         M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7));
126         V a2[] =
127         {
128             V(1, 1),
129             V(1, 2),
130             V(1, 3),
131             V(2, 1),
132             V(2, 2),
133             V(2, 3),
134             V(3, 1),
135             V(3, 2),
136             V(3, 3)
137         };
138         M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7));
139         M m3(std::move(m1), A(5));
140         assert(m3 == m2);
141         assert(m3.get_allocator() == A(5));
142         assert(m3.key_comp() == C(5));
143         assert(m1.empty());
144     }
145     {
146         typedef Counter<int> T;
147         typedef std::pair<int, T> V;
148         typedef std::pair<const int, T> VC;
149         typedef test_allocator<VC> A;
150         typedef std::less<int> C;
151         typedef std::multimap<const int, T, C, A> M;
152         typedef V* I;
153         Counter_base::gConstructed = 0;
154         {
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             const size_t num = sizeof(a1)/sizeof(a1[0]);
168             assert(Counter_base::gConstructed == num);
169 
170             M m1(I(a1), I(a1+num), C(), A());
171             assert(Counter_base::gConstructed == 2*num);
172 
173             M m2(m1);
174             assert(m2 == m1);
175             assert(Counter_base::gConstructed == 3*num);
176 
177             M m3(std::move(m1), A());
178             assert(m3 == m2);
179             assert(m1.empty());
180             assert(Counter_base::gConstructed == 3*num);
181 
182             {
183             M m4(std::move(m2), A(5));
184             assert(Counter_base::gConstructed == 3*num);
185             assert(m4 == m3);
186             assert(m2.empty());
187             }
188             assert(Counter_base::gConstructed == 2*num);
189         }
190         assert(Counter_base::gConstructed == 0);
191     }
192 #if __cplusplus >= 201103L
193     {
194         typedef std::pair<MoveOnly, MoveOnly> V;
195         typedef std::pair<const MoveOnly, MoveOnly> VC;
196         typedef test_compare<std::less<MoveOnly> > C;
197         typedef min_allocator<VC> A;
198         typedef std::multimap<MoveOnly, MoveOnly, C, A> M;
199         typedef std::move_iterator<V*> I;
200         V a1[] =
201         {
202             V(1, 1),
203             V(1, 2),
204             V(1, 3),
205             V(2, 1),
206             V(2, 2),
207             V(2, 3),
208             V(3, 1),
209             V(3, 2),
210             V(3, 3)
211         };
212         M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A());
213         V a2[] =
214         {
215             V(1, 1),
216             V(1, 2),
217             V(1, 3),
218             V(2, 1),
219             V(2, 2),
220             V(2, 3),
221             V(3, 1),
222             V(3, 2),
223             V(3, 3)
224         };
225         M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A());
226         M m3(std::move(m1), A());
227         assert(m3 == m2);
228         assert(m3.get_allocator() == A());
229         assert(m3.key_comp() == C(5));
230         assert(m1.empty());
231     }
232 #endif
233 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
234 }
235