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 @@
Have open
clear the error flags.
+ 431:
+ Swapping containers with unequal allocators
+
+ Implement Option 3, as per N1599.
+
+
434:
bitset::to_string() hard to use
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::__value>
+ struct __alloc_swap
+ { static void _S_do_it(_Alloc&, _Alloc&) { } };
+
+ template
+ 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::
+ _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_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::_S_do_it(_M_get_allocator(),
+ __rcs._M_get_allocator());
}
template
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
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
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::__value>
+ // (http://www.cantrip.org/emptyopt.html).
+ template
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.
- };
-
- template
- struct _Alloc_hider<_Alloc1, true>
- : 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 // For std::pair
+#include
#include
#include
#include
@@ -1443,8 +1444,11 @@ _GLIBCXX_BEGIN_NAMESPACE(tr1)
// have different members.
Internal::hash_code_base::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::_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
#include
-#include
-#include
-#include
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
#include
-#include
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
similarity index 100%
rename from libstdc++-v3/testsuite/23_containers/deque/modifiers/swap.cc
rename to 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
+
+// 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
+#include
+#include
+
+// uneq_allocator as a non-empty allocator.
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+
+ typedef __gnu_test::uneq_allocator my_alloc;
+ typedef deque 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
+
+// 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
+#include
+#include
+
+// uneq_allocator, two different personalities.
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+
+ typedef __gnu_test::uneq_allocator my_alloc;
+ typedef deque 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
similarity index 100%
rename from libstdc++-v3/testsuite/23_containers/list/modifiers/swap.cc
rename to 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
+
+// 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
+#include
+#include
+
+// uneq_allocator as a non-empty allocator.
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+
+ typedef __gnu_test::uneq_allocator my_alloc;
+ typedef list 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
+
+// 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
+#include
+#include
+
+// uneq_allocator, two different personalities.
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+
+ typedef __gnu_test::uneq_allocator my_alloc;
+ typedef list 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
similarity index 100%
rename from libstdc++-v3/testsuite/23_containers/map/modifiers/swap.cc
rename to 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
+
+// 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