1 | //===----------------------------------------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | // <map> |
10 | |
11 | // class multimap |
12 | |
13 | // void swap(multimap& m); |
14 | |
15 | #include <map> |
16 | #include <cassert> |
17 | |
18 | #include "test_macros.h" |
19 | #include "min_allocator.h" |
20 | |
21 | int main(int, char**) |
22 | { |
23 | typedef std::pair<const int, double> V; |
24 | { |
25 | typedef std::multimap<int, double> M; |
26 | { |
27 | M m1; |
28 | M m2; |
29 | M m1_save = m1; |
30 | M m2_save = m2; |
31 | m1.swap(x&: m2); |
32 | assert(m1 == m2_save); |
33 | assert(m2 == m1_save); |
34 | } |
35 | { |
36 | V ar2[] = |
37 | { |
38 | V(5, 5), |
39 | V(6, 6), |
40 | V(7, 7), |
41 | V(8, 8), |
42 | V(9, 9), |
43 | V(10, 10), |
44 | V(11, 11), |
45 | V(12, 12) |
46 | }; |
47 | M m1; |
48 | M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); |
49 | M m1_save = m1; |
50 | M m2_save = m2; |
51 | m1.swap(x&: m2); |
52 | assert(m1 == m2_save); |
53 | assert(m2 == m1_save); |
54 | } |
55 | { |
56 | V ar1[] = |
57 | { |
58 | V(1, 1), |
59 | V(2, 2), |
60 | V(3, 3), |
61 | V(4, 4) |
62 | }; |
63 | M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); |
64 | M m2; |
65 | M m1_save = m1; |
66 | M m2_save = m2; |
67 | m1.swap(x&: m2); |
68 | assert(m1 == m2_save); |
69 | assert(m2 == m1_save); |
70 | } |
71 | { |
72 | V ar1[] = |
73 | { |
74 | V(1, 1), |
75 | V(2, 2), |
76 | V(3, 3), |
77 | V(4, 4) |
78 | }; |
79 | V ar2[] = |
80 | { |
81 | V(5, 5), |
82 | V(6, 6), |
83 | V(7, 7), |
84 | V(8, 8), |
85 | V(9, 9), |
86 | V(10, 10), |
87 | V(11, 11), |
88 | V(12, 12) |
89 | }; |
90 | M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); |
91 | M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); |
92 | M m1_save = m1; |
93 | M m2_save = m2; |
94 | m1.swap(x&: m2); |
95 | assert(m1 == m2_save); |
96 | assert(m2 == m1_save); |
97 | } |
98 | } |
99 | #if TEST_STD_VER >= 11 |
100 | { |
101 | typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; |
102 | { |
103 | M m1; |
104 | M m2; |
105 | M m1_save = m1; |
106 | M m2_save = m2; |
107 | m1.swap(m2); |
108 | assert(m1 == m2_save); |
109 | assert(m2 == m1_save); |
110 | } |
111 | { |
112 | V ar2[] = |
113 | { |
114 | V(5, 5), |
115 | V(6, 6), |
116 | V(7, 7), |
117 | V(8, 8), |
118 | V(9, 9), |
119 | V(10, 10), |
120 | V(11, 11), |
121 | V(12, 12) |
122 | }; |
123 | M m1; |
124 | M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); |
125 | M m1_save = m1; |
126 | M m2_save = m2; |
127 | m1.swap(m2); |
128 | assert(m1 == m2_save); |
129 | assert(m2 == m1_save); |
130 | } |
131 | { |
132 | V ar1[] = |
133 | { |
134 | V(1, 1), |
135 | V(2, 2), |
136 | V(3, 3), |
137 | V(4, 4) |
138 | }; |
139 | M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); |
140 | M m2; |
141 | M m1_save = m1; |
142 | M m2_save = m2; |
143 | m1.swap(m2); |
144 | assert(m1 == m2_save); |
145 | assert(m2 == m1_save); |
146 | } |
147 | { |
148 | V ar1[] = |
149 | { |
150 | V(1, 1), |
151 | V(2, 2), |
152 | V(3, 3), |
153 | V(4, 4) |
154 | }; |
155 | V ar2[] = |
156 | { |
157 | V(5, 5), |
158 | V(6, 6), |
159 | V(7, 7), |
160 | V(8, 8), |
161 | V(9, 9), |
162 | V(10, 10), |
163 | V(11, 11), |
164 | V(12, 12) |
165 | }; |
166 | M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); |
167 | M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); |
168 | M m1_save = m1; |
169 | M m2_save = m2; |
170 | m1.swap(m2); |
171 | assert(m1 == m2_save); |
172 | assert(m2 == m1_save); |
173 | } |
174 | } |
175 | #endif |
176 | |
177 | return 0; |
178 | } |
179 | |