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