]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/tr1/6_containers/unordered_multimap/swap/2.cc
all_bound.cc: Disambiguate uses of TR1/C++0x facilities.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / tr1 / 6_containers / unordered_multimap / swap / 2.cc
1 // 2005-12-20 Paolo Carlini <pcarlini@suse.de>
2
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.
10
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.
15
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.
20
21 // 6.3.4.6 unordered_multimap::swap
22
23 #include <tr1/unordered_map>
24 #include <map>
25 #include <testsuite_hooks.h>
26 #include <testsuite_allocator.h>
27
28 // uneq_allocator, two different personalities.
29 void
30 test01()
31 {
32 bool test __attribute__((unused)) = true;
33 using namespace std::tr1;
34 using std::pair;
35 using std::equal_to;
36 using std::map;
37 using std::multimap;
38
39 typedef pair<const char, int> my_pair;
40 typedef __gnu_test::uneq_allocator<my_pair> my_alloc;
41 typedef unordered_multimap<char, int, hash<char>, equal_to<char>, my_alloc>
42 my_ummap;
43
44 const char title01[] = "Rivers of sand";
45 const char title02[] = "Concret PH";
46 const char title03[] = "Sonatas and Interludes for Prepared Piano";
47 const char title04[] = "never as tired as when i'm waking up";
48
49 const size_t N1 = sizeof(title01);
50 const size_t N2 = sizeof(title02);
51 const size_t N3 = sizeof(title03);
52 const size_t N4 = sizeof(title04);
53
54 typedef multimap<char, int> my_mmap;
55 my_mmap mmap01_ref;
56 for (size_t i = 0; i < N1; ++i)
57 mmap01_ref.insert(my_pair(title01[i], i));
58 my_mmap mmap02_ref;
59 for (size_t i = 0; i < N2; ++i)
60 mmap02_ref.insert(my_pair(title02[i], i));
61 my_mmap mmap03_ref;
62 for (size_t i = 0; i < N3; ++i)
63 mmap03_ref.insert(my_pair(title03[i], i));
64 my_mmap mmap04_ref;
65 for (size_t i = 0; i < N4; ++i)
66 mmap04_ref.insert(my_pair(title04[i], i));
67
68 typedef map<char, int> my_map;
69
70 my_ummap::size_type size01, size02;
71
72 my_alloc alloc01(1), alloc02(2);
73 int personality01, personality02;
74
75 my_ummap ummap01(10, hash<char>(), equal_to<char>(), alloc01);
76 size01 = ummap01.size();
77 personality01 = ummap01.get_allocator().get_personality();
78 my_ummap ummap02(10, hash<char>(), equal_to<char>(), alloc02);
79 size02 = ummap02.size();
80 personality02 = ummap02.get_allocator().get_personality();
81
82 ummap01.swap(ummap02);
83 VERIFY( ummap01.size() == size02 );
84 VERIFY( ummap01.empty() );
85 VERIFY( ummap02.size() == size01 );
86 VERIFY( ummap02.empty() );
87 VERIFY( ummap01.get_allocator().get_personality() == personality02 );
88 VERIFY( ummap02.get_allocator().get_personality() == personality01 );
89
90 my_ummap ummap03(10, hash<char>(), equal_to<char>(), alloc02);
91 size01 = ummap03.size();
92 personality01 = ummap03.get_allocator().get_personality();
93 my_ummap ummap04(mmap02_ref.begin(), mmap02_ref.end(), 10, hash<char>(),
94 equal_to<char>(), alloc01);
95 size02 = ummap04.size();
96 personality02 = ummap04.get_allocator().get_personality();
97
98 ummap03.swap(ummap04);
99 VERIFY( ummap03.size() == size02 );
100 VERIFY( my_map(ummap03.begin(), ummap03.end())
101 == my_map(mmap02_ref.begin(), mmap02_ref.end()) );
102 VERIFY( ummap04.size() == size01 );
103 VERIFY( ummap04.empty() );
104 VERIFY( ummap03.get_allocator().get_personality() == personality02 );
105 VERIFY( ummap04.get_allocator().get_personality() == personality01 );
106
107 my_ummap ummap05(mmap01_ref.begin(), mmap01_ref.end(), 10, hash<char>(),
108 equal_to<char>(), alloc01);
109 size01 = ummap05.size();
110 personality01 = ummap05.get_allocator().get_personality();
111 my_ummap ummap06(mmap02_ref.begin(), mmap02_ref.end(), 10, hash<char>(),
112 equal_to<char>(), alloc02);
113 size02 = ummap06.size();
114 personality02 = ummap06.get_allocator().get_personality();
115
116 ummap05.swap(ummap06);
117 VERIFY( ummap05.size() == size02 );
118 VERIFY( my_map(ummap05.begin(), ummap05.end())
119 == my_map(mmap02_ref.begin(), mmap02_ref.end()) );
120 VERIFY( ummap06.size() == size01 );
121 VERIFY( my_map(ummap06.begin(), ummap06.end())
122 == my_map(mmap01_ref.begin(), mmap01_ref.end()) );
123 VERIFY( ummap05.get_allocator().get_personality() == personality02 );
124 VERIFY( ummap06.get_allocator().get_personality() == personality01 );
125
126 my_ummap ummap07(mmap01_ref.begin(), mmap01_ref.end(), 10, hash<char>(),
127 equal_to<char>(), alloc02);
128 size01 = ummap07.size();
129 personality01 = ummap07.get_allocator().get_personality();
130 my_ummap ummap08(mmap03_ref.begin(), mmap03_ref.end(), 10, hash<char>(),
131 equal_to<char>(), alloc01);
132 size02 = ummap08.size();
133 personality02 = ummap08.get_allocator().get_personality();
134
135 ummap07.swap(ummap08);
136 VERIFY( ummap07.size() == size02 );
137 VERIFY( my_map(ummap07.begin(), ummap07.end())
138 == my_map(mmap03_ref.begin(), mmap03_ref.end()) );
139 VERIFY( ummap08.size() == size01 );
140 VERIFY( my_map(ummap08.begin(), ummap08.end())
141 == my_map(mmap01_ref.begin(), mmap01_ref.end()) );
142 VERIFY( ummap07.get_allocator().get_personality() == personality02 );
143 VERIFY( ummap08.get_allocator().get_personality() == personality01 );
144
145 my_ummap ummap09(mmap03_ref.begin(), mmap03_ref.end(), 10, hash<char>(),
146 equal_to<char>(), alloc01);
147 size01 = ummap09.size();
148 personality01 = ummap09.get_allocator().get_personality();
149 my_ummap ummap10(mmap04_ref.begin(), mmap04_ref.end(), 10, hash<char>(),
150 equal_to<char>(), alloc02);
151 size02 = ummap10.size();
152 personality02 = ummap10.get_allocator().get_personality();
153
154 ummap09.swap(ummap10);
155 VERIFY( ummap09.size() == size02 );
156 VERIFY( my_map(ummap09.begin(), ummap09.end())
157 == my_map(mmap04_ref.begin(), mmap04_ref.end()) );
158 VERIFY( ummap10.size() == size01 );
159 VERIFY( my_map(ummap10.begin(), ummap10.end())
160 == my_map(mmap03_ref.begin(), mmap03_ref.end()) );
161 VERIFY( ummap09.get_allocator().get_personality() == personality02 );
162 VERIFY( ummap10.get_allocator().get_personality() == personality01 );
163
164 my_ummap ummap11(mmap04_ref.begin(), mmap04_ref.end(), 10, hash<char>(),
165 equal_to<char>(), alloc02);
166 size01 = ummap11.size();
167 personality01 = ummap11.get_allocator().get_personality();
168 my_ummap ummap12(mmap01_ref.begin(), mmap01_ref.end(), 10, hash<char>(),
169 equal_to<char>(), alloc01);
170 size02 = ummap12.size();
171 personality02 = ummap12.get_allocator().get_personality();
172
173 ummap11.swap(ummap12);
174 VERIFY( ummap11.size() == size02 );
175 VERIFY( my_map(ummap11.begin(), ummap11.end())
176 == my_map(mmap01_ref.begin(), mmap01_ref.end()) );
177 VERIFY( ummap12.size() == size01 );
178 VERIFY( my_map(ummap12.begin(), ummap12.end())
179 == my_map(mmap04_ref.begin(), mmap04_ref.end()) );
180 VERIFY( ummap11.get_allocator().get_personality() == personality02 );
181 VERIFY( ummap12.get_allocator().get_personality() == personality01 );
182
183 my_ummap ummap13(mmap03_ref.begin(), mmap03_ref.end(), 10, hash<char>(),
184 equal_to<char>(), alloc01);
185 size01 = ummap13.size();
186 personality01 = ummap13.get_allocator().get_personality();
187 my_ummap ummap14(mmap03_ref.begin(), mmap03_ref.end(), 10, hash<char>(),
188 equal_to<char>(), alloc02);
189 size02 = ummap14.size();
190 personality02 = ummap14.get_allocator().get_personality();
191
192 ummap13.swap(ummap14);
193 VERIFY( ummap13.size() == size02 );
194 VERIFY( my_map(ummap13.begin(), ummap13.end())
195 == my_map(mmap03_ref.begin(), mmap03_ref.end()) );
196 VERIFY( ummap14.size() == size01 );
197 VERIFY( my_map(ummap14.begin(), ummap14.end())
198 == my_map(mmap03_ref.begin(), mmap03_ref.end()) );
199 VERIFY( ummap13.get_allocator().get_personality() == personality02 );
200 VERIFY( ummap14.get_allocator().get_personality() == personality01 );
201 }
202
203 int main()
204 {
205 test01();
206 return 0;
207 }