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