llvm-project
169 строк · 3.5 Кб
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#include "test_macros.h"
18#include "test_allocator.h"
19#include "../../../test_compare.h"
20
21int main(int, char**)
22{
23typedef int V;
24{
25typedef std::set<int> M;
26{
27M m1;
28M m2;
29M m1_save = m1;
30M m2_save = m2;
31swap(m1, m2);
32assert(m1 == m2_save);
33assert(m2 == m1_save);
34}
35{
36V ar2[] =
37{
385,
396,
407,
418,
429,
4310,
4411,
4512
46};
47M m1;
48M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
49M m1_save = m1;
50M m2_save = m2;
51swap(m1, m2);
52assert(m1 == m2_save);
53assert(m2 == m1_save);
54}
55{
56V ar1[] =
57{
581,
592,
603,
614
62};
63M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
64M m2;
65M m1_save = m1;
66M m2_save = m2;
67swap(m1, m2);
68assert(m1 == m2_save);
69assert(m2 == m1_save);
70}
71{
72V ar1[] =
73{
741,
752,
763,
774
78};
79V ar2[] =
80{
815,
826,
837,
848,
859,
8610,
8711,
8812
89};
90M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
91M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
92M m1_save = m1;
93M m2_save = m2;
94swap(m1, m2);
95assert(m1 == m2_save);
96assert(m2 == m1_save);
97}
98}
99{
100typedef test_allocator<V> A;
101typedef test_less<int> C;
102typedef std::set<int, C, A> M;
103V ar1[] =
104{
1051,
1062,
1073,
1084
109};
110V ar2[] =
111{
1125,
1136,
1147,
1158,
1169,
11710,
11811,
11912
120};
121M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]), C(1), A(1, 1));
122M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]), C(2), A(1, 2));
123M m1_save = m1;
124M m2_save = m2;
125swap(m1, m2);
126assert(m1 == m2_save);
127assert(m2 == m1_save);
128assert(m1.key_comp() == C(2));
129assert(m1.get_allocator().get_id() == 1);
130assert(m2.key_comp() == C(1));
131assert(m2.get_allocator().get_id() == 2);
132}
133{
134typedef other_allocator<V> A;
135typedef test_less<int> C;
136typedef std::set<int, C, A> M;
137V ar1[] =
138{
1391,
1402,
1413,
1424
143};
144V ar2[] =
145{
1465,
1476,
1487,
1498,
1509,
15110,
15211,
15312
154};
155M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]), C(1), A(1));
156M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]), C(2), A(2));
157M m1_save = m1;
158M m2_save = m2;
159swap(m1, m2);
160assert(m1 == m2_save);
161assert(m2 == m1_save);
162assert(m1.key_comp() == C(2));
163assert(m1.get_allocator() == A(2));
164assert(m2.key_comp() == C(1));
165assert(m2.get_allocator() == A(1));
166}
167
168return 0;
169}
170