]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/tr1/6_containers/unordered_set/swap/2.cc
1 // 2005-12-20 Paolo Carlini <pcarlini@suse.de>
3 // Copyright (C) 2005-2020 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.3 unordered_set::swap
22 #include <tr1/unordered_set>
24 #include <testsuite_hooks.h>
25 #include <testsuite_allocator.h>
27 // uneq_allocator, two different personalities.
31 using namespace std::tr1
;
35 typedef __gnu_test::uneq_allocator
<char> my_alloc
;
36 typedef unordered_set
<char, hash
<char>, equal_to
<char>, my_alloc
> my_uset
;
38 const char title01
[] = "Rivers of sand";
39 const char title02
[] = "Concret PH";
40 const char title03
[] = "Sonatas and Interludes for Prepared Piano";
41 const char title04
[] = "never as tired as when i'm waking up";
43 const size_t N1
= sizeof(title01
);
44 const size_t N2
= sizeof(title02
);
45 const size_t N3
= sizeof(title03
);
46 const size_t N4
= sizeof(title04
);
48 typedef set
<char> my_set
;
49 const my_set
set01_ref(title01
, title01
+ N1
);
50 const my_set
set02_ref(title02
, title02
+ N2
);
51 const my_set
set03_ref(title03
, title03
+ N3
);
52 const my_set
set04_ref(title04
, title04
+ N4
);
54 my_uset::size_type size01
, size02
;
56 my_alloc
alloc01(1), alloc02(2);
57 int personality01
, personality02
;
59 my_uset
uset01(10, hash
<char>(), equal_to
<char>(), alloc01
);
60 size01
= uset01
.size();
61 personality01
= uset01
.get_allocator().get_personality();
62 my_uset
uset02(10, hash
<char>(), equal_to
<char>(), alloc02
);
63 size02
= uset02
.size();
64 personality02
= uset02
.get_allocator().get_personality();
67 VERIFY( uset01
.size() == size02
);
68 VERIFY( uset01
.empty() );
69 VERIFY( uset02
.size() == size01
);
70 VERIFY( uset02
.empty() );
71 VERIFY( uset01
.get_allocator().get_personality() == personality02
);
72 VERIFY( uset02
.get_allocator().get_personality() == personality01
);
74 my_uset
uset03(10, hash
<char>(), equal_to
<char>(), alloc02
);
75 size01
= uset03
.size();
76 personality01
= uset03
.get_allocator().get_personality();
77 my_uset
uset04(set02_ref
.begin(), set02_ref
.end(), 10, hash
<char>(),
78 equal_to
<char>(), alloc01
);
79 size02
= uset04
.size();
80 personality02
= uset04
.get_allocator().get_personality();
83 VERIFY( uset03
.size() == size02
);
84 VERIFY( my_set(uset03
.begin(), uset03
.end()) == set02_ref
);
85 VERIFY( uset04
.size() == size01
);
86 VERIFY( uset04
.empty() );
87 VERIFY( uset03
.get_allocator().get_personality() == personality02
);
88 VERIFY( uset04
.get_allocator().get_personality() == personality01
);
90 my_uset
uset05(set01_ref
.begin(), set01_ref
.end(), 10, hash
<char>(),
91 equal_to
<char>(), alloc01
);
92 size01
= uset05
.size();
93 personality01
= uset05
.get_allocator().get_personality();
94 my_uset
uset06(set02_ref
.begin(), set02_ref
.end(), 10, hash
<char>(),
95 equal_to
<char>(), alloc02
);
96 size02
= uset06
.size();
97 personality02
= uset06
.get_allocator().get_personality();
100 VERIFY( uset05
.size() == size02
);
101 VERIFY( my_set(uset05
.begin(), uset05
.end()) == set02_ref
);
102 VERIFY( uset06
.size() == size01
);
103 VERIFY( my_set(uset06
.begin(), uset06
.end()) == set01_ref
);
104 VERIFY( uset05
.get_allocator().get_personality() == personality02
);
105 VERIFY( uset06
.get_allocator().get_personality() == personality01
);
107 my_uset
uset07(set01_ref
.begin(), set01_ref
.end(), 10, hash
<char>(),
108 equal_to
<char>(), alloc02
);
109 size01
= uset07
.size();
110 personality01
= uset07
.get_allocator().get_personality();
111 my_uset
uset08(set03_ref
.begin(), set03_ref
.end(), 10, hash
<char>(),
112 equal_to
<char>(), alloc01
);
113 size02
= uset08
.size();
114 personality02
= uset08
.get_allocator().get_personality();
117 VERIFY( uset07
.size() == size02
);
118 VERIFY( my_set(uset07
.begin(), uset07
.end()) == set03_ref
);
119 VERIFY( uset08
.size() == size01
);
120 VERIFY( my_set(uset08
.begin(), uset08
.end()) == set01_ref
);
121 VERIFY( uset07
.get_allocator().get_personality() == personality02
);
122 VERIFY( uset08
.get_allocator().get_personality() == personality01
);
124 my_uset
uset09(set03_ref
.begin(), set03_ref
.end(), 10, hash
<char>(),
125 equal_to
<char>(), alloc01
);
126 size01
= uset09
.size();
127 personality01
= uset09
.get_allocator().get_personality();
128 my_uset
uset10(set04_ref
.begin(), set04_ref
.end(), 10, hash
<char>(),
129 equal_to
<char>(), alloc02
);
130 size02
= uset10
.size();
131 personality02
= uset10
.get_allocator().get_personality();
134 VERIFY( uset09
.size() == size02
);
135 VERIFY( my_set(uset09
.begin(), uset09
.end()) == set04_ref
);
136 VERIFY( uset10
.size() == size01
);
137 VERIFY( my_set(uset10
.begin(), uset10
.end()) == set03_ref
);
138 VERIFY( uset09
.get_allocator().get_personality() == personality02
);
139 VERIFY( uset10
.get_allocator().get_personality() == personality01
);
141 my_uset
uset11(set04_ref
.begin(), set04_ref
.end(), 10, hash
<char>(),
142 equal_to
<char>(), alloc02
);
143 size01
= uset11
.size();
144 personality01
= uset11
.get_allocator().get_personality();
145 my_uset
uset12(set01_ref
.begin(), set01_ref
.end(), 10, hash
<char>(),
146 equal_to
<char>(), alloc01
);
147 size02
= uset12
.size();
148 personality02
= uset12
.get_allocator().get_personality();
151 VERIFY( uset11
.size() == size02
);
152 VERIFY( my_set(uset11
.begin(), uset11
.end()) == set01_ref
);
153 VERIFY( uset12
.size() == size01
);
154 VERIFY( my_set(uset12
.begin(), uset12
.end()) == set04_ref
);
155 VERIFY( uset11
.get_allocator().get_personality() == personality02
);
156 VERIFY( uset12
.get_allocator().get_personality() == personality01
);
158 my_uset
uset13(set03_ref
.begin(), set03_ref
.end(), 10, hash
<char>(),
159 equal_to
<char>(), alloc01
);
160 size01
= uset13
.size();
161 personality01
= uset13
.get_allocator().get_personality();
162 my_uset
uset14(set03_ref
.begin(), set03_ref
.end(), 10, hash
<char>(),
163 equal_to
<char>(), alloc02
);
164 size02
= uset14
.size();
165 personality02
= uset14
.get_allocator().get_personality();
168 VERIFY( uset13
.size() == size02
);
169 VERIFY( my_set(uset13
.begin(), uset13
.end()) == set03_ref
);
170 VERIFY( uset14
.size() == size01
);
171 VERIFY( my_set(uset14
.begin(), uset14
.end()) == set03_ref
);
172 VERIFY( uset13
.get_allocator().get_personality() == personality02
);
173 VERIFY( uset14
.get_allocator().get_personality() == personality01
);