| 1 |
// 2005-12-20 Paolo Carlini <[email protected]> |
| 2 |
|
| 3 |
// Copyright (C) 2005-2025 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 3, 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 COPYING3. If not see |
| 18 |
// <http://www.gnu.org/licenses/>. |
| 19 |
|
| 20 |
// 6.3.4.5 unordered_multiset::swap |
| 21 |
|
| 22 |
#include <tr1/unordered_set> |
| 23 |
#include <set> |
| 24 |
#include <testsuite_hooks.h> |
| 25 |
#include <testsuite_allocator.h> |
| 26 |
|
| 27 |
// uneq_allocator, two different personalities. |
| 28 |
void |
| 29 |
test01() |
| 30 |
{ |
| 31 |
using namespace std::tr1; |
| 32 |
using std::equal_to; |
| 33 |
using std::multiset; |
| 34 |
|
| 35 |
typedef __gnu_test::uneq_allocator<char> my_alloc; |
| 36 |
typedef unordered_multiset<char, hash<char>, equal_to<char>, my_alloc> |
| 37 |
my_umset; |
| 38 |
|
| 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"; |
| 43 |
|
| 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); |
| 48 |
|
| 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); |
| 54 |
|
| 55 |
my_umset::size_type size01, size02; |
| 56 |
|
| 57 |
my_alloc alloc01(1), alloc02(2); |
| 58 |
int personality01, personality02; |
| 59 |
|
| 60 |
my_umset umset01(10, hash<char>(), equal_to<char>(), alloc01); |
| 61 |
size01 = umset01.size(); |
| 62 |
personality01 = umset01.get_allocator().get_personality(); |
| 63 |
my_umset umset02(10, hash<char>(), equal_to<char>(), alloc02); |
| 64 |
size02 = umset02.size(); |
| 65 |
personality02 = umset02.get_allocator().get_personality(); |
| 66 |
|
| 67 |
umset01.swap(umset02); |
| 68 |
VERIFY( umset01.size() == size02 ); |
| 69 |
VERIFY( umset01.empty() ); |
| 70 |
VERIFY( umset02.size() == size01 ); |
| 71 |
VERIFY( umset02.empty() ); |
| 72 |
VERIFY( umset01.get_allocator().get_personality() == personality02 ); |
| 73 |
VERIFY( umset02.get_allocator().get_personality() == personality01 ); |
| 74 |
|
| 75 |
my_umset umset03(10, hash<char>(), equal_to<char>(), alloc02); |
| 76 |
size01 = umset03.size(); |
| 77 |
personality01 = umset03.get_allocator().get_personality(); |
| 78 |
my_umset umset04(mset02_ref.begin(), mset02_ref.end(), 10, hash<char>(), |
| 79 |
equal_to<char>(), alloc01); |
| 80 |
size02 = umset04.size(); |
| 81 |
personality02 = umset04.get_allocator().get_personality(); |
| 82 |
|
| 83 |
umset03.swap(umset04); |
| 84 |
VERIFY( umset03.size() == size02 ); |
| 85 |
VERIFY( my_mset(umset03.begin(), umset03.end()) == mset02_ref ); |
| 86 |
VERIFY( umset04.size() == size01 ); |
| 87 |
VERIFY( umset04.empty() ); |
| 88 |
VERIFY( umset03.get_allocator().get_personality() == personality02 ); |
| 89 |
VERIFY( umset04.get_allocator().get_personality() == personality01 ); |
| 90 |
|
| 91 |
my_umset umset05(mset01_ref.begin(), mset01_ref.end(), 10, hash<char>(), |
| 92 |
equal_to<char>(), alloc01); |
| 93 |
size01 = umset05.size(); |
| 94 |
personality01 = umset05.get_allocator().get_personality(); |
| 95 |
my_umset umset06(mset02_ref.begin(), mset02_ref.end(), 10, hash<char>(), |
| 96 |
equal_to<char>(), alloc02); |
| 97 |
size02 = umset06.size(); |
| 98 |
personality02 = umset06.get_allocator().get_personality(); |
| 99 |
|
| 100 |
umset05.swap(umset06); |
| 101 |
VERIFY( umset05.size() == size02 ); |
| 102 |
VERIFY( my_mset(umset05.begin(), umset05.end()) == mset02_ref ); |
| 103 |
VERIFY( umset06.size() == size01 ); |
| 104 |
VERIFY( my_mset(umset06.begin(), umset06.end()) == mset01_ref ); |
| 105 |
VERIFY( umset05.get_allocator().get_personality() == personality02 ); |
| 106 |
VERIFY( umset06.get_allocator().get_personality() == personality01 ); |
| 107 |
|
| 108 |
my_umset umset07(mset01_ref.begin(), mset01_ref.end(), 10, hash<char>(), |
| 109 |
equal_to<char>(), alloc02); |
| 110 |
size01 = umset07.size(); |
| 111 |
personality01 = umset07.get_allocator().get_personality(); |
| 112 |
my_umset umset08(mset03_ref.begin(), mset03_ref.end(), 10, hash<char>(), |
| 113 |
equal_to<char>(), alloc01); |
| 114 |
size02 = umset08.size(); |
| 115 |
personality02 = umset08.get_allocator().get_personality(); |
| 116 |
|
| 117 |
umset07.swap(umset08); |
| 118 |
VERIFY( umset07.size() == size02 ); |
| 119 |
VERIFY( my_mset(umset07.begin(), umset07.end()) == mset03_ref ); |
| 120 |
VERIFY( umset08.size() == size01 ); |
| 121 |
VERIFY( my_mset(umset08.begin(), umset08.end()) == mset01_ref ); |
| 122 |
VERIFY( umset07.get_allocator().get_personality() == personality02 ); |
| 123 |
VERIFY( umset08.get_allocator().get_personality() == personality01 ); |
| 124 |
|
| 125 |
my_umset umset09(mset03_ref.begin(), mset03_ref.end(), 10, hash<char>(), |
| 126 |
equal_to<char>(), alloc01); |
| 127 |
size01 = umset09.size(); |
| 128 |
personality01 = umset09.get_allocator().get_personality(); |
| 129 |
my_umset umset10(mset04_ref.begin(), mset04_ref.end(), 10, hash<char>(), |
| 130 |
equal_to<char>(), alloc02); |
| 131 |
size02 = umset10.size(); |
| 132 |
personality02 = umset10.get_allocator().get_personality(); |
| 133 |
|
| 134 |
umset09.swap(umset10); |
| 135 |
VERIFY( umset09.size() == size02 ); |
| 136 |
VERIFY( my_mset(umset09.begin(), umset09.end()) == mset04_ref ); |
| 137 |
VERIFY( umset10.size() == size01 ); |
| 138 |
VERIFY( my_mset(umset10.begin(), umset10.end()) == mset03_ref ); |
| 139 |
VERIFY( umset09.get_allocator().get_personality() == personality02 ); |
| 140 |
VERIFY( umset10.get_allocator().get_personality() == personality01 ); |
| 141 |
|
| 142 |
my_umset umset11(mset04_ref.begin(), mset04_ref.end(), 10, hash<char>(), |
| 143 |
equal_to<char>(), alloc02); |
| 144 |
size01 = umset11.size(); |
| 145 |
personality01 = umset11.get_allocator().get_personality(); |
| 146 |
my_umset umset12(mset01_ref.begin(), mset01_ref.end(), 10, hash<char>(), |
| 147 |
equal_to<char>(), alloc01); |
| 148 |
size02 = umset12.size(); |
| 149 |
personality02 = umset12.get_allocator().get_personality(); |
| 150 |
|
| 151 |
umset11.swap(umset12); |
| 152 |
VERIFY( umset11.size() == size02 ); |
| 153 |
VERIFY( my_mset(umset11.begin(), umset11.end()) == mset01_ref ); |
| 154 |
VERIFY( umset12.size() == size01 ); |
| 155 |
VERIFY( my_mset(umset12.begin(), umset12.end()) == mset04_ref ); |
| 156 |
VERIFY( umset11.get_allocator().get_personality() == personality02 ); |
| 157 |
VERIFY( umset12.get_allocator().get_personality() == personality01 ); |
| 158 |
|
| 159 |
my_umset umset13(mset03_ref.begin(), mset03_ref.end(), 10, hash<char>(), |
| 160 |
equal_to<char>(), alloc01); |
| 161 |
size01 = umset13.size(); |
| 162 |
personality01 = umset13.get_allocator().get_personality(); |
| 163 |
my_umset umset14(mset03_ref.begin(), mset03_ref.end(), 10, hash<char>(), |
| 164 |
equal_to<char>(), alloc02); |
| 165 |
size02 = umset14.size(); |
| 166 |
personality02 = umset14.get_allocator().get_personality(); |
| 167 |
|
| 168 |
umset13.swap(umset14); |
| 169 |
VERIFY( umset13.size() == size02 ); |
| 170 |
VERIFY( my_mset(umset13.begin(), umset13.end()) == mset03_ref ); |
| 171 |
VERIFY( umset14.size() == size01 ); |
| 172 |
VERIFY( my_mset(umset14.begin(), umset14.end()) == mset03_ref ); |
| 173 |
VERIFY( umset13.get_allocator().get_personality() == personality02 ); |
| 174 |
VERIFY( umset14.get_allocator().get_personality() == personality01 ); |
| 175 |
} |
| 176 |
|
| 177 |
int main() |
| 178 |
{ |
| 179 |
test01(); |
| 180 |
return 0; |
| 181 |
} |