diff options
author | Paolo Carlini <paolo@gcc.gnu.org> | 2006-01-04 11:34:45 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2006-01-04 11:34:45 +0000 |
commit | f7ace77f1f4a713c2e96b4daf6181216b5df29d9 (patch) | |
tree | cd3bddece803156966caae41da6fe7437f45b8f1 /libstdc++-v3/testsuite/tr1/6_containers | |
parent | db5d99e8b1c97aac22051f5dfd9296283e0d9848 (diff) | |
download | gcc-f7ace77f1f4a713c2e96b4daf6181216b5df29d9.tar.gz |
sso_string_base.h (__sso_string_base<>::_M_dataplus): Use _CharT_alloc_type as base class.
2006-01-04 Paolo Carlini <pcarlini@suse.de>
* include/ext/sso_string_base.h (__sso_string_base<>::_M_dataplus):
Use _CharT_alloc_type as base class.
(_M_get_allocator, _M_swap, _M_create, _M_destroy): Adjust.
* include/ext/vstring.h (get_allocator): Tidy.
2006-01-04 Paolo Carlini <pcarlini@suse.de>
Implement Option 3 of DR 431 for all the containers.
* include/bits/allocator.h (struct __alloc_swap): Add, swaps
allocators, optimized to nothing in case they are empty.
* include/bits/stl_deque.h (deque<>::swap): Use it.
* include/bits/stl_list.h (list<>::swap): Likewise.
* include/bits/stl_tree.h (_Rb_tree<>::swap): Likewise.
* include/bits/stl_vector.h (vector<>::swap): Likewise.
* include/tr1/hashtable (hashtable<>::swap): Likewise.
* include/ext/rc_string_base.h (__rc_string_base<>::_M_swap):
Likewise.
* include/ext/sso_string_base.h (__sso_string_base<>::_M_swap):
Likewise.
* include/ext/vstring_util.h (__vstring_utility<>::_Alloc_hider):
Clean-up (now vstring uses the generic __alloc_swap facility).
* include/tr1/unordered_map: Adjust includes.
* include/tr1/unordered_set: Likewise.
* docs/html/ext/howto.html: Add an entry for DR 431.
* testsuite/23_containers/deque/modifiers/swap.cc: Move to...
* testsuite/23_containers/deque/modifiers/swap/1.cc: ... here.
* testsuite/23_containers/deque/modifiers/swap/2.cc: New.
* testsuite/23_containers/deque/modifiers/swap/3.cc: New.
* testsuite/23_containers/list/modifiers/swap.cc: Move to...
* testsuite/23_containers/list/modifiers/swap/1.cc: ... here.
* testsuite/23_containers/list/modifiers/swap/2.cc: New.
* testsuite/23_containers/list/modifiers/swap/3.cc: New.
* testsuite/23_containers/vector/modifiers/swap.cc: Move to...
* testsuite/23_containers/vector/modifiers/swap/1.cc: ... here.
* testsuite/23_containers/vector/modifiers/swap/2.cc: New.
* testsuite/23_containers/vector/modifiers/swap/3.cc: New.
* testsuite/23_containers/set/modifiers/swap.cc: Move to...
* testsuite/23_containers/set/modifiers/swap/1.cc: ... here.
* testsuite/23_containers/set/modifiers/swap/2.cc: New.
* testsuite/23_containers/set/modifiers/swap/3.cc: New.
* testsuite/23_containers/map/modifiers/swap.cc: Move to...
* testsuite/23_containers/map/modifiers/swap/1.cc: ... here.
* testsuite/23_containers/map/modifiers/swap/2.cc: New.
* testsuite/23_containers/map/modifiers/swap/3.cc: New.
* testsuite/23_containers/multiset/modifiers/swap.cc: Move to...
* testsuite/23_containers/multiset/modifiers/swap/1.cc: ... here.
* testsuite/23_containers/multiset/modifiers/swap/2.cc: New.
* testsuite/23_containers/multiset/modifiers/swap/3.cc: New.
* testsuite/23_containers/multimap/modifiers/swap.cc: Move to...
* testsuite/23_containers/multimap/modifiers/swap/1.cc: ... here.
* testsuite/23_containers/multimap/modifiers/swap/2.cc: New.
* testsuite/23_containers/multimap/modifiers/swap/3.cc: New.
* testsuite/tr1/6_containers/unordered/swap/unordered_set/1.cc: New.
* testsuite/tr1/6_containers/unordered/swap/unordered_set/2.cc: New.
* testsuite/tr1/6_containers/unordered/swap/unordered_map/1.cc: New.
* testsuite/tr1/6_containers/unordered/swap/unordered_map/2.cc: New.
* testsuite/tr1/6_containers/unordered/swap/unordered_multiset/1.cc: New.
* testsuite/tr1/6_containers/unordered/swap/unordered_multiset/2.cc: New.
* testsuite/tr1/6_containers/unordered/swap/unordered_multimap/1.cc: New.
* testsuite/tr1/6_containers/unordered/swap/unordered_multimap/2.cc: New.
From-SVN: r109324
Diffstat (limited to 'libstdc++-v3/testsuite/tr1/6_containers')
8 files changed, 1400 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_map/1.cc b/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_map/1.cc new file mode 100644 index 00000000000..d379774926d --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_map/1.cc @@ -0,0 +1,162 @@ +// 2005-12-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 6.3.4.4 unordered_map::swap + +#include <tr1/unordered_map> +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator as a non-empty allocator. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + using namespace tr1; + + typedef pair<const char, int> my_pair; + typedef __gnu_test::uneq_allocator<my_pair> my_alloc; + typedef unordered_map<char, int, hash<char>, equal_to<char>, my_alloc> + my_umap; + + const char title01[] = "Rivers of sand"; + const char title02[] = "Concret PH"; + const char title03[] = "Sonatas and Interludes for Prepared Piano"; + const char title04[] = "never as tired as when i'm waking up"; + + const size_t N1 = sizeof(title01); + const size_t N2 = sizeof(title02); + const size_t N3 = sizeof(title03); + const size_t N4 = sizeof(title04); + + typedef map<char, int> my_map; + my_map map01_ref; + for (size_t i = 0; i < N1; ++i) + map01_ref.insert(my_pair(title01[i], i)); + my_map map02_ref; + for (size_t i = 0; i < N2; ++i) + map02_ref.insert(my_pair(title02[i], i)); + my_map map03_ref; + for (size_t i = 0; i < N3; ++i) + map03_ref.insert(my_pair(title03[i], i)); + my_map map04_ref; + for (size_t i = 0; i < N4; ++i) + map04_ref.insert(my_pair(title04[i], i)); + + my_umap::size_type size01, size02; + + my_alloc alloc01(1); + + my_umap umap01(10, hash<char>(), equal_to<char>(), alloc01); + size01 = umap01.size(); + my_umap umap02(10, hash<char>(), equal_to<char>(), alloc01); + size02 = umap02.size(); + + umap01.swap(umap02); + VERIFY( umap01.size() == size02 ); + VERIFY( umap01.empty() ); + VERIFY( umap02.size() == size01 ); + VERIFY( umap02.empty() ); + + my_umap umap03(10, hash<char>(), equal_to<char>(), alloc01); + size01 = umap03.size(); + my_umap umap04(map02_ref.begin(), map02_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = umap04.size(); + + umap03.swap(umap04); + VERIFY( umap03.size() == size02 ); + VERIFY( my_map(umap03.begin(), umap03.end()) == map02_ref ); + VERIFY( umap04.size() == size01 ); + VERIFY( umap04.empty() ); + + my_umap umap05(map01_ref.begin(), map01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = umap05.size(); + my_umap umap06(map02_ref.begin(), map02_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = umap06.size(); + + umap05.swap(umap06); + VERIFY( umap05.size() == size02 ); + VERIFY( my_map(umap05.begin(), umap05.end()) == map02_ref ); + VERIFY( umap06.size() == size01 ); + VERIFY( my_map(umap06.begin(), umap06.end()) == map01_ref ); + + my_umap umap07(map01_ref.begin(), map01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = umap07.size(); + my_umap umap08(map03_ref.begin(), map03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = umap08.size(); + + umap07.swap(umap08); + VERIFY( umap07.size() == size02 ); + VERIFY( my_map(umap07.begin(), umap07.end()) == map03_ref ); + VERIFY( umap08.size() == size01 ); + VERIFY( my_map(umap08.begin(), umap08.end()) == map01_ref ); + + my_umap umap09(map03_ref.begin(), map03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = umap09.size(); + my_umap umap10(map04_ref.begin(), map04_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = umap10.size(); + + umap09.swap(umap10); + VERIFY( umap09.size() == size02 ); + VERIFY( my_map(umap09.begin(), umap09.end()) == map04_ref ); + VERIFY( umap10.size() == size01 ); + VERIFY( my_map(umap10.begin(), umap10.end()) == map03_ref ); + + my_umap umap11(map04_ref.begin(), map04_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = umap11.size(); + my_umap umap12(map01_ref.begin(), map01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = umap12.size(); + + umap11.swap(umap12); + VERIFY( umap11.size() == size02 ); + VERIFY( my_map(umap11.begin(), umap11.end()) == map01_ref ); + VERIFY( umap12.size() == size01 ); + VERIFY( my_map(umap12.begin(), umap12.end()) == map04_ref ); + + my_umap umap13(map03_ref.begin(), map03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = umap13.size(); + my_umap umap14(map03_ref.begin(), map03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = umap14.size(); + + umap13.swap(umap14); + VERIFY( umap13.size() == size02 ); + VERIFY( my_map(umap13.begin(), umap13.end()) == map03_ref ); + VERIFY( umap14.size() == size01 ); + VERIFY( my_map(umap14.begin(), umap14.end()) == map03_ref ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_map/2.cc b/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_map/2.cc new file mode 100644 index 00000000000..8d708292ae3 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_map/2.cc @@ -0,0 +1,191 @@ +// 2005-12-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 6.3.4.4 unordered_map::swap + +#include <tr1/unordered_map> +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator, two different personalities. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + using namespace tr1; + + typedef pair<const char, int> my_pair; + typedef __gnu_test::uneq_allocator<my_pair> my_alloc; + typedef unordered_map<char, int, hash<char>, equal_to<char>, my_alloc> + my_umap; + + const char title01[] = "Rivers of sand"; + const char title02[] = "Concret PH"; + const char title03[] = "Sonatas and Interludes for Prepared Piano"; + const char title04[] = "never as tired as when i'm waking up"; + + const size_t N1 = sizeof(title01); + const size_t N2 = sizeof(title02); + const size_t N3 = sizeof(title03); + const size_t N4 = sizeof(title04); + + typedef map<char, int> my_map; + my_map map01_ref; + for (size_t i = 0; i < N1; ++i) + map01_ref.insert(my_pair(title01[i], i)); + my_map map02_ref; + for (size_t i = 0; i < N2; ++i) + map02_ref.insert(my_pair(title02[i], i)); + my_map map03_ref; + for (size_t i = 0; i < N3; ++i) + map03_ref.insert(my_pair(title03[i], i)); + my_map map04_ref; + for (size_t i = 0; i < N4; ++i) + map04_ref.insert(my_pair(title04[i], i)); + + my_umap::size_type size01, size02; + + my_alloc alloc01(1), alloc02(2); + int personality01, personality02; + + my_umap umap01(10, hash<char>(), equal_to<char>(), alloc01); + size01 = umap01.size(); + personality01 = umap01.get_allocator().get_personality(); + my_umap umap02(10, hash<char>(), equal_to<char>(), alloc02); + size02 = umap02.size(); + personality02 = umap02.get_allocator().get_personality(); + + umap01.swap(umap02); + VERIFY( umap01.size() == size02 ); + VERIFY( umap01.empty() ); + VERIFY( umap02.size() == size01 ); + VERIFY( umap02.empty() ); + VERIFY( umap01.get_allocator().get_personality() == personality02 ); + VERIFY( umap02.get_allocator().get_personality() == personality01 ); + + my_umap umap03(10, hash<char>(), equal_to<char>(), alloc02); + size01 = umap03.size(); + personality01 = umap03.get_allocator().get_personality(); + my_umap umap04(map02_ref.begin(), map02_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = umap04.size(); + personality02 = umap04.get_allocator().get_personality(); + + umap03.swap(umap04); + VERIFY( umap03.size() == size02 ); + VERIFY( my_map(umap03.begin(), umap03.end()) == map02_ref ); + VERIFY( umap04.size() == size01 ); + VERIFY( umap04.empty() ); + VERIFY( umap03.get_allocator().get_personality() == personality02 ); + VERIFY( umap04.get_allocator().get_personality() == personality01 ); + + my_umap umap05(map01_ref.begin(), map01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = umap05.size(); + personality01 = umap05.get_allocator().get_personality(); + my_umap umap06(map02_ref.begin(), map02_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size02 = umap06.size(); + personality02 = umap06.get_allocator().get_personality(); + + umap05.swap(umap06); + VERIFY( umap05.size() == size02 ); + VERIFY( my_map(umap05.begin(), umap05.end()) == map02_ref ); + VERIFY( umap06.size() == size01 ); + VERIFY( my_map(umap06.begin(), umap06.end()) == map01_ref ); + VERIFY( umap05.get_allocator().get_personality() == personality02 ); + VERIFY( umap06.get_allocator().get_personality() == personality01 ); + + my_umap umap07(map01_ref.begin(), map01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size01 = umap07.size(); + personality01 = umap07.get_allocator().get_personality(); + my_umap umap08(map03_ref.begin(), map03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = umap08.size(); + personality02 = umap08.get_allocator().get_personality(); + + umap07.swap(umap08); + VERIFY( umap07.size() == size02 ); + VERIFY( my_map(umap07.begin(), umap07.end()) == map03_ref ); + VERIFY( umap08.size() == size01 ); + VERIFY( my_map(umap08.begin(), umap08.end()) == map01_ref ); + VERIFY( umap07.get_allocator().get_personality() == personality02 ); + VERIFY( umap08.get_allocator().get_personality() == personality01 ); + + my_umap umap09(map03_ref.begin(), map03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = umap09.size(); + personality01 = umap09.get_allocator().get_personality(); + my_umap umap10(map04_ref.begin(), map04_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size02 = umap10.size(); + personality02 = umap10.get_allocator().get_personality(); + + umap09.swap(umap10); + VERIFY( umap09.size() == size02 ); + VERIFY( my_map(umap09.begin(), umap09.end()) == map04_ref ); + VERIFY( umap10.size() == size01 ); + VERIFY( my_map(umap10.begin(), umap10.end()) == map03_ref ); + VERIFY( umap09.get_allocator().get_personality() == personality02 ); + VERIFY( umap10.get_allocator().get_personality() == personality01 ); + + my_umap umap11(map04_ref.begin(), map04_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size01 = umap11.size(); + personality01 = umap11.get_allocator().get_personality(); + my_umap umap12(map01_ref.begin(), map01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = umap12.size(); + personality02 = umap12.get_allocator().get_personality(); + + umap11.swap(umap12); + VERIFY( umap11.size() == size02 ); + VERIFY( my_map(umap11.begin(), umap11.end()) == map01_ref ); + VERIFY( umap12.size() == size01 ); + VERIFY( my_map(umap12.begin(), umap12.end()) == map04_ref ); + VERIFY( umap11.get_allocator().get_personality() == personality02 ); + VERIFY( umap12.get_allocator().get_personality() == personality01 ); + + my_umap umap13(map03_ref.begin(), map03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = umap13.size(); + personality01 = umap13.get_allocator().get_personality(); + my_umap umap14(map03_ref.begin(), map03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size02 = umap14.size(); + personality02 = umap14.get_allocator().get_personality(); + + umap13.swap(umap14); + VERIFY( umap13.size() == size02 ); + VERIFY( my_map(umap13.begin(), umap13.end()) == map03_ref ); + VERIFY( umap14.size() == size01 ); + VERIFY( my_map(umap14.begin(), umap14.end()) == map03_ref ); + VERIFY( umap13.get_allocator().get_personality() == personality02 ); + VERIFY( umap14.get_allocator().get_personality() == personality01 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_multimap/1.cc b/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_multimap/1.cc new file mode 100644 index 00000000000..7648e08bd62 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_multimap/1.cc @@ -0,0 +1,175 @@ +// 2005-12-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 6.3.4.6 unordered_multimap::swap + +#include <tr1/unordered_map> +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator as a non-empty allocator. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + using namespace tr1; + + typedef pair<const char, int> my_pair; + typedef __gnu_test::uneq_allocator<my_pair> my_alloc; + typedef unordered_multimap<char, int, hash<char>, equal_to<char>, my_alloc> + my_ummap; + + const char title01[] = "Rivers of sand"; + const char title02[] = "Concret PH"; + const char title03[] = "Sonatas and Interludes for Prepared Piano"; + const char title04[] = "never as tired as when i'm waking up"; + + const size_t N1 = sizeof(title01); + const size_t N2 = sizeof(title02); + const size_t N3 = sizeof(title03); + const size_t N4 = sizeof(title04); + + typedef multimap<char, int> my_mmap; + my_mmap mmap01_ref; + for (size_t i = 0; i < N1; ++i) + mmap01_ref.insert(my_pair(title01[i], i)); + my_mmap mmap02_ref; + for (size_t i = 0; i < N2; ++i) + mmap02_ref.insert(my_pair(title02[i], i)); + my_mmap mmap03_ref; + for (size_t i = 0; i < N3; ++i) + mmap03_ref.insert(my_pair(title03[i], i)); + my_mmap mmap04_ref; + for (size_t i = 0; i < N4; ++i) + mmap04_ref.insert(my_pair(title04[i], i)); + + typedef map<char, int> my_map; + + my_ummap::size_type size01, size02; + + my_alloc alloc01(1); + + my_ummap ummap01(10, hash<char>(), equal_to<char>(), alloc01); + size01 = ummap01.size(); + my_ummap ummap02(10, hash<char>(), equal_to<char>(), alloc01); + size02 = ummap02.size(); + + ummap01.swap(ummap02); + VERIFY( ummap01.size() == size02 ); + VERIFY( ummap01.empty() ); + VERIFY( ummap02.size() == size01 ); + VERIFY( ummap02.empty() ); + + my_ummap ummap03(10, hash<char>(), equal_to<char>(), alloc01); + size01 = ummap03.size(); + my_ummap ummap04(mmap02_ref.begin(), mmap02_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = ummap04.size(); + + ummap03.swap(ummap04); + VERIFY( ummap03.size() == size02 ); + VERIFY( my_map(ummap03.begin(), ummap03.end()) + == my_map(mmap02_ref.begin(), mmap02_ref.end()) ); + VERIFY( ummap04.size() == size01 ); + VERIFY( ummap04.empty() ); + + my_ummap ummap05(mmap01_ref.begin(), mmap01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = ummap05.size(); + my_ummap ummap06(mmap02_ref.begin(), mmap02_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = ummap06.size(); + + ummap05.swap(ummap06); + VERIFY( ummap05.size() == size02 ); + VERIFY( my_map(ummap05.begin(), ummap05.end()) + == my_map(mmap02_ref.begin(), mmap02_ref.end()) ); + VERIFY( ummap06.size() == size01 ); + VERIFY( my_map(ummap06.begin(), ummap06.end()) + == my_map(mmap01_ref.begin(), mmap01_ref.end()) ); + + my_ummap ummap07(mmap01_ref.begin(), mmap01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = ummap07.size(); + my_ummap ummap08(mmap03_ref.begin(), mmap03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = ummap08.size(); + + ummap07.swap(ummap08); + VERIFY( ummap07.size() == size02 ); + VERIFY( my_map(ummap07.begin(), ummap07.end()) + == my_map(mmap03_ref.begin(), mmap03_ref.end()) ); + VERIFY( ummap08.size() == size01 ); + VERIFY( my_map(ummap08.begin(), ummap08.end()) + == my_map(mmap01_ref.begin(), mmap01_ref.end()) ); + + my_ummap ummap09(mmap03_ref.begin(), mmap03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = ummap09.size(); + my_ummap ummap10(mmap04_ref.begin(), mmap04_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = ummap10.size(); + + ummap09.swap(ummap10); + VERIFY( ummap09.size() == size02 ); + VERIFY( my_map(ummap09.begin(), ummap09.end()) + == my_map(mmap04_ref.begin(), mmap04_ref.end()) ); + VERIFY( ummap10.size() == size01 ); + VERIFY( my_map(ummap10.begin(), ummap10.end()) + == my_map(mmap03_ref.begin(), mmap03_ref.end()) ); + + my_ummap ummap11(mmap04_ref.begin(), mmap04_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = ummap11.size(); + my_ummap ummap12(mmap01_ref.begin(), mmap01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = ummap12.size(); + + ummap11.swap(ummap12); + VERIFY( ummap11.size() == size02 ); + VERIFY( my_map(ummap11.begin(), ummap11.end()) + == my_map(mmap01_ref.begin(), mmap01_ref.end()) ); + VERIFY( ummap12.size() == size01 ); + VERIFY( my_map(ummap12.begin(), ummap12.end()) + == my_map(mmap04_ref.begin(), mmap04_ref.end()) ); + + my_ummap ummap13(mmap03_ref.begin(), mmap03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = ummap13.size(); + my_ummap ummap14(mmap03_ref.begin(), mmap03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = ummap14.size(); + + ummap13.swap(ummap14); + VERIFY( ummap13.size() == size02 ); + VERIFY( my_map(ummap13.begin(), ummap13.end()) + == my_map(mmap03_ref.begin(), mmap03_ref.end()) ); + VERIFY( ummap14.size() == size01 ); + VERIFY( my_map(ummap14.begin(), ummap14.end()) + == my_map(mmap03_ref.begin(), mmap03_ref.end()) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_multimap/2.cc b/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_multimap/2.cc new file mode 100644 index 00000000000..f7744ebe854 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_multimap/2.cc @@ -0,0 +1,204 @@ +// 2005-12-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 6.3.4.6 unordered_multimap::swap + +#include <tr1/unordered_map> +#include <map> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator, two different personalities. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + using namespace tr1; + + typedef pair<const char, int> my_pair; + typedef __gnu_test::uneq_allocator<my_pair> my_alloc; + typedef unordered_multimap<char, int, hash<char>, equal_to<char>, my_alloc> + my_ummap; + + const char title01[] = "Rivers of sand"; + const char title02[] = "Concret PH"; + const char title03[] = "Sonatas and Interludes for Prepared Piano"; + const char title04[] = "never as tired as when i'm waking up"; + + const size_t N1 = sizeof(title01); + const size_t N2 = sizeof(title02); + const size_t N3 = sizeof(title03); + const size_t N4 = sizeof(title04); + + typedef multimap<char, int> my_mmap; + my_mmap mmap01_ref; + for (size_t i = 0; i < N1; ++i) + mmap01_ref.insert(my_pair(title01[i], i)); + my_mmap mmap02_ref; + for (size_t i = 0; i < N2; ++i) + mmap02_ref.insert(my_pair(title02[i], i)); + my_mmap mmap03_ref; + for (size_t i = 0; i < N3; ++i) + mmap03_ref.insert(my_pair(title03[i], i)); + my_mmap mmap04_ref; + for (size_t i = 0; i < N4; ++i) + mmap04_ref.insert(my_pair(title04[i], i)); + + typedef map<char, int> my_map; + + my_ummap::size_type size01, size02; + + my_alloc alloc01(1), alloc02(2); + int personality01, personality02; + + my_ummap ummap01(10, hash<char>(), equal_to<char>(), alloc01); + size01 = ummap01.size(); + personality01 = ummap01.get_allocator().get_personality(); + my_ummap ummap02(10, hash<char>(), equal_to<char>(), alloc02); + size02 = ummap02.size(); + personality02 = ummap02.get_allocator().get_personality(); + + ummap01.swap(ummap02); + VERIFY( ummap01.size() == size02 ); + VERIFY( ummap01.empty() ); + VERIFY( ummap02.size() == size01 ); + VERIFY( ummap02.empty() ); + VERIFY( ummap01.get_allocator().get_personality() == personality02 ); + VERIFY( ummap02.get_allocator().get_personality() == personality01 ); + + my_ummap ummap03(10, hash<char>(), equal_to<char>(), alloc02); + size01 = ummap03.size(); + personality01 = ummap03.get_allocator().get_personality(); + my_ummap ummap04(mmap02_ref.begin(), mmap02_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = ummap04.size(); + personality02 = ummap04.get_allocator().get_personality(); + + ummap03.swap(ummap04); + VERIFY( ummap03.size() == size02 ); + VERIFY( my_map(ummap03.begin(), ummap03.end()) + == my_map(mmap02_ref.begin(), mmap02_ref.end()) ); + VERIFY( ummap04.size() == size01 ); + VERIFY( ummap04.empty() ); + VERIFY( ummap03.get_allocator().get_personality() == personality02 ); + VERIFY( ummap04.get_allocator().get_personality() == personality01 ); + + my_ummap ummap05(mmap01_ref.begin(), mmap01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = ummap05.size(); + personality01 = ummap05.get_allocator().get_personality(); + my_ummap ummap06(mmap02_ref.begin(), mmap02_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size02 = ummap06.size(); + personality02 = ummap06.get_allocator().get_personality(); + + ummap05.swap(ummap06); + VERIFY( ummap05.size() == size02 ); + VERIFY( my_map(ummap05.begin(), ummap05.end()) + == my_map(mmap02_ref.begin(), mmap02_ref.end()) ); + VERIFY( ummap06.size() == size01 ); + VERIFY( my_map(ummap06.begin(), ummap06.end()) + == my_map(mmap01_ref.begin(), mmap01_ref.end()) ); + VERIFY( ummap05.get_allocator().get_personality() == personality02 ); + VERIFY( ummap06.get_allocator().get_personality() == personality01 ); + + my_ummap ummap07(mmap01_ref.begin(), mmap01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size01 = ummap07.size(); + personality01 = ummap07.get_allocator().get_personality(); + my_ummap ummap08(mmap03_ref.begin(), mmap03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = ummap08.size(); + personality02 = ummap08.get_allocator().get_personality(); + + ummap07.swap(ummap08); + VERIFY( ummap07.size() == size02 ); + VERIFY( my_map(ummap07.begin(), ummap07.end()) + == my_map(mmap03_ref.begin(), mmap03_ref.end()) ); + VERIFY( ummap08.size() == size01 ); + VERIFY( my_map(ummap08.begin(), ummap08.end()) + == my_map(mmap01_ref.begin(), mmap01_ref.end()) ); + VERIFY( ummap07.get_allocator().get_personality() == personality02 ); + VERIFY( ummap08.get_allocator().get_personality() == personality01 ); + + my_ummap ummap09(mmap03_ref.begin(), mmap03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = ummap09.size(); + personality01 = ummap09.get_allocator().get_personality(); + my_ummap ummap10(mmap04_ref.begin(), mmap04_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size02 = ummap10.size(); + personality02 = ummap10.get_allocator().get_personality(); + + ummap09.swap(ummap10); + VERIFY( ummap09.size() == size02 ); + VERIFY( my_map(ummap09.begin(), ummap09.end()) + == my_map(mmap04_ref.begin(), mmap04_ref.end()) ); + VERIFY( ummap10.size() == size01 ); + VERIFY( my_map(ummap10.begin(), ummap10.end()) + == my_map(mmap03_ref.begin(), mmap03_ref.end()) ); + VERIFY( ummap09.get_allocator().get_personality() == personality02 ); + VERIFY( ummap10.get_allocator().get_personality() == personality01 ); + + my_ummap ummap11(mmap04_ref.begin(), mmap04_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size01 = ummap11.size(); + personality01 = ummap11.get_allocator().get_personality(); + my_ummap ummap12(mmap01_ref.begin(), mmap01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = ummap12.size(); + personality02 = ummap12.get_allocator().get_personality(); + + ummap11.swap(ummap12); + VERIFY( ummap11.size() == size02 ); + VERIFY( my_map(ummap11.begin(), ummap11.end()) + == my_map(mmap01_ref.begin(), mmap01_ref.end()) ); + VERIFY( ummap12.size() == size01 ); + VERIFY( my_map(ummap12.begin(), ummap12.end()) + == my_map(mmap04_ref.begin(), mmap04_ref.end()) ); + VERIFY( ummap11.get_allocator().get_personality() == personality02 ); + VERIFY( ummap12.get_allocator().get_personality() == personality01 ); + + my_ummap ummap13(mmap03_ref.begin(), mmap03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = ummap13.size(); + personality01 = ummap13.get_allocator().get_personality(); + my_ummap ummap14(mmap03_ref.begin(), mmap03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size02 = ummap14.size(); + personality02 = ummap14.get_allocator().get_personality(); + + ummap13.swap(ummap14); + VERIFY( ummap13.size() == size02 ); + VERIFY( my_map(ummap13.begin(), ummap13.end()) + == my_map(mmap03_ref.begin(), mmap03_ref.end()) ); + VERIFY( ummap14.size() == size01 ); + VERIFY( my_map(ummap14.begin(), ummap14.end()) + == my_map(mmap03_ref.begin(), mmap03_ref.end()) ); + VERIFY( ummap13.get_allocator().get_personality() == personality02 ); + VERIFY( ummap14.get_allocator().get_personality() == personality01 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_multiset/1.cc b/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_multiset/1.cc new file mode 100644 index 00000000000..ca0194e3375 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_multiset/1.cc @@ -0,0 +1,153 @@ +// 2005-12-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 6.3.4.5 unordered_multiset::swap + +#include <tr1/unordered_set> +#include <set> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator as a non-empty allocator. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + using namespace tr1; + + typedef __gnu_test::uneq_allocator<char> my_alloc; + typedef unordered_multiset<char, hash<char>, equal_to<char>, my_alloc> + my_umset; + + const char title01[] = "Rivers of sand"; + const char title02[] = "Concret PH"; + const char title03[] = "Sonatas and Interludes for Prepared Piano"; + const char title04[] = "never as tired as when i'm waking up"; + + const size_t N1 = sizeof(title01); + const size_t N2 = sizeof(title02); + const size_t N3 = sizeof(title03); + const size_t N4 = sizeof(title04); + + typedef multiset<char> my_mset; + const my_mset mset01_ref(title01, title01 + N1); + const my_mset mset02_ref(title02, title02 + N2); + const my_mset mset03_ref(title03, title03 + N3); + const my_mset mset04_ref(title04, title04 + N4); + + my_umset::size_type size01, size02; + + my_alloc alloc01(1); + + my_umset umset01(10, hash<char>(), equal_to<char>(), alloc01); + size01 = umset01.size(); + my_umset umset02(10, hash<char>(), equal_to<char>(), alloc01); + size02 = umset02.size(); + + umset01.swap(umset02); + VERIFY( umset01.size() == size02 ); + VERIFY( umset01.empty() ); + VERIFY( umset02.size() == size01 ); + VERIFY( umset02.empty() ); + + my_umset umset03(10, hash<char>(), equal_to<char>(), alloc01); + size01 = umset03.size(); + my_umset umset04(mset02_ref.begin(), mset02_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = umset04.size(); + + umset03.swap(umset04); + VERIFY( umset03.size() == size02 ); + VERIFY( my_mset(umset03.begin(), umset03.end()) == mset02_ref ); + VERIFY( umset04.size() == size01 ); + VERIFY( umset04.empty() ); + + my_umset umset05(mset01_ref.begin(), mset01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = umset05.size(); + my_umset umset06(mset02_ref.begin(), mset02_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = umset06.size(); + + umset05.swap(umset06); + VERIFY( umset05.size() == size02 ); + VERIFY( my_mset(umset05.begin(), umset05.end()) == mset02_ref ); + VERIFY( umset06.size() == size01 ); + VERIFY( my_mset(umset06.begin(), umset06.end()) == mset01_ref ); + + my_umset umset07(mset01_ref.begin(), mset01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = umset07.size(); + my_umset umset08(mset03_ref.begin(), mset03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = umset08.size(); + + umset07.swap(umset08); + VERIFY( umset07.size() == size02 ); + VERIFY( my_mset(umset07.begin(), umset07.end()) == mset03_ref ); + VERIFY( umset08.size() == size01 ); + VERIFY( my_mset(umset08.begin(), umset08.end()) == mset01_ref ); + + my_umset umset09(mset03_ref.begin(), mset03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = umset09.size(); + my_umset umset10(mset04_ref.begin(), mset04_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = umset10.size(); + + umset09.swap(umset10); + VERIFY( umset09.size() == size02 ); + VERIFY( my_mset(umset09.begin(), umset09.end()) == mset04_ref ); + VERIFY( umset10.size() == size01 ); + VERIFY( my_mset(umset10.begin(), umset10.end()) == mset03_ref ); + + my_umset umset11(mset04_ref.begin(), mset04_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = umset11.size(); + my_umset umset12(mset01_ref.begin(), mset01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = umset12.size(); + + umset11.swap(umset12); + VERIFY( umset11.size() == size02 ); + VERIFY( my_mset(umset11.begin(), umset11.end()) == mset01_ref ); + VERIFY( umset12.size() == size01 ); + VERIFY( my_mset(umset12.begin(), umset12.end()) == mset04_ref ); + + my_umset umset13(mset03_ref.begin(), mset03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = umset13.size(); + my_umset umset14(mset03_ref.begin(), mset03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = umset14.size(); + + umset13.swap(umset14); + VERIFY( umset13.size() == size02 ); + VERIFY( my_mset(umset13.begin(), umset13.end()) == mset03_ref ); + VERIFY( umset14.size() == size01 ); + VERIFY( my_mset(umset14.begin(), umset14.end()) == mset03_ref ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_multiset/2.cc b/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_multiset/2.cc new file mode 100644 index 00000000000..a95ddd51fc8 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_multiset/2.cc @@ -0,0 +1,182 @@ +// 2005-12-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 6.3.4.5 unordered_multiset::swap + +#include <tr1/unordered_set> +#include <set> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator, two different personalities. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + using namespace tr1; + + typedef __gnu_test::uneq_allocator<char> my_alloc; + typedef unordered_multiset<char, hash<char>, equal_to<char>, my_alloc> + my_umset; + + const char title01[] = "Rivers of sand"; + const char title02[] = "Concret PH"; + const char title03[] = "Sonatas and Interludes for Prepared Piano"; + const char title04[] = "never as tired as when i'm waking up"; + + const size_t N1 = sizeof(title01); + const size_t N2 = sizeof(title02); + const size_t N3 = sizeof(title03); + const size_t N4 = sizeof(title04); + + typedef multiset<char> my_mset; + const my_mset mset01_ref(title01, title01 + N1); + const my_mset mset02_ref(title02, title02 + N2); + const my_mset mset03_ref(title03, title03 + N3); + const my_mset mset04_ref(title04, title04 + N4); + + my_umset::size_type size01, size02; + + my_alloc alloc01(1), alloc02(2); + int personality01, personality02; + + my_umset umset01(10, hash<char>(), equal_to<char>(), alloc01); + size01 = umset01.size(); + personality01 = umset01.get_allocator().get_personality(); + my_umset umset02(10, hash<char>(), equal_to<char>(), alloc02); + size02 = umset02.size(); + personality02 = umset02.get_allocator().get_personality(); + + umset01.swap(umset02); + VERIFY( umset01.size() == size02 ); + VERIFY( umset01.empty() ); + VERIFY( umset02.size() == size01 ); + VERIFY( umset02.empty() ); + VERIFY( umset01.get_allocator().get_personality() == personality02 ); + VERIFY( umset02.get_allocator().get_personality() == personality01 ); + + my_umset umset03(10, hash<char>(), equal_to<char>(), alloc02); + size01 = umset03.size(); + personality01 = umset03.get_allocator().get_personality(); + my_umset umset04(mset02_ref.begin(), mset02_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = umset04.size(); + personality02 = umset04.get_allocator().get_personality(); + + umset03.swap(umset04); + VERIFY( umset03.size() == size02 ); + VERIFY( my_mset(umset03.begin(), umset03.end()) == mset02_ref ); + VERIFY( umset04.size() == size01 ); + VERIFY( umset04.empty() ); + VERIFY( umset03.get_allocator().get_personality() == personality02 ); + VERIFY( umset04.get_allocator().get_personality() == personality01 ); + + my_umset umset05(mset01_ref.begin(), mset01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = umset05.size(); + personality01 = umset05.get_allocator().get_personality(); + my_umset umset06(mset02_ref.begin(), mset02_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size02 = umset06.size(); + personality02 = umset06.get_allocator().get_personality(); + + umset05.swap(umset06); + VERIFY( umset05.size() == size02 ); + VERIFY( my_mset(umset05.begin(), umset05.end()) == mset02_ref ); + VERIFY( umset06.size() == size01 ); + VERIFY( my_mset(umset06.begin(), umset06.end()) == mset01_ref ); + VERIFY( umset05.get_allocator().get_personality() == personality02 ); + VERIFY( umset06.get_allocator().get_personality() == personality01 ); + + my_umset umset07(mset01_ref.begin(), mset01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size01 = umset07.size(); + personality01 = umset07.get_allocator().get_personality(); + my_umset umset08(mset03_ref.begin(), mset03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = umset08.size(); + personality02 = umset08.get_allocator().get_personality(); + + umset07.swap(umset08); + VERIFY( umset07.size() == size02 ); + VERIFY( my_mset(umset07.begin(), umset07.end()) == mset03_ref ); + VERIFY( umset08.size() == size01 ); + VERIFY( my_mset(umset08.begin(), umset08.end()) == mset01_ref ); + VERIFY( umset07.get_allocator().get_personality() == personality02 ); + VERIFY( umset08.get_allocator().get_personality() == personality01 ); + + my_umset umset09(mset03_ref.begin(), mset03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = umset09.size(); + personality01 = umset09.get_allocator().get_personality(); + my_umset umset10(mset04_ref.begin(), mset04_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size02 = umset10.size(); + personality02 = umset10.get_allocator().get_personality(); + + umset09.swap(umset10); + VERIFY( umset09.size() == size02 ); + VERIFY( my_mset(umset09.begin(), umset09.end()) == mset04_ref ); + VERIFY( umset10.size() == size01 ); + VERIFY( my_mset(umset10.begin(), umset10.end()) == mset03_ref ); + VERIFY( umset09.get_allocator().get_personality() == personality02 ); + VERIFY( umset10.get_allocator().get_personality() == personality01 ); + + my_umset umset11(mset04_ref.begin(), mset04_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size01 = umset11.size(); + personality01 = umset11.get_allocator().get_personality(); + my_umset umset12(mset01_ref.begin(), mset01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = umset12.size(); + personality02 = umset12.get_allocator().get_personality(); + + umset11.swap(umset12); + VERIFY( umset11.size() == size02 ); + VERIFY( my_mset(umset11.begin(), umset11.end()) == mset01_ref ); + VERIFY( umset12.size() == size01 ); + VERIFY( my_mset(umset12.begin(), umset12.end()) == mset04_ref ); + VERIFY( umset11.get_allocator().get_personality() == personality02 ); + VERIFY( umset12.get_allocator().get_personality() == personality01 ); + + my_umset umset13(mset03_ref.begin(), mset03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = umset13.size(); + personality01 = umset13.get_allocator().get_personality(); + my_umset umset14(mset03_ref.begin(), mset03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size02 = umset14.size(); + personality02 = umset14.get_allocator().get_personality(); + + umset13.swap(umset14); + VERIFY( umset13.size() == size02 ); + VERIFY( my_mset(umset13.begin(), umset13.end()) == mset03_ref ); + VERIFY( umset14.size() == size01 ); + VERIFY( my_mset(umset14.begin(), umset14.end()) == mset03_ref ); + VERIFY( umset13.get_allocator().get_personality() == personality02 ); + VERIFY( umset14.get_allocator().get_personality() == personality01 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_set/1.cc b/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_set/1.cc new file mode 100644 index 00000000000..1928c9e1bdc --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_set/1.cc @@ -0,0 +1,152 @@ +// 2005-12-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 6.3.4.3 unordered_set::swap + +#include <tr1/unordered_set> +#include <set> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator as a non-empty allocator. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + using namespace tr1; + + typedef __gnu_test::uneq_allocator<char> my_alloc; + typedef unordered_set<char, hash<char>, equal_to<char>, my_alloc> my_uset; + + const char title01[] = "Rivers of sand"; + const char title02[] = "Concret PH"; + const char title03[] = "Sonatas and Interludes for Prepared Piano"; + const char title04[] = "never as tired as when i'm waking up"; + + const size_t N1 = sizeof(title01); + const size_t N2 = sizeof(title02); + const size_t N3 = sizeof(title03); + const size_t N4 = sizeof(title04); + + typedef set<char> my_set; + const my_set set01_ref(title01, title01 + N1); + const my_set set02_ref(title02, title02 + N2); + const my_set set03_ref(title03, title03 + N3); + const my_set set04_ref(title04, title04 + N4); + + my_uset::size_type size01, size02; + + my_alloc alloc01(1); + + my_uset uset01(10, hash<char>(), equal_to<char>(), alloc01); + size01 = uset01.size(); + my_uset uset02(10, hash<char>(), equal_to<char>(), alloc01); + size02 = uset02.size(); + + uset01.swap(uset02); + VERIFY( uset01.size() == size02 ); + VERIFY( uset01.empty() ); + VERIFY( uset02.size() == size01 ); + VERIFY( uset02.empty() ); + + my_uset uset03(10, hash<char>(), equal_to<char>(), alloc01); + size01 = uset03.size(); + my_uset uset04(set02_ref.begin(), set02_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = uset04.size(); + + uset03.swap(uset04); + VERIFY( uset03.size() == size02 ); + VERIFY( my_set(uset03.begin(), uset03.end()) == set02_ref ); + VERIFY( uset04.size() == size01 ); + VERIFY( uset04.empty() ); + + my_uset uset05(set01_ref.begin(), set01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = uset05.size(); + my_uset uset06(set02_ref.begin(), set02_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = uset06.size(); + + uset05.swap(uset06); + VERIFY( uset05.size() == size02 ); + VERIFY( my_set(uset05.begin(), uset05.end()) == set02_ref ); + VERIFY( uset06.size() == size01 ); + VERIFY( my_set(uset06.begin(), uset06.end()) == set01_ref ); + + my_uset uset07(set01_ref.begin(), set01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = uset07.size(); + my_uset uset08(set03_ref.begin(), set03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = uset08.size(); + + uset07.swap(uset08); + VERIFY( uset07.size() == size02 ); + VERIFY( my_set(uset07.begin(), uset07.end()) == set03_ref ); + VERIFY( uset08.size() == size01 ); + VERIFY( my_set(uset08.begin(), uset08.end()) == set01_ref ); + + my_uset uset09(set03_ref.begin(), set03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = uset09.size(); + my_uset uset10(set04_ref.begin(), set04_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = uset10.size(); + + uset09.swap(uset10); + VERIFY( uset09.size() == size02 ); + VERIFY( my_set(uset09.begin(), uset09.end()) == set04_ref ); + VERIFY( uset10.size() == size01 ); + VERIFY( my_set(uset10.begin(), uset10.end()) == set03_ref ); + + my_uset uset11(set04_ref.begin(), set04_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = uset11.size(); + my_uset uset12(set01_ref.begin(), set01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = uset12.size(); + + uset11.swap(uset12); + VERIFY( uset11.size() == size02 ); + VERIFY( my_set(uset11.begin(), uset11.end()) == set01_ref ); + VERIFY( uset12.size() == size01 ); + VERIFY( my_set(uset12.begin(), uset12.end()) == set04_ref ); + + my_uset uset13(set03_ref.begin(), set03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = uset13.size(); + my_uset uset14(set03_ref.begin(), set03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = uset14.size(); + + uset13.swap(uset14); + VERIFY( uset13.size() == size02 ); + VERIFY( my_set(uset13.begin(), uset13.end()) == set03_ref ); + VERIFY( uset14.size() == size01 ); + VERIFY( my_set(uset14.begin(), uset14.end()) == set03_ref ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_set/2.cc b/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_set/2.cc new file mode 100644 index 00000000000..46e859cabac --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/6_containers/unordered/swap/unordered_set/2.cc @@ -0,0 +1,181 @@ +// 2005-12-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 6.3.4.3 unordered_set::swap + +#include <tr1/unordered_set> +#include <set> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator, two different personalities. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + using namespace tr1; + + typedef __gnu_test::uneq_allocator<char> my_alloc; + typedef unordered_set<char, hash<char>, equal_to<char>, my_alloc> my_uset; + + const char title01[] = "Rivers of sand"; + const char title02[] = "Concret PH"; + const char title03[] = "Sonatas and Interludes for Prepared Piano"; + const char title04[] = "never as tired as when i'm waking up"; + + const size_t N1 = sizeof(title01); + const size_t N2 = sizeof(title02); + const size_t N3 = sizeof(title03); + const size_t N4 = sizeof(title04); + + typedef set<char> my_set; + const my_set set01_ref(title01, title01 + N1); + const my_set set02_ref(title02, title02 + N2); + const my_set set03_ref(title03, title03 + N3); + const my_set set04_ref(title04, title04 + N4); + + my_uset::size_type size01, size02; + + my_alloc alloc01(1), alloc02(2); + int personality01, personality02; + + my_uset uset01(10, hash<char>(), equal_to<char>(), alloc01); + size01 = uset01.size(); + personality01 = uset01.get_allocator().get_personality(); + my_uset uset02(10, hash<char>(), equal_to<char>(), alloc02); + size02 = uset02.size(); + personality02 = uset02.get_allocator().get_personality(); + + uset01.swap(uset02); + VERIFY( uset01.size() == size02 ); + VERIFY( uset01.empty() ); + VERIFY( uset02.size() == size01 ); + VERIFY( uset02.empty() ); + VERIFY( uset01.get_allocator().get_personality() == personality02 ); + VERIFY( uset02.get_allocator().get_personality() == personality01 ); + + my_uset uset03(10, hash<char>(), equal_to<char>(), alloc02); + size01 = uset03.size(); + personality01 = uset03.get_allocator().get_personality(); + my_uset uset04(set02_ref.begin(), set02_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = uset04.size(); + personality02 = uset04.get_allocator().get_personality(); + + uset03.swap(uset04); + VERIFY( uset03.size() == size02 ); + VERIFY( my_set(uset03.begin(), uset03.end()) == set02_ref ); + VERIFY( uset04.size() == size01 ); + VERIFY( uset04.empty() ); + VERIFY( uset03.get_allocator().get_personality() == personality02 ); + VERIFY( uset04.get_allocator().get_personality() == personality01 ); + + my_uset uset05(set01_ref.begin(), set01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = uset05.size(); + personality01 = uset05.get_allocator().get_personality(); + my_uset uset06(set02_ref.begin(), set02_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size02 = uset06.size(); + personality02 = uset06.get_allocator().get_personality(); + + uset05.swap(uset06); + VERIFY( uset05.size() == size02 ); + VERIFY( my_set(uset05.begin(), uset05.end()) == set02_ref ); + VERIFY( uset06.size() == size01 ); + VERIFY( my_set(uset06.begin(), uset06.end()) == set01_ref ); + VERIFY( uset05.get_allocator().get_personality() == personality02 ); + VERIFY( uset06.get_allocator().get_personality() == personality01 ); + + my_uset uset07(set01_ref.begin(), set01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size01 = uset07.size(); + personality01 = uset07.get_allocator().get_personality(); + my_uset uset08(set03_ref.begin(), set03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = uset08.size(); + personality02 = uset08.get_allocator().get_personality(); + + uset07.swap(uset08); + VERIFY( uset07.size() == size02 ); + VERIFY( my_set(uset07.begin(), uset07.end()) == set03_ref ); + VERIFY( uset08.size() == size01 ); + VERIFY( my_set(uset08.begin(), uset08.end()) == set01_ref ); + VERIFY( uset07.get_allocator().get_personality() == personality02 ); + VERIFY( uset08.get_allocator().get_personality() == personality01 ); + + my_uset uset09(set03_ref.begin(), set03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = uset09.size(); + personality01 = uset09.get_allocator().get_personality(); + my_uset uset10(set04_ref.begin(), set04_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size02 = uset10.size(); + personality02 = uset10.get_allocator().get_personality(); + + uset09.swap(uset10); + VERIFY( uset09.size() == size02 ); + VERIFY( my_set(uset09.begin(), uset09.end()) == set04_ref ); + VERIFY( uset10.size() == size01 ); + VERIFY( my_set(uset10.begin(), uset10.end()) == set03_ref ); + VERIFY( uset09.get_allocator().get_personality() == personality02 ); + VERIFY( uset10.get_allocator().get_personality() == personality01 ); + + my_uset uset11(set04_ref.begin(), set04_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size01 = uset11.size(); + personality01 = uset11.get_allocator().get_personality(); + my_uset uset12(set01_ref.begin(), set01_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size02 = uset12.size(); + personality02 = uset12.get_allocator().get_personality(); + + uset11.swap(uset12); + VERIFY( uset11.size() == size02 ); + VERIFY( my_set(uset11.begin(), uset11.end()) == set01_ref ); + VERIFY( uset12.size() == size01 ); + VERIFY( my_set(uset12.begin(), uset12.end()) == set04_ref ); + VERIFY( uset11.get_allocator().get_personality() == personality02 ); + VERIFY( uset12.get_allocator().get_personality() == personality01 ); + + my_uset uset13(set03_ref.begin(), set03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc01); + size01 = uset13.size(); + personality01 = uset13.get_allocator().get_personality(); + my_uset uset14(set03_ref.begin(), set03_ref.end(), 10, hash<char>(), + equal_to<char>(), alloc02); + size02 = uset14.size(); + personality02 = uset14.get_allocator().get_personality(); + + uset13.swap(uset14); + VERIFY( uset13.size() == size02 ); + VERIFY( my_set(uset13.begin(), uset13.end()) == set03_ref ); + VERIFY( uset14.size() == size01 ); + VERIFY( my_set(uset14.begin(), uset14.end()) == set03_ref ); + VERIFY( uset13.get_allocator().get_personality() == personality02 ); + VERIFY( uset14.get_allocator().get_personality() == personality01 ); +} + +int main() +{ + test01(); + return 0; +} |