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