Dead
[official-gcc.git] / gomp-20050608-branch / libstdc++-v3 / testsuite / tr1 / 6_containers / unordered / swap / unordered_set / 2.cc
blob46e859cabacb832305bc8a67198e3fdad6ba2d05
1 // 2005-12-20 Paolo Carlini <pcarlini@suse.de>
3 // Copyright (C) 2005 Free Software Foundation, Inc.
4 //
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 2, or (at your option)
9 // any later version.
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 COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
21 // 6.3.4.3 unordered_set::swap
23 #include <tr1/unordered_set>
24 #include <set>
25 #include <testsuite_hooks.h>
26 #include <testsuite_allocator.h>
28 // uneq_allocator, two different personalities.
29 void
30 test01()
32 bool test __attribute__((unused)) = true;
33 using namespace std;
34 using namespace tr1;
36 typedef __gnu_test::uneq_allocator<char> my_alloc;
37 typedef unordered_set<char, hash<char>, equal_to<char>, my_alloc> my_uset;
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 set<char> my_set;
50 const my_set set01_ref(title01, title01 + N1);
51 const my_set set02_ref(title02, title02 + N2);
52 const my_set set03_ref(title03, title03 + N3);
53 const my_set set04_ref(title04, title04 + N4);
55 my_uset::size_type size01, size02;
57 my_alloc alloc01(1), alloc02(2);
58 int personality01, personality02;
60 my_uset uset01(10, hash<char>(), equal_to<char>(), alloc01);
61 size01 = uset01.size();
62 personality01 = uset01.get_allocator().get_personality();
63 my_uset uset02(10, hash<char>(), equal_to<char>(), alloc02);
64 size02 = uset02.size();
65 personality02 = uset02.get_allocator().get_personality();
67 uset01.swap(uset02);
68 VERIFY( uset01.size() == size02 );
69 VERIFY( uset01.empty() );
70 VERIFY( uset02.size() == size01 );
71 VERIFY( uset02.empty() );
72 VERIFY( uset01.get_allocator().get_personality() == personality02 );
73 VERIFY( uset02.get_allocator().get_personality() == personality01 );
75 my_uset uset03(10, hash<char>(), equal_to<char>(), alloc02);
76 size01 = uset03.size();
77 personality01 = uset03.get_allocator().get_personality();
78 my_uset uset04(set02_ref.begin(), set02_ref.end(), 10, hash<char>(),
79 equal_to<char>(), alloc01);
80 size02 = uset04.size();
81 personality02 = uset04.get_allocator().get_personality();
83 uset03.swap(uset04);
84 VERIFY( uset03.size() == size02 );
85 VERIFY( my_set(uset03.begin(), uset03.end()) == set02_ref );
86 VERIFY( uset04.size() == size01 );
87 VERIFY( uset04.empty() );
88 VERIFY( uset03.get_allocator().get_personality() == personality02 );
89 VERIFY( uset04.get_allocator().get_personality() == personality01 );
91 my_uset uset05(set01_ref.begin(), set01_ref.end(), 10, hash<char>(),
92 equal_to<char>(), alloc01);
93 size01 = uset05.size();
94 personality01 = uset05.get_allocator().get_personality();
95 my_uset uset06(set02_ref.begin(), set02_ref.end(), 10, hash<char>(),
96 equal_to<char>(), alloc02);
97 size02 = uset06.size();
98 personality02 = uset06.get_allocator().get_personality();
100 uset05.swap(uset06);
101 VERIFY( uset05.size() == size02 );
102 VERIFY( my_set(uset05.begin(), uset05.end()) == set02_ref );
103 VERIFY( uset06.size() == size01 );
104 VERIFY( my_set(uset06.begin(), uset06.end()) == set01_ref );
105 VERIFY( uset05.get_allocator().get_personality() == personality02 );
106 VERIFY( uset06.get_allocator().get_personality() == personality01 );
108 my_uset uset07(set01_ref.begin(), set01_ref.end(), 10, hash<char>(),
109 equal_to<char>(), alloc02);
110 size01 = uset07.size();
111 personality01 = uset07.get_allocator().get_personality();
112 my_uset uset08(set03_ref.begin(), set03_ref.end(), 10, hash<char>(),
113 equal_to<char>(), alloc01);
114 size02 = uset08.size();
115 personality02 = uset08.get_allocator().get_personality();
117 uset07.swap(uset08);
118 VERIFY( uset07.size() == size02 );
119 VERIFY( my_set(uset07.begin(), uset07.end()) == set03_ref );
120 VERIFY( uset08.size() == size01 );
121 VERIFY( my_set(uset08.begin(), uset08.end()) == set01_ref );
122 VERIFY( uset07.get_allocator().get_personality() == personality02 );
123 VERIFY( uset08.get_allocator().get_personality() == personality01 );
125 my_uset uset09(set03_ref.begin(), set03_ref.end(), 10, hash<char>(),
126 equal_to<char>(), alloc01);
127 size01 = uset09.size();
128 personality01 = uset09.get_allocator().get_personality();
129 my_uset uset10(set04_ref.begin(), set04_ref.end(), 10, hash<char>(),
130 equal_to<char>(), alloc02);
131 size02 = uset10.size();
132 personality02 = uset10.get_allocator().get_personality();
134 uset09.swap(uset10);
135 VERIFY( uset09.size() == size02 );
136 VERIFY( my_set(uset09.begin(), uset09.end()) == set04_ref );
137 VERIFY( uset10.size() == size01 );
138 VERIFY( my_set(uset10.begin(), uset10.end()) == set03_ref );
139 VERIFY( uset09.get_allocator().get_personality() == personality02 );
140 VERIFY( uset10.get_allocator().get_personality() == personality01 );
142 my_uset uset11(set04_ref.begin(), set04_ref.end(), 10, hash<char>(),
143 equal_to<char>(), alloc02);
144 size01 = uset11.size();
145 personality01 = uset11.get_allocator().get_personality();
146 my_uset uset12(set01_ref.begin(), set01_ref.end(), 10, hash<char>(),
147 equal_to<char>(), alloc01);
148 size02 = uset12.size();
149 personality02 = uset12.get_allocator().get_personality();
151 uset11.swap(uset12);
152 VERIFY( uset11.size() == size02 );
153 VERIFY( my_set(uset11.begin(), uset11.end()) == set01_ref );
154 VERIFY( uset12.size() == size01 );
155 VERIFY( my_set(uset12.begin(), uset12.end()) == set04_ref );
156 VERIFY( uset11.get_allocator().get_personality() == personality02 );
157 VERIFY( uset12.get_allocator().get_personality() == personality01 );
159 my_uset uset13(set03_ref.begin(), set03_ref.end(), 10, hash<char>(),
160 equal_to<char>(), alloc01);
161 size01 = uset13.size();
162 personality01 = uset13.get_allocator().get_personality();
163 my_uset uset14(set03_ref.begin(), set03_ref.end(), 10, hash<char>(),
164 equal_to<char>(), alloc02);
165 size02 = uset14.size();
166 personality02 = uset14.get_allocator().get_personality();
168 uset13.swap(uset14);
169 VERIFY( uset13.size() == size02 );
170 VERIFY( my_set(uset13.begin(), uset13.end()) == set03_ref );
171 VERIFY( uset14.size() == size01 );
172 VERIFY( my_set(uset14.begin(), uset14.end()) == set03_ref );
173 VERIFY( uset13.get_allocator().get_personality() == personality02 );
174 VERIFY( uset14.get_allocator().get_personality() == personality01 );
177 int main()
179 test01();
180 return 0;