]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/tr1/6_containers/unordered_multiset/swap/1.cc
1 // 2005-12-20 Paolo Carlini <pcarlini@suse.de>
3 // Copyright (C) 2005-2023 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
20 // 6.3.4.5 unordered_multiset::swap
22 #include <tr1/unordered_set>
24 #include <testsuite_hooks.h>
25 #include <testsuite_allocator.h>
27 // uneq_allocator as a non-empty allocator.
31 using namespace std::tr1
;
35 typedef __gnu_test::uneq_allocator
<char> my_alloc
;
36 typedef unordered_multiset
<char, hash
<char>, equal_to
<char>, my_alloc
>
39 const char title01
[] = "Rivers of sand";
40 const char title02
[] = "Concret PH";
41 const char title03
[] = "Sonatas and Interludes for Prepared Piano";
42 const char title04
[] = "never as tired as when i'm waking up";
44 const size_t N1
= sizeof(title01
);
45 const size_t N2
= sizeof(title02
);
46 const size_t N3
= sizeof(title03
);
47 const size_t N4
= sizeof(title04
);
49 typedef multiset
<char> my_mset
;
50 const my_mset
mset01_ref(title01
, title01
+ N1
);
51 const my_mset
mset02_ref(title02
, title02
+ N2
);
52 const my_mset
mset03_ref(title03
, title03
+ N3
);
53 const my_mset
mset04_ref(title04
, title04
+ N4
);
55 my_umset::size_type size01
, size02
;
59 my_umset
umset01(10, hash
<char>(), equal_to
<char>(), alloc01
);
60 size01
= umset01
.size();
61 my_umset
umset02(10, hash
<char>(), equal_to
<char>(), alloc01
);
62 size02
= umset02
.size();
64 umset01
.swap(umset02
);
65 VERIFY( umset01
.size() == size02
);
66 VERIFY( umset01
.empty() );
67 VERIFY( umset02
.size() == size01
);
68 VERIFY( umset02
.empty() );
70 my_umset
umset03(10, hash
<char>(), equal_to
<char>(), alloc01
);
71 size01
= umset03
.size();
72 my_umset
umset04(mset02_ref
.begin(), mset02_ref
.end(), 10, hash
<char>(),
73 equal_to
<char>(), alloc01
);
74 size02
= umset04
.size();
76 umset03
.swap(umset04
);
77 VERIFY( umset03
.size() == size02
);
78 VERIFY( my_mset(umset03
.begin(), umset03
.end()) == mset02_ref
);
79 VERIFY( umset04
.size() == size01
);
80 VERIFY( umset04
.empty() );
82 my_umset
umset05(mset01_ref
.begin(), mset01_ref
.end(), 10, hash
<char>(),
83 equal_to
<char>(), alloc01
);
84 size01
= umset05
.size();
85 my_umset
umset06(mset02_ref
.begin(), mset02_ref
.end(), 10, hash
<char>(),
86 equal_to
<char>(), alloc01
);
87 size02
= umset06
.size();
89 umset05
.swap(umset06
);
90 VERIFY( umset05
.size() == size02
);
91 VERIFY( my_mset(umset05
.begin(), umset05
.end()) == mset02_ref
);
92 VERIFY( umset06
.size() == size01
);
93 VERIFY( my_mset(umset06
.begin(), umset06
.end()) == mset01_ref
);
95 my_umset
umset07(mset01_ref
.begin(), mset01_ref
.end(), 10, hash
<char>(),
96 equal_to
<char>(), alloc01
);
97 size01
= umset07
.size();
98 my_umset
umset08(mset03_ref
.begin(), mset03_ref
.end(), 10, hash
<char>(),
99 equal_to
<char>(), alloc01
);
100 size02
= umset08
.size();
102 umset07
.swap(umset08
);
103 VERIFY( umset07
.size() == size02
);
104 VERIFY( my_mset(umset07
.begin(), umset07
.end()) == mset03_ref
);
105 VERIFY( umset08
.size() == size01
);
106 VERIFY( my_mset(umset08
.begin(), umset08
.end()) == mset01_ref
);
108 my_umset
umset09(mset03_ref
.begin(), mset03_ref
.end(), 10, hash
<char>(),
109 equal_to
<char>(), alloc01
);
110 size01
= umset09
.size();
111 my_umset
umset10(mset04_ref
.begin(), mset04_ref
.end(), 10, hash
<char>(),
112 equal_to
<char>(), alloc01
);
113 size02
= umset10
.size();
115 umset09
.swap(umset10
);
116 VERIFY( umset09
.size() == size02
);
117 VERIFY( my_mset(umset09
.begin(), umset09
.end()) == mset04_ref
);
118 VERIFY( umset10
.size() == size01
);
119 VERIFY( my_mset(umset10
.begin(), umset10
.end()) == mset03_ref
);
121 my_umset
umset11(mset04_ref
.begin(), mset04_ref
.end(), 10, hash
<char>(),
122 equal_to
<char>(), alloc01
);
123 size01
= umset11
.size();
124 my_umset
umset12(mset01_ref
.begin(), mset01_ref
.end(), 10, hash
<char>(),
125 equal_to
<char>(), alloc01
);
126 size02
= umset12
.size();
128 umset11
.swap(umset12
);
129 VERIFY( umset11
.size() == size02
);
130 VERIFY( my_mset(umset11
.begin(), umset11
.end()) == mset01_ref
);
131 VERIFY( umset12
.size() == size01
);
132 VERIFY( my_mset(umset12
.begin(), umset12
.end()) == mset04_ref
);
134 my_umset
umset13(mset03_ref
.begin(), mset03_ref
.end(), 10, hash
<char>(),
135 equal_to
<char>(), alloc01
);
136 size01
= umset13
.size();
137 my_umset
umset14(mset03_ref
.begin(), mset03_ref
.end(), 10, hash
<char>(),
138 equal_to
<char>(), alloc01
);
139 size02
= umset14
.size();
141 umset13
.swap(umset14
);
142 VERIFY( umset13
.size() == size02
);
143 VERIFY( my_mset(umset13
.begin(), umset13
.end()) == mset03_ref
);
144 VERIFY( umset14
.size() == size01
);
145 VERIFY( my_mset(umset14
.begin(), umset14
.end()) == mset03_ref
);