diff options
42 files changed, 3619 insertions, 52 deletions
diff --git a/libstdc++-v3/docs/html/ext/howto.html b/libstdc++-v3/docs/html/ext/howto.html index b2e8b5b2dca..9d86bc04162 100644 --- a/libstdc++-v3/docs/html/ext/howto.html +++ b/libstdc++-v3/docs/html/ext/howto.html @@ -516,6 +516,12 @@ <dd>Have <code>open</code> clear the error flags. </dd> + <dt><a href="lwg-active.html#431">431</a>: + <em>Swapping containers with unequal allocators</em> + </dt> + <dd>Implement Option 3, as per N1599. + </dd> + <dt><a href="lwg-defects.html#434">434</a>: <em>bitset::to_string() hard to use</em> </dt> diff --git a/libstdc++-v3/include/bits/allocator.h b/libstdc++-v3/include/bits/allocator.h index 18bfd5f60eb..3e8d94a26e1 100644 --- a/libstdc++-v3/include/bits/allocator.h +++ b/libstdc++-v3/include/bits/allocator.h @@ -1,6 +1,7 @@ // Allocators -*- C++ -*- -// Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 +// 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 @@ -128,6 +129,23 @@ _GLIBCXX_BEGIN_NAMESPACE(std) // Undefine. #undef __glibcxx_base_allocator + // To implement Option 3 of DR 431. + template<typename _Alloc, bool = std::__is_empty<_Alloc>::__value> + struct __alloc_swap + { static void _S_do_it(_Alloc&, _Alloc&) { } }; + + template<typename _Alloc> + struct __alloc_swap<_Alloc, false> + { + static void + _S_do_it(_Alloc& __one, _Alloc& __two) + { + // Precondition: swappable allocators. + if (__one != __two) + swap(__one, __two); + } + }; + _GLIBCXX_END_NAMESPACE #endif diff --git a/libstdc++-v3/include/bits/stl_deque.h b/libstdc++-v3/include/bits/stl_deque.h index d9bbb007b06..8f3fc99f61e 100644 --- a/libstdc++-v3/include/bits/stl_deque.h +++ b/libstdc++-v3/include/bits/stl_deque.h @@ -1195,6 +1195,11 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD) std::swap(this->_M_impl._M_finish, __x._M_impl._M_finish); std::swap(this->_M_impl._M_map, __x._M_impl._M_map); std::swap(this->_M_impl._M_map_size, __x._M_impl._M_map_size); + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 431. Swapping containers with unequal allocators. + std::__alloc_swap<_Tp_alloc_type>::_S_do_it(_M_get_Tp_allocator(), + __x._M_get_Tp_allocator()); } /** diff --git a/libstdc++-v3/include/bits/stl_list.h b/libstdc++-v3/include/bits/stl_list.h index 1761bf5c133..513833c71ef 100644 --- a/libstdc++-v3/include/bits/stl_list.h +++ b/libstdc++-v3/include/bits/stl_list.h @@ -888,7 +888,14 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD) */ void swap(list& __x) - { _List_node_base::swap(this->_M_impl._M_node, __x._M_impl._M_node); } + { + _List_node_base::swap(this->_M_impl._M_node, __x._M_impl._M_node); + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 431. Swapping containers with unequal allocators. + std::__alloc_swap<typename _Base::_Node_alloc_type>:: + _S_do_it(_M_get_Node_allocator(), __x._M_get_Node_allocator()); + } /** * Erases all the elements. Note that this function only erases diff --git a/libstdc++-v3/include/bits/stl_tree.h b/libstdc++-v3/include/bits/stl_tree.h index c2acf87e350..01a8bad81c9 100644 --- a/libstdc++-v3/include/bits/stl_tree.h +++ b/libstdc++-v3/include/bits/stl_tree.h @@ -912,6 +912,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) // No need to swap header's color as it does not change. std::swap(this->_M_impl._M_node_count, __t._M_impl._M_node_count); std::swap(this->_M_impl._M_key_compare, __t._M_impl._M_key_compare); + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 431. Swapping containers with unequal allocators. + std::__alloc_swap<_Node_allocator>:: + _S_do_it(_M_get_Node_allocator(), __t._M_get_Node_allocator()); } template<typename _Key, typename _Val, typename _KeyOfValue, diff --git a/libstdc++-v3/include/bits/stl_vector.h b/libstdc++-v3/include/bits/stl_vector.h index 43f69de450e..b4434fca863 100644 --- a/libstdc++-v3/include/bits/stl_vector.h +++ b/libstdc++-v3/include/bits/stl_vector.h @@ -731,6 +731,11 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD) std::swap(this->_M_impl._M_finish, __x._M_impl._M_finish); std::swap(this->_M_impl._M_end_of_storage, __x._M_impl._M_end_of_storage); + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 431. Swapping containers with unequal allocators. + std::__alloc_swap<_Tp_alloc_type>::_S_do_it(_M_get_Tp_allocator(), + __x._M_get_Tp_allocator()); } /** diff --git a/libstdc++-v3/include/ext/rc_string_base.h b/libstdc++-v3/include/ext/rc_string_base.h index a264c1ef0ec..dece887d199 100644 --- a/libstdc++-v3/include/ext/rc_string_base.h +++ b/libstdc++-v3/include/ext/rc_string_base.h @@ -583,9 +583,11 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) _CharT* __tmp = _M_data(); _M_data(__rcs._M_data()); __rcs._M_data(__tmp); - - // NB: Implement Option 3 of DR 431 (see N1599). - _M_dataplus._M_alloc_swap(__rcs._M_dataplus); + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 431. Swapping containers with unequal allocators. + std::__alloc_swap<allocator_type>::_S_do_it(_M_get_allocator(), + __rcs._M_get_allocator()); } template<typename _CharT, typename _Traits, typename _Alloc> diff --git a/libstdc++-v3/include/ext/sso_string_base.h b/libstdc++-v3/include/ext/sso_string_base.h index c21dbbd3ab4..0bf99cad53f 100644 --- a/libstdc++-v3/include/ext/sso_string_base.h +++ b/libstdc++-v3/include/ext/sso_string_base.h @@ -1,6 +1,6 @@ // Short-string-optimized versatile string base -*- C++ -*- -// Copyright (C) 2005 Free Software Foundation, Inc. +// Copyright (C) 2005, 2006 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 @@ -45,7 +45,6 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) public: typedef _Traits traits_type; typedef typename _Traits::char_type value_type; - typedef _Alloc allocator_type; typedef __vstring_utility<_CharT, _Traits, _Alloc> _Util_Base; typedef typename _Util_Base::_CharT_alloc_type _CharT_alloc_type; @@ -67,7 +66,8 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) / sizeof(_CharT)) - 1) / 4) }; // Data Members (private): - typename _Util_Base::template _Alloc_hider<_Alloc> _M_dataplus; + typename _Util_Base::template _Alloc_hider<_CharT_alloc_type> + _M_dataplus; size_type _M_string_length; enum { _S_local_capacity = 15 }; @@ -202,11 +202,11 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) ~__sso_string_base() { _M_dispose(); } - allocator_type& + _CharT_alloc_type& _M_get_allocator() { return _M_dataplus; } - const allocator_type& + const _CharT_alloc_type& _M_get_allocator() const { return _M_dataplus; } @@ -235,15 +235,17 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) void __sso_string_base<_CharT, _Traits, _Alloc>:: _M_destroy(size_type __size) throw() - { _CharT_alloc_type(_M_get_allocator()).deallocate(_M_data(), __size + 1); } + { _M_dataplus._CharT_alloc_type::deallocate(_M_data(), __size + 1); } template<typename _CharT, typename _Traits, typename _Alloc> void __sso_string_base<_CharT, _Traits, _Alloc>:: _M_swap(__sso_string_base& __rcs) { - // NB: Implement Option 3 of DR 431 (see N1599). - _M_dataplus._M_alloc_swap(__rcs._M_dataplus); + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 431. Swapping containers with unequal allocators. + std::__alloc_swap<_CharT_alloc_type>::_S_do_it(_M_get_allocator(), + __rcs._M_get_allocator()); if (_M_is_local()) if (__rcs._M_is_local()) @@ -327,7 +329,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) // NB: Need an array of char_type[__capacity], plus a terminating // null char_type() element. - return _CharT_alloc_type(_M_get_allocator()).allocate(__capacity + 1); + return _M_dataplus._CharT_alloc_type::allocate(__capacity + 1); } template<typename _CharT, typename _Traits, typename _Alloc> diff --git a/libstdc++-v3/include/ext/vstring.h b/libstdc++-v3/include/ext/vstring.h index 6b04761888e..a117c5826ee 100644 --- a/libstdc++-v3/include/ext/vstring.h +++ b/libstdc++-v3/include/ext/vstring.h @@ -1,6 +1,6 @@ // Versatile string -*- C++ -*- -// Copyright (C) 2005 Free Software Foundation, Inc. +// Copyright (C) 2005, 2006 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 @@ -1271,7 +1271,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) */ allocator_type get_allocator() const - { return this->_M_get_allocator(); } + { return allocator_type(this->_M_get_allocator()); } /** * @brief Find position of a C substring. diff --git a/libstdc++-v3/include/ext/vstring_util.h b/libstdc++-v3/include/ext/vstring_util.h index 30ec39ba851..a17de088252 100644 --- a/libstdc++-v3/include/ext/vstring_util.h +++ b/libstdc++-v3/include/ext/vstring_util.h @@ -1,6 +1,6 @@ // Versatile string utility -*- C++ -*- -// Copyright (C) 2005 Free Software Foundation, Inc. +// Copyright (C) 2005, 2006 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 @@ -83,38 +83,14 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) __const_rc_iterator; // NB: When the allocator is empty, deriving from it saves space - // (http://www.cantrip.org/emptyopt.html). We do that anyway for - // consistency. - template<typename _Alloc1, bool = std::__is_empty<_Alloc1>::__value> - struct _Alloc_hider - : public _Alloc1 - { - _Alloc_hider(const _Alloc1& __a, _CharT* __ptr) - : _Alloc1(__a), _M_p(__ptr) { } - - void - _M_alloc_swap(_Alloc_hider& __ah) - { - // Implement Option 3 of DR 431 (see N1599). - // Precondition: swappable allocators. - _Alloc1& __this = static_cast<_Alloc1&>(*this); - _Alloc1& __that = static_cast<_Alloc1&>(__ah); - if (__this != __that) - swap(__this, __that); - } - - _CharT* _M_p; // The actual data. - }; - + // (http://www.cantrip.org/emptyopt.html). template<typename _Alloc1> - struct _Alloc_hider<_Alloc1, true> + struct _Alloc_hider : public _Alloc1 { _Alloc_hider(const _Alloc1& __a, _CharT* __ptr) : _Alloc1(__a), _M_p(__ptr) { } - void _M_alloc_swap(_Alloc_hider&) { } - _CharT* _M_p; // The actual data. }; diff --git a/libstdc++-v3/include/tr1/hashtable b/libstdc++-v3/include/tr1/hashtable index 4cf4ae9c192..0b9bc418443 100644 --- a/libstdc++-v3/include/tr1/hashtable +++ b/libstdc++-v3/include/tr1/hashtable @@ -1,6 +1,6 @@ // Internal header for TR1 unordered_set and unordered_map -*- C++ -*- -// Copyright (C) 2005 Free Software Foundation, Inc. +// Copyright (C) 2005, 2006 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 @@ -55,6 +55,7 @@ #define GNU_LIBSTDCXX_TR1_HASHTABLE_ #include <utility> // For std::pair +#include <memory> #include <iterator> #include <cstddef> #include <cstdlib> @@ -1443,8 +1444,11 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1) // have different members. Internal::hash_code_base<K, V, Ex, Eq, H1, H2, H, c>::m_swap(x); - // open LWG issue 431 - // std::swap(m_node_allocator, x.m_node_allocator); + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 431. Swapping containers with unequal allocators. + std::__alloc_swap<node_allocator_t>::_S_do_it(m_node_allocator, + x.m_node_allocator); + std::swap(m_rehash_policy, x.m_rehash_policy); std::swap(m_buckets, x.m_buckets); std::swap(m_bucket_count, x.m_bucket_count); diff --git a/libstdc++-v3/include/tr1/unordered_map b/libstdc++-v3/include/tr1/unordered_map index 2f1a239c7c9..da0d86bf8b6 100644 --- a/libstdc++-v3/include/tr1/unordered_map +++ b/libstdc++-v3/include/tr1/unordered_map @@ -1,6 +1,6 @@ // TR1 unordered_map -*- C++ -*- -// Copyright (C) 2005 Free Software Foundation, Inc. +// Copyright (C) 2005, 2006 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 @@ -36,9 +36,6 @@ #include <tr1/hashtable> #include <tr1/functional> -#include <tr1/functional> -#include <utility> -#include <memory> namespace std { diff --git a/libstdc++-v3/include/tr1/unordered_set b/libstdc++-v3/include/tr1/unordered_set index c3c16ddc6d7..02c518451af 100644 --- a/libstdc++-v3/include/tr1/unordered_set +++ b/libstdc++-v3/include/tr1/unordered_set @@ -1,6 +1,6 @@ // TR1 unordered_set -*- C++ -*- -// Copyright (C) 2005 Free Software Foundation, Inc. +// Copyright (C) 2005, 2006 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 @@ -36,7 +36,6 @@ #include <tr1/hashtable> #include <tr1/functional> -#include <memory> namespace std { diff --git a/libstdc++-v3/testsuite/23_containers/deque/modifiers/swap.cc b/libstdc++-v3/testsuite/23_containers/deque/modifiers/swap/1.cc index 2834ae56d82..2834ae56d82 100644 --- a/libstdc++-v3/testsuite/23_containers/deque/modifiers/swap.cc +++ b/libstdc++-v3/testsuite/23_containers/deque/modifiers/swap/1.cc diff --git a/libstdc++-v3/testsuite/23_containers/deque/modifiers/swap/2.cc b/libstdc++-v3/testsuite/23_containers/deque/modifiers/swap/2.cc new file mode 100644 index 00000000000..25402a79178 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/modifiers/swap/2.cc @@ -0,0 +1,133 @@ +// 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. + +// 23.2.1.3 deque::swap + +#include <deque> +#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; + + typedef __gnu_test::uneq_allocator<char> my_alloc; + typedef deque<char, my_alloc> my_deque; + + 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); + + my_deque::size_type size01, size02; + + my_alloc alloc01(1); + + my_deque deq01(alloc01); + size01 = deq01.size(); + my_deque deq02(alloc01); + size02 = deq02.size(); + + deq01.swap(deq02); + VERIFY( deq01.size() == size02 ); + VERIFY( deq01.empty() ); + VERIFY( deq02.size() == size01 ); + VERIFY( deq02.empty() ); + + my_deque deq03(alloc01); + size01 = deq03.size(); + my_deque deq04(title02, title02 + N2, alloc01); + size02 = deq04.size(); + + deq03.swap(deq04); + VERIFY( deq03.size() == size02 ); + VERIFY( equal(deq03.begin(), deq03.end(), title02) ); + VERIFY( deq04.size() == size01 ); + VERIFY( deq04.empty() ); + + my_deque deq05(title01, title01 + N1, alloc01); + size01 = deq05.size(); + my_deque deq06(title02, title02 + N2, alloc01); + size02 = deq06.size(); + + deq05.swap(deq06); + VERIFY( deq05.size() == size02 ); + VERIFY( equal(deq05.begin(), deq05.end(), title02) ); + VERIFY( deq06.size() == size01 ); + VERIFY( equal(deq06.begin(), deq06.end(), title01) ); + + my_deque deq07(title01, title01 + N1, alloc01); + size01 = deq07.size(); + my_deque deq08(title03, title03 + N3, alloc01); + size02 = deq08.size(); + + deq07.swap(deq08); + VERIFY( deq07.size() == size02 ); + VERIFY( equal(deq07.begin(), deq07.end(), title03) ); + VERIFY( deq08.size() == size01 ); + VERIFY( equal(deq08.begin(), deq08.end(), title01) ); + + my_deque deq09(title03, title03 + N3, alloc01); + size01 = deq09.size(); + my_deque deq10(title04, title04 + N4, alloc01); + size02 = deq10.size(); + + deq09.swap(deq10); + VERIFY( deq09.size() == size02 ); + VERIFY( equal(deq09.begin(), deq09.end(), title04) ); + VERIFY( deq10.size() == size01 ); + VERIFY( equal(deq10.begin(), deq10.end(), title03) ); + + my_deque deq11(title04, title04 + N4, alloc01); + size01 = deq11.size(); + my_deque deq12(title01, title01 + N1, alloc01); + size02 = deq12.size(); + + deq11.swap(deq12); + VERIFY( deq11.size() == size02 ); + VERIFY( equal(deq11.begin(), deq11.end(), title01) ); + VERIFY( deq12.size() == size01 ); + VERIFY( equal(deq12.begin(), deq12.end(), title04) ); + + my_deque deq13(title03, title03 + N3, alloc01); + size01 = deq13.size(); + my_deque deq14(title03, title03 + N3, alloc01); + size02 = deq14.size(); + + deq13.swap(deq14); + VERIFY( deq13.size() == size02 ); + VERIFY( equal(deq13.begin(), deq13.end(), title03) ); + VERIFY( deq14.size() == size01 ); + VERIFY( equal(deq14.begin(), deq14.end(), title03) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/modifiers/swap/3.cc b/libstdc++-v3/testsuite/23_containers/deque/modifiers/swap/3.cc new file mode 100644 index 00000000000..70f5e2abf9c --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/modifiers/swap/3.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. + +// 23.2.1.3 deque::swap + +#include <deque> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator, two different personalities. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef __gnu_test::uneq_allocator<char> my_alloc; + typedef deque<char, my_alloc> my_deque; + + 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); + + my_deque::size_type size01, size02; + + my_alloc alloc01(1), alloc02(2); + int personality01, personality02; + + my_deque deq01(alloc01); + size01 = deq01.size(); + personality01 = deq01.get_allocator().get_personality(); + my_deque deq02(alloc02); + size02 = deq02.size(); + personality02 = deq02.get_allocator().get_personality(); + + deq01.swap(deq02); + VERIFY( deq01.size() == size02 ); + VERIFY( deq01.empty() ); + VERIFY( deq02.size() == size01 ); + VERIFY( deq02.empty() ); + VERIFY( deq01.get_allocator().get_personality() == personality02 ); + VERIFY( deq02.get_allocator().get_personality() == personality01 ); + + my_deque deq03(alloc02); + size01 = deq03.size(); + personality01 = deq03.get_allocator().get_personality(); + my_deque deq04(title02, title02 + N2, alloc01); + size02 = deq04.size(); + personality02 = deq04.get_allocator().get_personality(); + + deq03.swap(deq04); + VERIFY( deq03.size() == size02 ); + VERIFY( equal(deq03.begin(), deq03.end(), title02) ); + VERIFY( deq04.size() == size01 ); + VERIFY( deq04.empty() ); + VERIFY( deq03.get_allocator().get_personality() == personality02 ); + VERIFY( deq04.get_allocator().get_personality() == personality01 ); + + my_deque deq05(title01, title01 + N1, alloc01); + size01 = deq05.size(); + personality01 = deq05.get_allocator().get_personality(); + my_deque deq06(title02, title02 + N2, alloc02); + size02 = deq06.size(); + personality02 = deq06.get_allocator().get_personality(); + + deq05.swap(deq06); + VERIFY( deq05.size() == size02 ); + VERIFY( equal(deq05.begin(), deq05.end(), title02) ); + VERIFY( deq06.size() == size01 ); + VERIFY( equal(deq06.begin(), deq06.end(), title01) ); + VERIFY( deq05.get_allocator().get_personality() == personality02 ); + VERIFY( deq06.get_allocator().get_personality() == personality01 ); + + my_deque deq07(title01, title01 + N1, alloc02); + size01 = deq07.size(); + personality01 = deq07.get_allocator().get_personality(); + my_deque deq08(title03, title03 + N3, alloc01); + size02 = deq08.size(); + personality02 = deq08.get_allocator().get_personality(); + + deq07.swap(deq08); + VERIFY( deq07.size() == size02 ); + VERIFY( equal(deq07.begin(), deq07.end(), title03) ); + VERIFY( deq08.size() == size01 ); + VERIFY( equal(deq08.begin(), deq08.end(), title01) ); + VERIFY( deq07.get_allocator().get_personality() == personality02 ); + VERIFY( deq08.get_allocator().get_personality() == personality01 ); + + my_deque deq09(title03, title03 + N3, alloc01); + size01 = deq09.size(); + personality01 = deq09.get_allocator().get_personality(); + my_deque deq10(title04, title04 + N4, alloc02); + size02 = deq10.size(); + personality02 = deq10.get_allocator().get_personality(); + + deq09.swap(deq10); + VERIFY( deq09.size() == size02 ); + VERIFY( equal(deq09.begin(), deq09.end(), title04) ); + VERIFY( deq10.size() == size01 ); + VERIFY( equal(deq10.begin(), deq10.end(), title03) ); + VERIFY( deq09.get_allocator().get_personality() == personality02 ); + VERIFY( deq10.get_allocator().get_personality() == personality01 ); + + my_deque deq11(title04, title04 + N4, alloc02); + size01 = deq11.size(); + personality01 = deq11.get_allocator().get_personality(); + my_deque deq12(title01, title01 + N1, alloc01); + size02 = deq12.size(); + personality02 = deq12.get_allocator().get_personality(); + + deq11.swap(deq12); + VERIFY( deq11.size() == size02 ); + VERIFY( equal(deq11.begin(), deq11.end(), title01) ); + VERIFY( deq12.size() == size01 ); + VERIFY( equal(deq12.begin(), deq12.end(), title04) ); + VERIFY( deq11.get_allocator().get_personality() == personality02 ); + VERIFY( deq12.get_allocator().get_personality() == personality01 ); + + my_deque deq13(title03, title03 + N3, alloc01); + size01 = deq13.size(); + personality01 = deq13.get_allocator().get_personality(); + my_deque deq14(title03, title03 + N3, alloc02); + size02 = deq14.size(); + personality02 = deq14.get_allocator().get_personality(); + + deq13.swap(deq14); + VERIFY( deq13.size() == size02 ); + VERIFY( equal(deq13.begin(), deq13.end(), title03) ); + VERIFY( deq14.size() == size01 ); + VERIFY( equal(deq14.begin(), deq14.end(), title03) ); + VERIFY( deq13.get_allocator().get_personality() == personality02 ); + VERIFY( deq14.get_allocator().get_personality() == personality01 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/swap.cc b/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/1.cc index a277ac5e43f..a277ac5e43f 100644 --- a/libstdc++-v3/testsuite/23_containers/list/modifiers/swap.cc +++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/1.cc diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/2.cc b/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/2.cc new file mode 100644 index 00000000000..084143c4262 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/2.cc @@ -0,0 +1,133 @@ +// 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. + +// 23.2.2.3 list::swap + +#include <list> +#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; + + typedef __gnu_test::uneq_allocator<char> my_alloc; + typedef list<char, my_alloc> my_list; + + 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); + + my_list::size_type size01, size02; + + my_alloc alloc01(1); + + my_list lis01(alloc01); + size01 = lis01.size(); + my_list lis02(alloc01); + size02 = lis02.size(); + + lis01.swap(lis02); + VERIFY( lis01.size() == size02 ); + VERIFY( lis01.empty() ); + VERIFY( lis02.size() == size01 ); + VERIFY( lis02.empty() ); + + my_list lis03(alloc01); + size01 = lis03.size(); + my_list lis04(title02, title02 + N2, alloc01); + size02 = lis04.size(); + + lis03.swap(lis04); + VERIFY( lis03.size() == size02 ); + VERIFY( equal(lis03.begin(), lis03.end(), title02) ); + VERIFY( lis04.size() == size01 ); + VERIFY( lis04.empty() ); + + my_list lis05(title01, title01 + N1, alloc01); + size01 = lis05.size(); + my_list lis06(title02, title02 + N2, alloc01); + size02 = lis06.size(); + + lis05.swap(lis06); + VERIFY( lis05.size() == size02 ); + VERIFY( equal(lis05.begin(), lis05.end(), title02) ); + VERIFY( lis06.size() == size01 ); + VERIFY( equal(lis06.begin(), lis06.end(), title01) ); + + my_list lis07(title01, title01 + N1, alloc01); + size01 = lis07.size(); + my_list lis08(title03, title03 + N3, alloc01); + size02 = lis08.size(); + + lis07.swap(lis08); + VERIFY( lis07.size() == size02 ); + VERIFY( equal(lis07.begin(), lis07.end(), title03) ); + VERIFY( lis08.size() == size01 ); + VERIFY( equal(lis08.begin(), lis08.end(), title01) ); + + my_list lis09(title03, title03 + N3, alloc01); + size01 = lis09.size(); + my_list lis10(title04, title04 + N4, alloc01); + size02 = lis10.size(); + + lis09.swap(lis10); + VERIFY( lis09.size() == size02 ); + VERIFY( equal(lis09.begin(), lis09.end(), title04) ); + VERIFY( lis10.size() == size01 ); + VERIFY( equal(lis10.begin(), lis10.end(), title03) ); + + my_list lis11(title04, title04 + N4, alloc01); + size01 = lis11.size(); + my_list lis12(title01, title01 + N1, alloc01); + size02 = lis12.size(); + + lis11.swap(lis12); + VERIFY( lis11.size() == size02 ); + VERIFY( equal(lis11.begin(), lis11.end(), title01) ); + VERIFY( lis12.size() == size01 ); + VERIFY( equal(lis12.begin(), lis12.end(), title04) ); + + my_list lis13(title03, title03 + N3, alloc01); + size01 = lis13.size(); + my_list lis14(title03, title03 + N3, alloc01); + size02 = lis14.size(); + + lis13.swap(lis14); + VERIFY( lis13.size() == size02 ); + VERIFY( equal(lis13.begin(), lis13.end(), title03) ); + VERIFY( lis14.size() == size01 ); + VERIFY( equal(lis14.begin(), lis14.end(), title03) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/3.cc b/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/3.cc new file mode 100644 index 00000000000..714e0ccea3f --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/modifiers/swap/3.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. + +// 23.2.2.3 list::swap + +#include <list> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator, two different personalities. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef __gnu_test::uneq_allocator<char> my_alloc; + typedef list<char, my_alloc> my_list; + + 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); + + my_list::size_type size01, size02; + + my_alloc alloc01(1), alloc02(2); + int personality01, personality02; + + my_list lis01(alloc01); + size01 = lis01.size(); + personality01 = lis01.get_allocator().get_personality(); + my_list lis02(alloc02); + size02 = lis02.size(); + personality02 = lis02.get_allocator().get_personality(); + + lis01.swap(lis02); + VERIFY( lis01.size() == size02 ); + VERIFY( lis01.empty() ); + VERIFY( lis02.size() == size01 ); + VERIFY( lis02.empty() ); + VERIFY( lis01.get_allocator().get_personality() == personality02 ); + VERIFY( lis02.get_allocator().get_personality() == personality01 ); + + my_list lis03(alloc02); + size01 = lis03.size(); + personality01 = lis03.get_allocator().get_personality(); + my_list lis04(title02, title02 + N2, alloc01); + size02 = lis04.size(); + personality02 = lis04.get_allocator().get_personality(); + + lis03.swap(lis04); + VERIFY( lis03.size() == size02 ); + VERIFY( equal(lis03.begin(), lis03.end(), title02) ); + VERIFY( lis04.size() == size01 ); + VERIFY( lis04.empty() ); + VERIFY( lis03.get_allocator().get_personality() == personality02 ); + VERIFY( lis04.get_allocator().get_personality() == personality01 ); + + my_list lis05(title01, title01 + N1, alloc01); + size01 = lis05.size(); + personality01 = lis05.get_allocator().get_personality(); + my_list lis06(title02, title02 + N2, alloc02); + size02 = lis06.size(); + personality02 = lis06.get_allocator().get_personality(); + + lis05.swap(lis06); + VERIFY( lis05.size() == size02 ); + VERIFY( equal(lis05.begin(), lis05.end(), title02) ); + VERIFY( lis06.size() == size01 ); + VERIFY( equal(lis06.begin(), lis06.end(), title01) ); + VERIFY( lis05.get_allocator().get_personality() == personality02 ); + VERIFY( lis06.get_allocator().get_personality() == personality01 ); + + my_list lis07(title01, title01 + N1, alloc02); + size01 = lis07.size(); + personality01 = lis07.get_allocator().get_personality(); + my_list lis08(title03, title03 + N3, alloc01); + size02 = lis08.size(); + personality02 = lis08.get_allocator().get_personality(); + + lis07.swap(lis08); + VERIFY( lis07.size() == size02 ); + VERIFY( equal(lis07.begin(), lis07.end(), title03) ); + VERIFY( lis08.size() == size01 ); + VERIFY( equal(lis08.begin(), lis08.end(), title01) ); + VERIFY( lis07.get_allocator().get_personality() == personality02 ); + VERIFY( lis08.get_allocator().get_personality() == personality01 ); + + my_list lis09(title03, title03 + N3, alloc01); + size01 = lis09.size(); + personality01 = lis09.get_allocator().get_personality(); + my_list lis10(title04, title04 + N4, alloc02); + size02 = lis10.size(); + personality02 = lis10.get_allocator().get_personality(); + + lis09.swap(lis10); + VERIFY( lis09.size() == size02 ); + VERIFY( equal(lis09.begin(), lis09.end(), title04) ); + VERIFY( lis10.size() == size01 ); + VERIFY( equal(lis10.begin(), lis10.end(), title03) ); + VERIFY( lis09.get_allocator().get_personality() == personality02 ); + VERIFY( lis10.get_allocator().get_personality() == personality01 ); + + my_list lis11(title04, title04 + N4, alloc02); + size01 = lis11.size(); + personality01 = lis11.get_allocator().get_personality(); + my_list lis12(title01, title01 + N1, alloc01); + size02 = lis12.size(); + personality02 = lis12.get_allocator().get_personality(); + + lis11.swap(lis12); + VERIFY( lis11.size() == size02 ); + VERIFY( equal(lis11.begin(), lis11.end(), title01) ); + VERIFY( lis12.size() == size01 ); + VERIFY( equal(lis12.begin(), lis12.end(), title04) ); + VERIFY( lis11.get_allocator().get_personality() == personality02 ); + VERIFY( lis12.get_allocator().get_personality() == personality01 ); + + my_list lis13(title03, title03 + N3, alloc01); + size01 = lis13.size(); + personality01 = lis13.get_allocator().get_personality(); + my_list lis14(title03, title03 + N3, alloc02); + size02 = lis14.size(); + personality02 = lis14.get_allocator().get_personality(); + + lis13.swap(lis14); + VERIFY( lis13.size() == size02 ); + VERIFY( equal(lis13.begin(), lis13.end(), title03) ); + VERIFY( lis14.size() == size01 ); + VERIFY( equal(lis14.begin(), lis14.end(), title03) ); + VERIFY( lis13.get_allocator().get_personality() == personality02 ); + VERIFY( lis14.get_allocator().get_personality() == personality01 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/modifiers/swap.cc b/libstdc++-v3/testsuite/23_containers/map/modifiers/swap/1.cc index 85aa95cf11d..85aa95cf11d 100644 --- a/libstdc++-v3/testsuite/23_containers/map/modifiers/swap.cc +++ b/libstdc++-v3/testsuite/23_containers/map/modifiers/swap/1.cc diff --git a/libstdc++-v3/testsuite/23_containers/map/modifiers/swap/2.cc b/libstdc++-v3/testsuite/23_containers/map/modifiers/swap/2.cc new file mode 100644 index 00000000000..5b1a17b8900 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/modifiers/swap/2.cc @@ -0,0 +1,147 @@ +// 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. + +// 23.3.1 map::swap + +#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; + + typedef pair<const char, int> my_pair; + typedef __gnu_test::uneq_allocator<my_pair> my_alloc; + typedef map<char, int, less<char>, my_alloc> my_map; + + 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); + + map<char, int> map01_ref; + for (size_t i = 0; i < N1; ++i) + map01_ref.insert(my_pair(title01[i], i)); + map<char, int> map02_ref; + for (size_t i = 0; i < N2; ++i) + map02_ref.insert(my_pair(title02[i], i)); + map<char, int> map03_ref; + for (size_t i = 0; i < N3; ++i) + map03_ref.insert(my_pair(title03[i], i)); + map<char, int> map04_ref; + for (size_t i = 0; i < N4; ++i) + map04_ref.insert(my_pair(title04[i], i)); + + my_map::size_type size01, size02; + + my_alloc alloc01(1); + + my_map map01(less<char>(), alloc01); + size01 = map01.size(); + my_map map02(less<char>(), alloc01); + size02 = map02.size(); + + map01.swap(map02); + VERIFY( map01.size() == size02 ); + VERIFY( map01.empty() ); + VERIFY( map02.size() == size01 ); + VERIFY( map02.empty() ); + + my_map map03(less<char>(), alloc01); + size01 = map03.size(); + my_map map04(map02_ref.begin(), map02_ref.end(), less<char>(), alloc01); + size02 = map04.size(); + + map03.swap(map04); + VERIFY( map03.size() == size02 ); + VERIFY( equal(map03.begin(), map03.end(), map02_ref.begin()) ); + VERIFY( map04.size() == size01 ); + VERIFY( map04.empty() ); + + my_map map05(map01_ref.begin(), map01_ref.end(), less<char>(), alloc01); + size01 = map05.size(); + my_map map06(map02_ref.begin(), map02_ref.end(), less<char>(), alloc01); + size02 = map06.size(); + + map05.swap(map06); + VERIFY( map05.size() == size02 ); + VERIFY( equal(map05.begin(), map05.end(), map02_ref.begin()) ); + VERIFY( map06.size() == size01 ); + VERIFY( equal(map06.begin(), map06.end(), map01_ref.begin()) ); + + my_map map07(map01_ref.begin(), map01_ref.end(), less<char>(), alloc01); + size01 = map07.size(); + my_map map08(map03_ref.begin(), map03_ref.end(), less<char>(), alloc01); + size02 = map08.size(); + + map07.swap(map08); + VERIFY( map07.size() == size02 ); + VERIFY( equal(map07.begin(), map07.end(), map03_ref.begin()) ); + VERIFY( map08.size() == size01 ); + VERIFY( equal(map08.begin(), map08.end(), map01_ref.begin()) ); + + my_map map09(map03_ref.begin(), map03_ref.end(), less<char>(), alloc01); + size01 = map09.size(); + my_map map10(map04_ref.begin(), map04_ref.end(), less<char>(), alloc01); + size02 = map10.size(); + + map09.swap(map10); + VERIFY( map09.size() == size02 ); + VERIFY( equal(map09.begin(), map09.end(), map04_ref.begin()) ); + VERIFY( map10.size() == size01 ); + VERIFY( equal(map10.begin(), map10.end(), map03_ref.begin()) ); + + my_map map11(map04_ref.begin(), map04_ref.end(), less<char>(), alloc01); + size01 = map11.size(); + my_map map12(map01_ref.begin(), map01_ref.end(), less<char>(), alloc01); + size02 = map12.size(); + + map11.swap(map12); + VERIFY( map11.size() == size02 ); + VERIFY( equal(map11.begin(), map11.end(), map01_ref.begin()) ); + VERIFY( map12.size() == size01 ); + VERIFY( equal(map12.begin(), map12.end(), map04_ref.begin()) ); + + my_map map13(map03_ref.begin(), map03_ref.end(), less<char>(), alloc01); + size01 = map13.size(); + my_map map14(map03_ref.begin(), map03_ref.end(), less<char>(), alloc01); + size02 = map14.size(); + + map13.swap(map14); + VERIFY( map13.size() == size02 ); + VERIFY( equal(map13.begin(), map13.end(), map03_ref.begin()) ); + VERIFY( map14.size() == size01 ); + VERIFY( equal(map14.begin(), map14.end(), map03_ref.begin()) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/modifiers/swap/3.cc b/libstdc++-v3/testsuite/23_containers/map/modifiers/swap/3.cc new file mode 100644 index 00000000000..2152b4b001d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/modifiers/swap/3.cc @@ -0,0 +1,176 @@ +// 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. + +// 23.3.1 map::swap + +#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; + + typedef pair<const char, int> my_pair; + typedef __gnu_test::uneq_allocator<my_pair> my_alloc; + typedef map<char, int, less<char>, my_alloc> my_map; + + 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); + + map<char, int> map01_ref; + for (size_t i = 0; i < N1; ++i) + map01_ref.insert(my_pair(title01[i], i)); + map<char, int> map02_ref; + for (size_t i = 0; i < N2; ++i) + map02_ref.insert(my_pair(title02[i], i)); + map<char, int> map03_ref; + for (size_t i = 0; i < N3; ++i) + map03_ref.insert(my_pair(title03[i], i)); + map<char, int> map04_ref; + for (size_t i = 0; i < N4; ++i) + map04_ref.insert(my_pair(title04[i], i)); + + my_map::size_type size01, size02; + + my_alloc alloc01(1), alloc02(2); + int personality01, personality02; + + my_map map01(less<char>(), alloc01); + size01 = map01.size(); + personality01 = map01.get_allocator().get_personality(); + my_map map02(less<char>(), alloc02); + size02 = map02.size(); + personality02 = map02.get_allocator().get_personality(); + + map01.swap(map02); + VERIFY( map01.size() == size02 ); + VERIFY( map01.empty() ); + VERIFY( map02.size() == size01 ); + VERIFY( map02.empty() ); + VERIFY( map01.get_allocator().get_personality() == personality02 ); + VERIFY( map02.get_allocator().get_personality() == personality01 ); + + my_map map03(less<char>(), alloc02); + size01 = map03.size(); + personality01 = map03.get_allocator().get_personality(); + my_map map04(map02_ref.begin(), map02_ref.end(), less<char>(), alloc01); + size02 = map04.size(); + personality02 = map04.get_allocator().get_personality(); + + map03.swap(map04); + VERIFY( map03.size() == size02 ); + VERIFY( equal(map03.begin(), map03.end(), map02_ref.begin()) ); + VERIFY( map04.size() == size01 ); + VERIFY( map04.empty() ); + VERIFY( map03.get_allocator().get_personality() == personality02 ); + VERIFY( map04.get_allocator().get_personality() == personality01 ); + + my_map map05(map01_ref.begin(), map01_ref.end(), less<char>(), alloc01); + size01 = map05.size(); + personality01 = map05.get_allocator().get_personality(); + my_map map06(map02_ref.begin(), map02_ref.end(), less<char>(), alloc02); + size02 = map06.size(); + personality02 = map06.get_allocator().get_personality(); + + map05.swap(map06); + VERIFY( map05.size() == size02 ); + VERIFY( equal(map05.begin(), map05.end(), map02_ref.begin()) ); + VERIFY( map06.size() == size01 ); + VERIFY( equal(map06.begin(), map06.end(), map01_ref.begin()) ); + VERIFY( map05.get_allocator().get_personality() == personality02 ); + VERIFY( map06.get_allocator().get_personality() == personality01 ); + + my_map map07(map01_ref.begin(), map01_ref.end(), less<char>(), alloc02); + size01 = map07.size(); + personality01 = map07.get_allocator().get_personality(); + my_map map08(map03_ref.begin(), map03_ref.end(), less<char>(), alloc01); + size02 = map08.size(); + personality02 = map08.get_allocator().get_personality(); + + map07.swap(map08); + VERIFY( map07.size() == size02 ); + VERIFY( equal(map07.begin(), map07.end(), map03_ref.begin()) ); + VERIFY( map08.size() == size01 ); + VERIFY( equal(map08.begin(), map08.end(), map01_ref.begin()) ); + VERIFY( map07.get_allocator().get_personality() == personality02 ); + VERIFY( map08.get_allocator().get_personality() == personality01 ); + + my_map map09(map03_ref.begin(), map03_ref.end(), less<char>(), alloc01); + size01 = map09.size(); + personality01 = map09.get_allocator().get_personality(); + my_map map10(map04_ref.begin(), map04_ref.end(), less<char>(), alloc02); + size02 = map10.size(); + personality02 = map10.get_allocator().get_personality(); + + map09.swap(map10); + VERIFY( map09.size() == size02 ); + VERIFY( equal(map09.begin(), map09.end(), map04_ref.begin()) ); + VERIFY( map10.size() == size01 ); + VERIFY( equal(map10.begin(), map10.end(), map03_ref.begin()) ); + VERIFY( map09.get_allocator().get_personality() == personality02 ); + VERIFY( map10.get_allocator().get_personality() == personality01 ); + + my_map map11(map04_ref.begin(), map04_ref.end(), less<char>(), alloc02); + size01 = map11.size(); + personality01 = map11.get_allocator().get_personality(); + my_map map12(map01_ref.begin(), map01_ref.end(), less<char>(), alloc01); + size02 = map12.size(); + personality02 = map12.get_allocator().get_personality(); + + map11.swap(map12); + VERIFY( map11.size() == size02 ); + VERIFY( equal(map11.begin(), map11.end(), map01_ref.begin()) ); + VERIFY( map12.size() == size01 ); + VERIFY( equal(map12.begin(), map12.end(), map04_ref.begin()) ); + VERIFY( map11.get_allocator().get_personality() == personality02 ); + VERIFY( map12.get_allocator().get_personality() == personality01 ); + + my_map map13(map03_ref.begin(), map03_ref.end(), less<char>(), alloc01); + size01 = map13.size(); + personality01 = map13.get_allocator().get_personality(); + my_map map14(map03_ref.begin(), map03_ref.end(), less<char>(), alloc02); + size02 = map14.size(); + personality02 = map14.get_allocator().get_personality(); + + map13.swap(map14); + VERIFY( map13.size() == size02 ); + VERIFY( equal(map13.begin(), map13.end(), map03_ref.begin()) ); + VERIFY( map14.size() == size01 ); + VERIFY( equal(map14.begin(), map14.end(), map03_ref.begin()) ); + VERIFY( map13.get_allocator().get_personality() == personality02 ); + VERIFY( map14.get_allocator().get_personality() == personality01 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap.cc b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap/1.cc index 76cbe465cc3..76cbe465cc3 100644 --- a/libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap.cc +++ b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap/1.cc diff --git a/libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap/2.cc b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap/2.cc new file mode 100644 index 00000000000..dc2c9c9080d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap/2.cc @@ -0,0 +1,147 @@ +// 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. + +// 23.3.2 multimap::swap + +#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; + + typedef pair<const char, int> my_pair; + typedef __gnu_test::uneq_allocator<my_pair> my_alloc; + typedef multimap<char, int, less<char>, my_alloc> my_mmap; + + 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); + + multimap<char, int> mmap01_ref; + for (size_t i = 0; i < N1; ++i) + mmap01_ref.insert(my_pair(title01[i], i)); + multimap<char, int> mmap02_ref; + for (size_t i = 0; i < N2; ++i) + mmap02_ref.insert(my_pair(title02[i], i)); + multimap<char, int> mmap03_ref; + for (size_t i = 0; i < N3; ++i) + mmap03_ref.insert(my_pair(title03[i], i)); + multimap<char, int> mmap04_ref; + for (size_t i = 0; i < N4; ++i) + mmap04_ref.insert(my_pair(title04[i], i)); + + my_mmap::size_type size01, size02; + + my_alloc alloc01(1); + + my_mmap mmap01(less<char>(), alloc01); + size01 = mmap01.size(); + my_mmap mmap02(less<char>(), alloc01); + size02 = mmap02.size(); + + mmap01.swap(mmap02); + VERIFY( mmap01.size() == size02 ); + VERIFY( mmap01.empty() ); + VERIFY( mmap02.size() == size01 ); + VERIFY( mmap02.empty() ); + + my_mmap mmap03(less<char>(), alloc01); + size01 = mmap03.size(); + my_mmap mmap04(mmap02_ref.begin(), mmap02_ref.end(), less<char>(), alloc01); + size02 = mmap04.size(); + + mmap03.swap(mmap04); + VERIFY( mmap03.size() == size02 ); + VERIFY( equal(mmap03.begin(), mmap03.end(), mmap02_ref.begin()) ); + VERIFY( mmap04.size() == size01 ); + VERIFY( mmap04.empty() ); + + my_mmap mmap05(mmap01_ref.begin(), mmap01_ref.end(), less<char>(), alloc01); + size01 = mmap05.size(); + my_mmap mmap06(mmap02_ref.begin(), mmap02_ref.end(), less<char>(), alloc01); + size02 = mmap06.size(); + + mmap05.swap(mmap06); + VERIFY( mmap05.size() == size02 ); + VERIFY( equal(mmap05.begin(), mmap05.end(), mmap02_ref.begin()) ); + VERIFY( mmap06.size() == size01 ); + VERIFY( equal(mmap06.begin(), mmap06.end(), mmap01_ref.begin()) ); + + my_mmap mmap07(mmap01_ref.begin(), mmap01_ref.end(), less<char>(), alloc01); + size01 = mmap07.size(); + my_mmap mmap08(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc01); + size02 = mmap08.size(); + + mmap07.swap(mmap08); + VERIFY( mmap07.size() == size02 ); + VERIFY( equal(mmap07.begin(), mmap07.end(), mmap03_ref.begin()) ); + VERIFY( mmap08.size() == size01 ); + VERIFY( equal(mmap08.begin(), mmap08.end(), mmap01_ref.begin()) ); + + my_mmap mmap09(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc01); + size01 = mmap09.size(); + my_mmap mmap10(mmap04_ref.begin(), mmap04_ref.end(), less<char>(), alloc01); + size02 = mmap10.size(); + + mmap09.swap(mmap10); + VERIFY( mmap09.size() == size02 ); + VERIFY( equal(mmap09.begin(), mmap09.end(), mmap04_ref.begin()) ); + VERIFY( mmap10.size() == size01 ); + VERIFY( equal(mmap10.begin(), mmap10.end(), mmap03_ref.begin()) ); + + my_mmap mmap11(mmap04_ref.begin(), mmap04_ref.end(), less<char>(), alloc01); + size01 = mmap11.size(); + my_mmap mmap12(mmap01_ref.begin(), mmap01_ref.end(), less<char>(), alloc01); + size02 = mmap12.size(); + + mmap11.swap(mmap12); + VERIFY( mmap11.size() == size02 ); + VERIFY( equal(mmap11.begin(), mmap11.end(), mmap01_ref.begin()) ); + VERIFY( mmap12.size() == size01 ); + VERIFY( equal(mmap12.begin(), mmap12.end(), mmap04_ref.begin()) ); + + my_mmap mmap13(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc01); + size01 = mmap13.size(); + my_mmap mmap14(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc01); + size02 = mmap14.size(); + + mmap13.swap(mmap14); + VERIFY( mmap13.size() == size02 ); + VERIFY( equal(mmap13.begin(), mmap13.end(), mmap03_ref.begin()) ); + VERIFY( mmap14.size() == size01 ); + VERIFY( equal(mmap14.begin(), mmap14.end(), mmap03_ref.begin()) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap/3.cc b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap/3.cc new file mode 100644 index 00000000000..9214490f2b9 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/modifiers/swap/3.cc @@ -0,0 +1,176 @@ +// 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. + +// 23.3.2 multimap::swap + +#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; + + typedef pair<const char, int> my_pair; + typedef __gnu_test::uneq_allocator<my_pair> my_alloc; + typedef multimap<char, int, less<char>, my_alloc> my_mmap; + + 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); + + multimap<char, int> mmap01_ref; + for (size_t i = 0; i < N1; ++i) + mmap01_ref.insert(my_pair(title01[i], i)); + multimap<char, int> mmap02_ref; + for (size_t i = 0; i < N2; ++i) + mmap02_ref.insert(my_pair(title02[i], i)); + multimap<char, int> mmap03_ref; + for (size_t i = 0; i < N3; ++i) + mmap03_ref.insert(my_pair(title03[i], i)); + multimap<char, int> mmap04_ref; + for (size_t i = 0; i < N4; ++i) + mmap04_ref.insert(my_pair(title04[i], i)); + + my_mmap::size_type size01, size02; + + my_alloc alloc01(1), alloc02(2); + int personality01, personality02; + + my_mmap mmap01(less<char>(), alloc01); + size01 = mmap01.size(); + personality01 = mmap01.get_allocator().get_personality(); + my_mmap mmap02(less<char>(), alloc02); + size02 = mmap02.size(); + personality02 = mmap02.get_allocator().get_personality(); + + mmap01.swap(mmap02); + VERIFY( mmap01.size() == size02 ); + VERIFY( mmap01.empty() ); + VERIFY( mmap02.size() == size01 ); + VERIFY( mmap02.empty() ); + VERIFY( mmap01.get_allocator().get_personality() == personality02 ); + VERIFY( mmap02.get_allocator().get_personality() == personality01 ); + + my_mmap mmap03(less<char>(), alloc02); + size01 = mmap03.size(); + personality01 = mmap03.get_allocator().get_personality(); + my_mmap mmap04(mmap02_ref.begin(), mmap02_ref.end(), less<char>(), alloc01); + size02 = mmap04.size(); + personality02 = mmap04.get_allocator().get_personality(); + + mmap03.swap(mmap04); + VERIFY( mmap03.size() == size02 ); + VERIFY( equal(mmap03.begin(), mmap03.end(), mmap02_ref.begin()) ); + VERIFY( mmap04.size() == size01 ); + VERIFY( mmap04.empty() ); + VERIFY( mmap03.get_allocator().get_personality() == personality02 ); + VERIFY( mmap04.get_allocator().get_personality() == personality01 ); + + my_mmap mmap05(mmap01_ref.begin(), mmap01_ref.end(), less<char>(), alloc01); + size01 = mmap05.size(); + personality01 = mmap05.get_allocator().get_personality(); + my_mmap mmap06(mmap02_ref.begin(), mmap02_ref.end(), less<char>(), alloc02); + size02 = mmap06.size(); + personality02 = mmap06.get_allocator().get_personality(); + + mmap05.swap(mmap06); + VERIFY( mmap05.size() == size02 ); + VERIFY( equal(mmap05.begin(), mmap05.end(), mmap02_ref.begin()) ); + VERIFY( mmap06.size() == size01 ); + VERIFY( equal(mmap06.begin(), mmap06.end(), mmap01_ref.begin()) ); + VERIFY( mmap05.get_allocator().get_personality() == personality02 ); + VERIFY( mmap06.get_allocator().get_personality() == personality01 ); + + my_mmap mmap07(mmap01_ref.begin(), mmap01_ref.end(), less<char>(), alloc02); + size01 = mmap07.size(); + personality01 = mmap07.get_allocator().get_personality(); + my_mmap mmap08(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc01); + size02 = mmap08.size(); + personality02 = mmap08.get_allocator().get_personality(); + + mmap07.swap(mmap08); + VERIFY( mmap07.size() == size02 ); + VERIFY( equal(mmap07.begin(), mmap07.end(), mmap03_ref.begin()) ); + VERIFY( mmap08.size() == size01 ); + VERIFY( equal(mmap08.begin(), mmap08.end(), mmap01_ref.begin()) ); + VERIFY( mmap07.get_allocator().get_personality() == personality02 ); + VERIFY( mmap08.get_allocator().get_personality() == personality01 ); + + my_mmap mmap09(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc01); + size01 = mmap09.size(); + personality01 = mmap09.get_allocator().get_personality(); + my_mmap mmap10(mmap04_ref.begin(), mmap04_ref.end(), less<char>(), alloc02); + size02 = mmap10.size(); + personality02 = mmap10.get_allocator().get_personality(); + + mmap09.swap(mmap10); + VERIFY( mmap09.size() == size02 ); + VERIFY( equal(mmap09.begin(), mmap09.end(), mmap04_ref.begin()) ); + VERIFY( mmap10.size() == size01 ); + VERIFY( equal(mmap10.begin(), mmap10.end(), mmap03_ref.begin()) ); + VERIFY( mmap09.get_allocator().get_personality() == personality02 ); + VERIFY( mmap10.get_allocator().get_personality() == personality01 ); + + my_mmap mmap11(mmap04_ref.begin(), mmap04_ref.end(), less<char>(), alloc02); + size01 = mmap11.size(); + personality01 = mmap11.get_allocator().get_personality(); + my_mmap mmap12(mmap01_ref.begin(), mmap01_ref.end(), less<char>(), alloc01); + size02 = mmap12.size(); + personality02 = mmap12.get_allocator().get_personality(); + + mmap11.swap(mmap12); + VERIFY( mmap11.size() == size02 ); + VERIFY( equal(mmap11.begin(), mmap11.end(), mmap01_ref.begin()) ); + VERIFY( mmap12.size() == size01 ); + VERIFY( equal(mmap12.begin(), mmap12.end(), mmap04_ref.begin()) ); + VERIFY( mmap11.get_allocator().get_personality() == personality02 ); + VERIFY( mmap12.get_allocator().get_personality() == personality01 ); + + my_mmap mmap13(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc01); + size01 = mmap13.size(); + personality01 = mmap13.get_allocator().get_personality(); + my_mmap mmap14(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc02); + size02 = mmap14.size(); + personality02 = mmap14.get_allocator().get_personality(); + + mmap13.swap(mmap14); + VERIFY( mmap13.size() == size02 ); + VERIFY( equal(mmap13.begin(), mmap13.end(), mmap03_ref.begin()) ); + VERIFY( mmap14.size() == size01 ); + VERIFY( equal(mmap14.begin(), mmap14.end(), mmap03_ref.begin()) ); + VERIFY( mmap13.get_allocator().get_personality() == personality02 ); + VERIFY( mmap14.get_allocator().get_personality() == personality01 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/modifiers/swap.cc b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/swap/1.cc index 23851990016..23851990016 100644 --- a/libstdc++-v3/testsuite/23_containers/multiset/modifiers/swap.cc +++ b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/swap/1.cc diff --git a/libstdc++-v3/testsuite/23_containers/multiset/modifiers/swap/2.cc b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/swap/2.cc new file mode 100644 index 00000000000..587dc9c4b9e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/swap/2.cc @@ -0,0 +1,138 @@ +// 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. + +// 23.3.4 multiset::swap + +#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; + + typedef __gnu_test::uneq_allocator<char> my_alloc; + typedef multiset<char, less<char>, my_alloc> my_multiset; + + 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); + + const multiset<char> mset01_ref(title01, title01 + N1); + const multiset<char> mset02_ref(title02, title02 + N2); + const multiset<char> mset03_ref(title03, title03 + N3); + const multiset<char> mset04_ref(title04, title04 + N4); + + my_multiset::size_type size01, size02; + + my_alloc alloc01(1); + + my_multiset mset01(less<char>(), alloc01); + size01 = mset01.size(); + my_multiset mset02(less<char>(), alloc01); + size02 = mset02.size(); + + mset01.swap(mset02); + VERIFY( mset01.size() == size02 ); + VERIFY( mset01.empty() ); + VERIFY( mset02.size() == size01 ); + VERIFY( mset02.empty() ); + + my_multiset mset03(less<char>(), alloc01); + size01 = mset03.size(); + my_multiset mset04(title02, title02 + N2, less<char>(), alloc01); + size02 = mset04.size(); + + mset03.swap(mset04); + VERIFY( mset03.size() == size02 ); + VERIFY( equal(mset03.begin(), mset03.end(), mset02_ref.begin()) ); + VERIFY( mset04.size() == size01 ); + VERIFY( mset04.empty() ); + + my_multiset mset05(title01, title01 + N1, less<char>(), alloc01); + size01 = mset05.size(); + my_multiset mset06(title02, title02 + N2, less<char>(), alloc01); + size02 = mset06.size(); + + mset05.swap(mset06); + VERIFY( mset05.size() == size02 ); + VERIFY( equal(mset05.begin(), mset05.end(), mset02_ref.begin()) ); + VERIFY( mset06.size() == size01 ); + VERIFY( equal(mset06.begin(), mset06.end(), mset01_ref.begin()) ); + + my_multiset mset07(title01, title01 + N1, less<char>(), alloc01); + size01 = mset07.size(); + my_multiset mset08(title03, title03 + N3, less<char>(), alloc01); + size02 = mset08.size(); + + mset07.swap(mset08); + VERIFY( mset07.size() == size02 ); + VERIFY( equal(mset07.begin(), mset07.end(), mset03_ref.begin()) ); + VERIFY( mset08.size() == size01 ); + VERIFY( equal(mset08.begin(), mset08.end(), mset01_ref.begin()) ); + + my_multiset mset09(title03, title03 + N3, less<char>(), alloc01); + size01 = mset09.size(); + my_multiset mset10(title04, title04 + N4, less<char>(), alloc01); + size02 = mset10.size(); + + mset09.swap(mset10); + VERIFY( mset09.size() == size02 ); + VERIFY( equal(mset09.begin(), mset09.end(), mset04_ref.begin()) ); + VERIFY( mset10.size() == size01 ); + VERIFY( equal(mset10.begin(), mset10.end(), mset03_ref.begin()) ); + + my_multiset mset11(title04, title04 + N4, less<char>(), alloc01); + size01 = mset11.size(); + my_multiset mset12(title01, title01 + N1, less<char>(), alloc01); + size02 = mset12.size(); + + mset11.swap(mset12); + VERIFY( mset11.size() == size02 ); + VERIFY( equal(mset11.begin(), mset11.end(), mset01_ref.begin()) ); + VERIFY( mset12.size() == size01 ); + VERIFY( equal(mset12.begin(), mset12.end(), mset04_ref.begin()) ); + + my_multiset mset13(title03, title03 + N3, less<char>(), alloc01); + size01 = mset13.size(); + my_multiset mset14(title03, title03 + N3, less<char>(), alloc01); + size02 = mset14.size(); + + mset13.swap(mset14); + VERIFY( mset13.size() == size02 ); + VERIFY( equal(mset13.begin(), mset13.end(), mset03_ref.begin()) ); + VERIFY( mset14.size() == size01 ); + VERIFY( equal(mset14.begin(), mset14.end(), mset03_ref.begin()) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/multiset/modifiers/swap/3.cc b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/swap/3.cc new file mode 100644 index 00000000000..e5a05d7b138 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/modifiers/swap/3.cc @@ -0,0 +1,167 @@ +// 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. + +// 23.3.4 multiset::swap + +#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; + + typedef __gnu_test::uneq_allocator<char> my_alloc; + typedef multiset<char, less<char>, my_alloc> my_multiset; + + 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); + + const multiset<char> mset01_ref(title01, title01 + N1); + const multiset<char> mset02_ref(title02, title02 + N2); + const multiset<char> mset03_ref(title03, title03 + N3); + const multiset<char> mset04_ref(title04, title04 + N4); + + my_multiset::size_type size01, size02; + + my_alloc alloc01(1), alloc02(2); + int personality01, personality02; + + my_multiset mset01(less<char>(), alloc01); + size01 = mset01.size(); + personality01 = mset01.get_allocator().get_personality(); + my_multiset mset02(less<char>(), alloc02); + size02 = mset02.size(); + personality02 = mset02.get_allocator().get_personality(); + + mset01.swap(mset02); + VERIFY( mset01.size() == size02 ); + VERIFY( mset01.empty() ); + VERIFY( mset02.size() == size01 ); + VERIFY( mset02.empty() ); + VERIFY( mset01.get_allocator().get_personality() == personality02 ); + VERIFY( mset02.get_allocator().get_personality() == personality01 ); + + my_multiset mset03(less<char>(), alloc02); + size01 = mset03.size(); + personality01 = mset03.get_allocator().get_personality(); + my_multiset mset04(title02, title02 + N2, less<char>(), alloc01); + size02 = mset04.size(); + personality02 = mset04.get_allocator().get_personality(); + + mset03.swap(mset04); + VERIFY( mset03.size() == size02 ); + VERIFY( equal(mset03.begin(), mset03.end(), mset02_ref.begin()) ); + VERIFY( mset04.size() == size01 ); + VERIFY( mset04.empty() ); + VERIFY( mset03.get_allocator().get_personality() == personality02 ); + VERIFY( mset04.get_allocator().get_personality() == personality01 ); + + my_multiset mset05(title01, title01 + N1, less<char>(), alloc01); + size01 = mset05.size(); + personality01 = mset05.get_allocator().get_personality(); + my_multiset mset06(title02, title02 + N2, less<char>(), alloc02); + size02 = mset06.size(); + personality02 = mset06.get_allocator().get_personality(); + + mset05.swap(mset06); + VERIFY( mset05.size() == size02 ); + VERIFY( equal(mset05.begin(), mset05.end(), mset02_ref.begin()) ); + VERIFY( mset06.size() == size01 ); + VERIFY( equal(mset06.begin(), mset06.end(), mset01_ref.begin()) ); + VERIFY( mset05.get_allocator().get_personality() == personality02 ); + VERIFY( mset06.get_allocator().get_personality() == personality01 ); + + my_multiset mset07(title01, title01 + N1, less<char>(), alloc02); + size01 = mset07.size(); + personality01 = mset07.get_allocator().get_personality(); + my_multiset mset08(title03, title03 + N3, less<char>(), alloc01); + size02 = mset08.size(); + personality02 = mset08.get_allocator().get_personality(); + + mset07.swap(mset08); + VERIFY( mset07.size() == size02 ); + VERIFY( equal(mset07.begin(), mset07.end(), mset03_ref.begin()) ); + VERIFY( mset08.size() == size01 ); + VERIFY( equal(mset08.begin(), mset08.end(), mset01_ref.begin()) ); + VERIFY( mset07.get_allocator().get_personality() == personality02 ); + VERIFY( mset08.get_allocator().get_personality() == personality01 ); + + my_multiset mset09(title03, title03 + N3, less<char>(), alloc01); + size01 = mset09.size(); + personality01 = mset09.get_allocator().get_personality(); + my_multiset mset10(title04, title04 + N4, less<char>(), alloc02); + size02 = mset10.size(); + personality02 = mset10.get_allocator().get_personality(); + + mset09.swap(mset10); + VERIFY( mset09.size() == size02 ); + VERIFY( equal(mset09.begin(), mset09.end(), mset04_ref.begin()) ); + VERIFY( mset10.size() == size01 ); + VERIFY( equal(mset10.begin(), mset10.end(), mset03_ref.begin()) ); + VERIFY( mset09.get_allocator().get_personality() == personality02 ); + VERIFY( mset10.get_allocator().get_personality() == personality01 ); + + my_multiset mset11(title04, title04 + N4, less<char>(), alloc02); + size01 = mset11.size(); + personality01 = mset11.get_allocator().get_personality(); + my_multiset mset12(title01, title01 + N1, less<char>(), alloc01); + size02 = mset12.size(); + personality02 = mset12.get_allocator().get_personality(); + + mset11.swap(mset12); + VERIFY( mset11.size() == size02 ); + VERIFY( equal(mset11.begin(), mset11.end(), mset01_ref.begin()) ); + VERIFY( mset12.size() == size01 ); + VERIFY( equal(mset12.begin(), mset12.end(), mset04_ref.begin()) ); + VERIFY( mset11.get_allocator().get_personality() == personality02 ); + VERIFY( mset12.get_allocator().get_personality() == personality01 ); + + my_multiset mset13(title03, title03 + N3, less<char>(), alloc01); + size01 = mset13.size(); + personality01 = mset13.get_allocator().get_personality(); + my_multiset mset14(title03, title03 + N3, less<char>(), alloc02); + size02 = mset14.size(); + personality02 = mset14.get_allocator().get_personality(); + + mset13.swap(mset14); + VERIFY( mset13.size() == size02 ); + VERIFY( equal(mset13.begin(), mset13.end(), mset03_ref.begin()) ); + VERIFY( mset14.size() == size01 ); + VERIFY( equal(mset14.begin(), mset14.end(), mset03_ref.begin()) ); + VERIFY( mset13.get_allocator().get_personality() == personality02 ); + VERIFY( mset14.get_allocator().get_personality() == personality01 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/set/modifiers/swap.cc b/libstdc++-v3/testsuite/23_containers/set/modifiers/swap/1.cc index 7efa8a6bf60..7efa8a6bf60 100644 --- a/libstdc++-v3/testsuite/23_containers/set/modifiers/swap.cc +++ b/libstdc++-v3/testsuite/23_containers/set/modifiers/swap/1.cc diff --git a/libstdc++-v3/testsuite/23_containers/set/modifiers/swap/2.cc b/libstdc++-v3/testsuite/23_containers/set/modifiers/swap/2.cc new file mode 100644 index 00000000000..1849630f8c7 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/modifiers/swap/2.cc @@ -0,0 +1,138 @@ +// 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. + +// 23.3.3 set::swap + +#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; + + typedef __gnu_test::uneq_allocator<char> my_alloc; + typedef set<char, less<char>, my_alloc> my_set; + + 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); + + const set<char> set01_ref(title01, title01 + N1); + const set<char> set02_ref(title02, title02 + N2); + const set<char> set03_ref(title03, title03 + N3); + const set<char> set04_ref(title04, title04 + N4); + + my_set::size_type size01, size02; + + my_alloc alloc01(1); + + my_set set01(less<char>(), alloc01); + size01 = set01.size(); + my_set set02(less<char>(), alloc01); + size02 = set02.size(); + + set01.swap(set02); + VERIFY( set01.size() == size02 ); + VERIFY( set01.empty() ); + VERIFY( set02.size() == size01 ); + VERIFY( set02.empty() ); + + my_set set03(less<char>(), alloc01); + size01 = set03.size(); + my_set set04(title02, title02 + N2, less<char>(), alloc01); + size02 = set04.size(); + + set03.swap(set04); + VERIFY( set03.size() == size02 ); + VERIFY( equal(set03.begin(), set03.end(), set02_ref.begin()) ); + VERIFY( set04.size() == size01 ); + VERIFY( set04.empty() ); + + my_set set05(title01, title01 + N1, less<char>(), alloc01); + size01 = set05.size(); + my_set set06(title02, title02 + N2, less<char>(), alloc01); + size02 = set06.size(); + + set05.swap(set06); + VERIFY( set05.size() == size02 ); + VERIFY( equal(set05.begin(), set05.end(), set02_ref.begin()) ); + VERIFY( set06.size() == size01 ); + VERIFY( equal(set06.begin(), set06.end(), set01_ref.begin()) ); + + my_set set07(title01, title01 + N1, less<char>(), alloc01); + size01 = set07.size(); + my_set set08(title03, title03 + N3, less<char>(), alloc01); + size02 = set08.size(); + + set07.swap(set08); + VERIFY( set07.size() == size02 ); + VERIFY( equal(set07.begin(), set07.end(), set03_ref.begin()) ); + VERIFY( set08.size() == size01 ); + VERIFY( equal(set08.begin(), set08.end(), set01_ref.begin()) ); + + my_set set09(title03, title03 + N3, less<char>(), alloc01); + size01 = set09.size(); + my_set set10(title04, title04 + N4, less<char>(), alloc01); + size02 = set10.size(); + + set09.swap(set10); + VERIFY( set09.size() == size02 ); + VERIFY( equal(set09.begin(), set09.end(), set04_ref.begin()) ); + VERIFY( set10.size() == size01 ); + VERIFY( equal(set10.begin(), set10.end(), set03_ref.begin()) ); + + my_set set11(title04, title04 + N4, less<char>(), alloc01); + size01 = set11.size(); + my_set set12(title01, title01 + N1, less<char>(), alloc01); + size02 = set12.size(); + + set11.swap(set12); + VERIFY( set11.size() == size02 ); + VERIFY( equal(set11.begin(), set11.end(), set01_ref.begin()) ); + VERIFY( set12.size() == size01 ); + VERIFY( equal(set12.begin(), set12.end(), set04_ref.begin()) ); + + my_set set13(title03, title03 + N3, less<char>(), alloc01); + size01 = set13.size(); + my_set set14(title03, title03 + N3, less<char>(), alloc01); + size02 = set14.size(); + + set13.swap(set14); + VERIFY( set13.size() == size02 ); + VERIFY( equal(set13.begin(), set13.end(), set03_ref.begin()) ); + VERIFY( set14.size() == size01 ); + VERIFY( equal(set14.begin(), set14.end(), set03_ref.begin()) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/set/modifiers/swap/3.cc b/libstdc++-v3/testsuite/23_containers/set/modifiers/swap/3.cc new file mode 100644 index 00000000000..8e71af46d46 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/modifiers/swap/3.cc @@ -0,0 +1,167 @@ +// 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. + +// 23.3.3 set::swap + +#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; + + typedef __gnu_test::uneq_allocator<char> my_alloc; + typedef set<char, less<char>, my_alloc> my_set; + + 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); + + const set<char> set01_ref(title01, title01 + N1); + const set<char> set02_ref(title02, title02 + N2); + const set<char> set03_ref(title03, title03 + N3); + const set<char> set04_ref(title04, title04 + N4); + + my_set::size_type size01, size02; + + my_alloc alloc01(1), alloc02(2); + int personality01, personality02; + + my_set set01(less<char>(), alloc01); + size01 = set01.size(); + personality01 = set01.get_allocator().get_personality(); + my_set set02(less<char>(), alloc02); + size02 = set02.size(); + personality02 = set02.get_allocator().get_personality(); + + set01.swap(set02); + VERIFY( set01.size() == size02 ); + VERIFY( set01.empty() ); + VERIFY( set02.size() == size01 ); + VERIFY( set02.empty() ); + VERIFY( set01.get_allocator().get_personality() == personality02 ); + VERIFY( set02.get_allocator().get_personality() == personality01 ); + + my_set set03(less<char>(), alloc02); + size01 = set03.size(); + personality01 = set03.get_allocator().get_personality(); + my_set set04(title02, title02 + N2, less<char>(), alloc01); + size02 = set04.size(); + personality02 = set04.get_allocator().get_personality(); + + set03.swap(set04); + VERIFY( set03.size() == size02 ); + VERIFY( equal(set03.begin(), set03.end(), set02_ref.begin()) ); + VERIFY( set04.size() == size01 ); + VERIFY( set04.empty() ); + VERIFY( set03.get_allocator().get_personality() == personality02 ); + VERIFY( set04.get_allocator().get_personality() == personality01 ); + + my_set set05(title01, title01 + N1, less<char>(), alloc01); + size01 = set05.size(); + personality01 = set05.get_allocator().get_personality(); + my_set set06(title02, title02 + N2, less<char>(), alloc02); + size02 = set06.size(); + personality02 = set06.get_allocator().get_personality(); + + set05.swap(set06); + VERIFY( set05.size() == size02 ); + VERIFY( equal(set05.begin(), set05.end(), set02_ref.begin()) ); + VERIFY( set06.size() == size01 ); + VERIFY( equal(set06.begin(), set06.end(), set01_ref.begin()) ); + VERIFY( set05.get_allocator().get_personality() == personality02 ); + VERIFY( set06.get_allocator().get_personality() == personality01 ); + + my_set set07(title01, title01 + N1, less<char>(), alloc02); + size01 = set07.size(); + personality01 = set07.get_allocator().get_personality(); + my_set set08(title03, title03 + N3, less<char>(), alloc01); + size02 = set08.size(); + personality02 = set08.get_allocator().get_personality(); + + set07.swap(set08); + VERIFY( set07.size() == size02 ); + VERIFY( equal(set07.begin(), set07.end(), set03_ref.begin()) ); + VERIFY( set08.size() == size01 ); + VERIFY( equal(set08.begin(), set08.end(), set01_ref.begin()) ); + VERIFY( set07.get_allocator().get_personality() == personality02 ); + VERIFY( set08.get_allocator().get_personality() == personality01 ); + + my_set set09(title03, title03 + N3, less<char>(), alloc01); + size01 = set09.size(); + personality01 = set09.get_allocator().get_personality(); + my_set set10(title04, title04 + N4, less<char>(), alloc02); + size02 = set10.size(); + personality02 = set10.get_allocator().get_personality(); + + set09.swap(set10); + VERIFY( set09.size() == size02 ); + VERIFY( equal(set09.begin(), set09.end(), set04_ref.begin()) ); + VERIFY( set10.size() == size01 ); + VERIFY( equal(set10.begin(), set10.end(), set03_ref.begin()) ); + VERIFY( set09.get_allocator().get_personality() == personality02 ); + VERIFY( set10.get_allocator().get_personality() == personality01 ); + + my_set set11(title04, title04 + N4, less<char>(), alloc02); + size01 = set11.size(); + personality01 = set11.get_allocator().get_personality(); + my_set set12(title01, title01 + N1, less<char>(), alloc01); + size02 = set12.size(); + personality02 = set12.get_allocator().get_personality(); + + set11.swap(set12); + VERIFY( set11.size() == size02 ); + VERIFY( equal(set11.begin(), set11.end(), set01_ref.begin()) ); + VERIFY( set12.size() == size01 ); + VERIFY( equal(set12.begin(), set12.end(), set04_ref.begin()) ); + VERIFY( set11.get_allocator().get_personality() == personality02 ); + VERIFY( set12.get_allocator().get_personality() == personality01 ); + + my_set set13(title03, title03 + N3, less<char>(), alloc01); + size01 = set13.size(); + personality01 = set13.get_allocator().get_personality(); + my_set set14(title03, title03 + N3, less<char>(), alloc02); + size02 = set14.size(); + personality02 = set14.get_allocator().get_personality(); + + set13.swap(set14); + VERIFY( set13.size() == size02 ); + VERIFY( equal(set13.begin(), set13.end(), set03_ref.begin()) ); + VERIFY( set14.size() == size01 ); + VERIFY( equal(set14.begin(), set14.end(), set03_ref.begin()) ); + VERIFY( set13.get_allocator().get_personality() == personality02 ); + VERIFY( set14.get_allocator().get_personality() == personality01 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/1.cc index 8489945354a..8489945354a 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/1.cc diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/2.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/2.cc new file mode 100644 index 00000000000..ea41b4af38d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/2.cc @@ -0,0 +1,133 @@ +// 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. + +// 23.2.4.3 vector::swap + +#include <vector> +#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; + + typedef __gnu_test::uneq_allocator<char> my_alloc; + typedef vector<char, my_alloc> my_vector; + + 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); + + my_vector::size_type size01, size02; + + my_alloc alloc01(1); + + my_vector vec01(alloc01); + size01 = vec01.size(); + my_vector vec02(alloc01); + size02 = vec02.size(); + + vec01.swap(vec02); + VERIFY( vec01.size() == size02 ); + VERIFY( vec01.empty() ); + VERIFY( vec02.size() == size01 ); + VERIFY( vec02.empty() ); + + my_vector vec03(alloc01); + size01 = vec03.size(); + my_vector vec04(title02, title02 + N2, alloc01); + size02 = vec04.size(); + + vec03.swap(vec04); + VERIFY( vec03.size() == size02 ); + VERIFY( equal(vec03.begin(), vec03.end(), title02) ); + VERIFY( vec04.size() == size01 ); + VERIFY( vec04.empty() ); + + my_vector vec05(title01, title01 + N1, alloc01); + size01 = vec05.size(); + my_vector vec06(title02, title02 + N2, alloc01); + size02 = vec06.size(); + + vec05.swap(vec06); + VERIFY( vec05.size() == size02 ); + VERIFY( equal(vec05.begin(), vec05.end(), title02) ); + VERIFY( vec06.size() == size01 ); + VERIFY( equal(vec06.begin(), vec06.end(), title01) ); + + my_vector vec07(title01, title01 + N1, alloc01); + size01 = vec07.size(); + my_vector vec08(title03, title03 + N3, alloc01); + size02 = vec08.size(); + + vec07.swap(vec08); + VERIFY( vec07.size() == size02 ); + VERIFY( equal(vec07.begin(), vec07.end(), title03) ); + VERIFY( vec08.size() == size01 ); + VERIFY( equal(vec08.begin(), vec08.end(), title01) ); + + my_vector vec09(title03, title03 + N3, alloc01); + size01 = vec09.size(); + my_vector vec10(title04, title04 + N4, alloc01); + size02 = vec10.size(); + + vec09.swap(vec10); + VERIFY( vec09.size() == size02 ); + VERIFY( equal(vec09.begin(), vec09.end(), title04) ); + VERIFY( vec10.size() == size01 ); + VERIFY( equal(vec10.begin(), vec10.end(), title03) ); + + my_vector vec11(title04, title04 + N4, alloc01); + size01 = vec11.size(); + my_vector vec12(title01, title01 + N1, alloc01); + size02 = vec12.size(); + + vec11.swap(vec12); + VERIFY( vec11.size() == size02 ); + VERIFY( equal(vec11.begin(), vec11.end(), title01) ); + VERIFY( vec12.size() == size01 ); + VERIFY( equal(vec12.begin(), vec12.end(), title04) ); + + my_vector vec13(title03, title03 + N3, alloc01); + size01 = vec13.size(); + my_vector vec14(title03, title03 + N3, alloc01); + size02 = vec14.size(); + + vec13.swap(vec14); + VERIFY( vec13.size() == size02 ); + VERIFY( equal(vec13.begin(), vec13.end(), title03) ); + VERIFY( vec14.size() == size01 ); + VERIFY( equal(vec14.begin(), vec14.end(), title03) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/3.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/3.cc new file mode 100644 index 00000000000..7f1acdc645a --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/3.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. + +// 23.2.4.3 vector::swap + +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +// uneq_allocator, two different personalities. +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef __gnu_test::uneq_allocator<char> my_alloc; + typedef vector<char, my_alloc> my_vector; + + 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); + + my_vector::size_type size01, size02; + + my_alloc alloc01(1), alloc02(2); + int personality01, personality02; + + my_vector vec01(alloc01); + size01 = vec01.size(); + personality01 = vec01.get_allocator().get_personality(); + my_vector vec02(alloc02); + size02 = vec02.size(); + personality02 = vec02.get_allocator().get_personality(); + + vec01.swap(vec02); + VERIFY( vec01.size() == size02 ); + VERIFY( vec01.empty() ); + VERIFY( vec02.size() == size01 ); + VERIFY( vec02.empty() ); + VERIFY( vec01.get_allocator().get_personality() == personality02 ); + VERIFY( vec02.get_allocator().get_personality() == personality01 ); + + my_vector vec03(alloc02); + size01 = vec03.size(); + personality01 = vec03.get_allocator().get_personality(); + my_vector vec04(title02, title02 + N2, alloc01); + size02 = vec04.size(); + personality02 = vec04.get_allocator().get_personality(); + + vec03.swap(vec04); + VERIFY( vec03.size() == size02 ); + VERIFY( equal(vec03.begin(), vec03.end(), title02) ); + VERIFY( vec04.size() == size01 ); + VERIFY( vec04.empty() ); + VERIFY( vec03.get_allocator().get_personality() == personality02 ); + VERIFY( vec04.get_allocator().get_personality() == personality01 ); + + my_vector vec05(title01, title01 + N1, alloc01); + size01 = vec05.size(); + personality01 = vec05.get_allocator().get_personality(); + my_vector vec06(title02, title02 + N2, alloc02); + size02 = vec06.size(); + personality02 = vec06.get_allocator().get_personality(); + + vec05.swap(vec06); + VERIFY( vec05.size() == size02 ); + VERIFY( equal(vec05.begin(), vec05.end(), title02) ); + VERIFY( vec06.size() == size01 ); + VERIFY( equal(vec06.begin(), vec06.end(), title01) ); + VERIFY( vec05.get_allocator().get_personality() == personality02 ); + VERIFY( vec06.get_allocator().get_personality() == personality01 ); + + my_vector vec07(title01, title01 + N1, alloc02); + size01 = vec07.size(); + personality01 = vec07.get_allocator().get_personality(); + my_vector vec08(title03, title03 + N3, alloc01); + size02 = vec08.size(); + personality02 = vec08.get_allocator().get_personality(); + + vec07.swap(vec08); + VERIFY( vec07.size() == size02 ); + VERIFY( equal(vec07.begin(), vec07.end(), title03) ); + VERIFY( vec08.size() == size01 ); + VERIFY( equal(vec08.begin(), vec08.end(), title01) ); + VERIFY( vec07.get_allocator().get_personality() == personality02 ); + VERIFY( vec08.get_allocator().get_personality() == personality01 ); + + my_vector vec09(title03, title03 + N3, alloc01); + size01 = vec09.size(); + personality01 = vec09.get_allocator().get_personality(); + my_vector vec10(title04, title04 + N4, alloc02); + size02 = vec10.size(); + personality02 = vec10.get_allocator().get_personality(); + + vec09.swap(vec10); + VERIFY( vec09.size() == size02 ); + VERIFY( equal(vec09.begin(), vec09.end(), title04) ); + VERIFY( vec10.size() == size01 ); + VERIFY( equal(vec10.begin(), vec10.end(), title03) ); + VERIFY( vec09.get_allocator().get_personality() == personality02 ); + VERIFY( vec10.get_allocator().get_personality() == personality01 ); + + my_vector vec11(title04, title04 + N4, alloc02); + size01 = vec11.size(); + personality01 = vec11.get_allocator().get_personality(); + my_vector vec12(title01, title01 + N1, alloc01); + size02 = vec12.size(); + personality02 = vec12.get_allocator().get_personality(); + + vec11.swap(vec12); + VERIFY( vec11.size() == size02 ); + VERIFY( equal(vec11.begin(), vec11.end(), title01) ); + VERIFY( vec12.size() == size01 ); + VERIFY( equal(vec12.begin(), vec12.end(), title04) ); + VERIFY( vec11.get_allocator().get_personality() == personality02 ); + VERIFY( vec12.get_allocator().get_personality() == personality01 ); + + my_vector vec13(title03, title03 + N3, alloc01); + size01 = vec13.size(); + personality01 = vec13.get_allocator().get_personality(); + my_vector vec14(title03, title03 + N3, alloc02); + size02 = vec14.size(); + personality02 = vec14.get_allocator().get_personality(); + + vec13.swap(vec14); + VERIFY( vec13.size() == size02 ); + VERIFY( equal(vec13.begin(), vec13.end(), title03) ); + VERIFY( vec14.size() == size01 ); + VERIFY( equal(vec14.begin(), vec14.end(), title03) ); + VERIFY( vec13.get_allocator().get_personality() == personality02 ); + VERIFY( vec14.get_allocator().get_personality() == personality01 ); +} + +int main() +{ + test01(); + return 0; +} 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; +} |