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 | // <set> |
10 | |
11 | // class set |
12 | |
13 | // void swap(set& m); |
14 | |
15 | #include <set> |
16 | #include <cassert> |
17 | |
18 | #include "test_macros.h" |
19 | #include "min_allocator.h" |
20 | |
21 | int main(int, char**) |
22 | { |
23 | { |
24 | typedef int V; |
25 | typedef std::set<int> 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 | 5, |
39 | 6, |
40 | 7, |
41 | 8, |
42 | 9, |
43 | 10, |
44 | 11, |
45 | 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 | 1, |
59 | 2, |
60 | 3, |
61 | 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 | 1, |
75 | 2, |
76 | 3, |
77 | 4 |
78 | }; |
79 | V ar2[] = |
80 | { |
81 | 5, |
82 | 6, |
83 | 7, |
84 | 8, |
85 | 9, |
86 | 10, |
87 | 11, |
88 | 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 int V; |
102 | typedef std::set<int, std::less<int>, min_allocator<int>> M; |
103 | { |
104 | M m1; |
105 | M m2; |
106 | M m1_save = m1; |
107 | M m2_save = m2; |
108 | m1.swap(m2); |
109 | assert(m1 == m2_save); |
110 | assert(m2 == m1_save); |
111 | } |
112 | { |
113 | V ar2[] = |
114 | { |
115 | 5, |
116 | 6, |
117 | 7, |
118 | 8, |
119 | 9, |
120 | 10, |
121 | 11, |
122 | 12 |
123 | }; |
124 | M m1; |
125 | M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); |
126 | M m1_save = m1; |
127 | M m2_save = m2; |
128 | m1.swap(m2); |
129 | assert(m1 == m2_save); |
130 | assert(m2 == m1_save); |
131 | } |
132 | { |
133 | V ar1[] = |
134 | { |
135 | 1, |
136 | 2, |
137 | 3, |
138 | 4 |
139 | }; |
140 | M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); |
141 | M m2; |
142 | M m1_save = m1; |
143 | M m2_save = m2; |
144 | m1.swap(m2); |
145 | assert(m1 == m2_save); |
146 | assert(m2 == m1_save); |
147 | } |
148 | { |
149 | V ar1[] = |
150 | { |
151 | 1, |
152 | 2, |
153 | 3, |
154 | 4 |
155 | }; |
156 | V ar2[] = |
157 | { |
158 | 5, |
159 | 6, |
160 | 7, |
161 | 8, |
162 | 9, |
163 | 10, |
164 | 11, |
165 | 12 |
166 | }; |
167 | M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); |
168 | M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); |
169 | M m1_save = m1; |
170 | M m2_save = m2; |
171 | m1.swap(m2); |
172 | assert(m1 == m2_save); |
173 | assert(m2 == m1_save); |
174 | } |
175 | } |
176 | #endif |
177 | |
178 | return 0; |
179 | } |
180 | |