summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/23_containers/deque/modifiers
diff options
context:
space:
mode:
Diffstat (limited to 'libstdc++-v3/testsuite/23_containers/deque/modifiers')
-rw-r--r--libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/1.cc135
-rw-r--r--libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/2.cc114
-rw-r--r--libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/3.cc53
-rw-r--r--libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/50529.cc38
-rw-r--r--libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/moveable.cc62
-rw-r--r--libstdc++-v3/testsuite/23_containers/deque/modifiers/moveable.cc134
-rw-r--r--libstdc++-v3/testsuite/23_containers/deque/modifiers/swap/1.cc62
-rw-r--r--libstdc++-v3/testsuite/23_containers/deque/modifiers/swap/2.cc132
-rw-r--r--libstdc++-v3/testsuite/23_containers/deque/modifiers/swap/3.cc161
9 files changed, 891 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/1.cc b/libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/1.cc
new file mode 100644
index 000000000..2da37a9f0
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/1.cc
@@ -0,0 +1,135 @@
+// 2005-11-25 Paolo Carlini <pcarlini@suse.de>
+
+// Copyright (C) 2005, 2006, 2007, 2009 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 3, 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 23.2.1.3 deque modifiers
+
+#include <deque>
+#include <testsuite_hooks.h>
+
+const int A[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
+const int A1[] = {0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
+const int A2[] = {0, 2, 3, 4, 10, 11, 12, 13, 14, 15};
+const int A3[] = {0, 2, 3, 4, 10, 11};
+const int A4[] = {4, 10, 11};
+const int A5[] = {4, 10};
+const unsigned N = sizeof(A) / sizeof(int);
+const unsigned N1 = sizeof(A1) / sizeof(int);
+const unsigned N2 = sizeof(A2) / sizeof(int);
+const unsigned N3 = sizeof(A3) / sizeof(int);
+const unsigned N4 = sizeof(A4) / sizeof(int);
+const unsigned N5 = sizeof(A5) / sizeof(int);
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ typedef std::deque<int> deque_type;
+ typedef deque_type::iterator iterator_type;
+
+ deque_type v(A, A + N);
+
+ iterator_type it1 = v.erase(v.begin() + 1);
+ VERIFY( it1 == v.begin() + 1 );
+ VERIFY( v.size() == N1 );
+ VERIFY( std::equal(v.begin(), v.end(), A1) );
+
+ iterator_type it2 = v.erase(v.begin() + 4, v.begin() + 9);
+ VERIFY( it2 == v.begin() + 4 );
+ VERIFY( v.size() == N2 );
+ VERIFY( std::equal(v.begin(), v.end(), A2) );
+
+ iterator_type it3 = v.erase(v.begin() + 6, v.end());
+ VERIFY( it3 == v.begin() + 6 );
+ VERIFY( v.size() == N3 );
+ VERIFY( std::equal(v.begin(), v.end(), A3) );
+
+ iterator_type it4 = v.erase(v.begin(), v.begin() + 3);
+ VERIFY( it4 == v.begin() );
+ VERIFY( v.size() == N4 );
+ VERIFY( std::equal(v.begin(), v.end(), A4) );
+
+ iterator_type it5 = v.erase(v.begin() + 2);
+ VERIFY( it5 == v.begin() + 2 );
+ VERIFY( v.size() == N5 );
+ VERIFY( std::equal(v.begin(), v.end(), A5) );
+
+ iterator_type it6 = v.erase(v.begin(), v.end());
+ VERIFY( it6 == v.begin() );
+ VERIFY( v.empty() );
+}
+
+void
+test02()
+{
+ bool test __attribute__((unused)) = true;
+
+ typedef std::deque<std::deque<int> > deque_type;
+ typedef deque_type::iterator iterator_type;
+
+ deque_type v, v1, v2, v3, v4, v5;
+ for (unsigned i = 0; i < N; ++i)
+ v.push_back(std::deque<int>(1, A[i]));
+ for (unsigned i = 0; i < N1; ++i)
+ v1.push_back(std::deque<int>(1, A1[i]));
+ for (unsigned i = 0; i < N2; ++i)
+ v2.push_back(std::deque<int>(1, A2[i]));
+ for (unsigned i = 0; i < N3; ++i)
+ v3.push_back(std::deque<int>(1, A3[i]));
+ for (unsigned i = 0; i < N4; ++i)
+ v4.push_back(std::deque<int>(1, A4[i]));
+ for (unsigned i = 0; i < N5; ++i)
+ v5.push_back(std::deque<int>(1, A5[i]));
+
+ iterator_type it1 = v.erase(v.begin() + 1);
+ VERIFY( it1 == v.begin() + 1 );
+ VERIFY( v.size() == N1 );
+ VERIFY( std::equal(v.begin(), v.end(), v1.begin()) );
+
+ iterator_type it2 = v.erase(v.begin() + 4, v.begin() + 9);
+ VERIFY( it2 == v.begin() + 4 );
+ VERIFY( v.size() == N2 );
+ VERIFY( std::equal(v.begin(), v.end(), v2.begin()) );
+
+ iterator_type it3 = v.erase(v.begin() + 6, v.end());
+ VERIFY( it3 == v.begin() + 6 );
+ VERIFY( v.size() == N3 );
+ VERIFY( std::equal(v.begin(), v.end(), v3.begin()) );
+
+ iterator_type it4 = v.erase(v.begin(), v.begin() + 3);
+ VERIFY( it4 == v.begin() );
+ VERIFY( v.size() == N4 );
+ VERIFY( std::equal(v.begin(), v.end(), v4.begin()) );
+
+ iterator_type it5 = v.erase(v.begin() + 2);
+ VERIFY( it5 == v.begin() + 2 );
+ VERIFY( v.size() == N5 );
+ VERIFY( std::equal(v.begin(), v.end(), v5.begin()) );
+
+ iterator_type it6 = v.erase(v.begin(), v.end());
+ VERIFY( it6 == v.begin() );
+ VERIFY( v.empty() );
+}
+
+int main()
+{
+ test01();
+ test02();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/2.cc b/libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/2.cc
new file mode 100644
index 000000000..2d592d7b4
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/2.cc
@@ -0,0 +1,114 @@
+// 2005-11-25 Paolo Carlini <pcarlini@suse.de>
+
+// Copyright (C) 2005, 2006, 2007, 2009 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 3, 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 23.2.1.3 deque modifiers
+
+#include <deque>
+#include <testsuite_hooks.h>
+
+const int A[] = {-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
+ 13, 14, 15};
+const int A0[] = {-5, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
+const int A1[] = {-5, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
+const int A2[] = {-5, 0, 1, 2, 8, 9, 10, 11, 12, 13, 14, 15};
+const int A3[] = {-5, 0, 1, 2, 8, 9, 10, 11};
+const int A4[] = {2, 8, 9, 10, 11};
+const int A5[] = {2, 8, 10, 11};
+const int A6[] = {2, 8, 10};
+const unsigned N = sizeof(A) / sizeof(int);
+const unsigned N0 = sizeof(A0) / sizeof(int);
+const unsigned N1 = sizeof(A1) / sizeof(int);
+const unsigned N2 = sizeof(A2) / sizeof(int);
+const unsigned N3 = sizeof(A3) / sizeof(int);
+const unsigned N4 = sizeof(A4) / sizeof(int);
+const unsigned N5 = sizeof(A5) / sizeof(int);
+const unsigned N6 = sizeof(A6) / sizeof(int);
+
+template<int Size>
+ class My_class
+ {
+ double dummy[Size];
+ int data;
+
+ public:
+ My_class(int num)
+ : data(num) { }
+
+ operator int() const
+ { return data; }
+ };
+
+template<typename T>
+ void
+ test01()
+ {
+ bool test __attribute__((unused)) = true;
+
+ typedef std::deque<T> deque_type;
+ typedef typename deque_type::iterator iterator_type;
+
+ deque_type v(A, A + N);
+
+ iterator_type it0 = v.erase(v.begin() + 1, v.begin() + 4);
+ VERIFY( it0 == v.begin() + 1 );
+ VERIFY( v.size() == N0 );
+ VERIFY( std::equal(v.begin(), v.end(), A0) );
+
+ iterator_type it1 = v.erase(v.begin() + 1);
+ VERIFY( it1 == v.begin() + 1 );
+ VERIFY( v.size() == N1 );
+ VERIFY( std::equal(v.begin(), v.end(), A1) );
+
+ iterator_type it2 = v.erase(v.begin() + 4, v.begin() + 9);
+ VERIFY( it2 == v.begin() + 4 );
+ VERIFY( v.size() == N2 );
+ VERIFY( std::equal(v.begin(), v.end(), A2) );
+
+ iterator_type it3 = v.erase(v.begin() + 8, v.end());
+ VERIFY( it3 == v.begin() + 8 );
+ VERIFY( v.size() == N3 );
+ VERIFY( std::equal(v.begin(), v.end(), A3) );
+
+ iterator_type it4 = v.erase(v.begin(), v.begin() + 3);
+ VERIFY( it4 == v.begin() );
+ VERIFY( v.size() == N4 );
+ VERIFY( std::equal(v.begin(), v.end(), A4) );
+
+ iterator_type it5 = v.erase(v.begin() + 2);
+ VERIFY( it5 == v.begin() + 2 );
+ VERIFY( v.size() == N5 );
+ VERIFY( std::equal(v.begin(), v.end(), A5) );
+
+ iterator_type it6 = v.erase(v.begin() + 3, v.end());
+ VERIFY( it6 == v.begin() + 3 );
+ VERIFY( v.size() == N6 );
+ VERIFY( std::equal(v.begin(), v.end(), A6) );
+
+ iterator_type it7 = v.erase(v.begin(), v.end());
+ VERIFY( it7 == v.begin() );
+ VERIFY( v.empty() );
+ }
+
+int main()
+{
+ test01<My_class<1> >();
+ test01<My_class<8> >();
+ test01<My_class<32> >();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/3.cc b/libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/3.cc
new file mode 100644
index 000000000..79a046ed7
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/3.cc
@@ -0,0 +1,53 @@
+// Copyright (C) 2007, 2009, 2010, 2011 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 3, 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 23.2.1.3 deque modifiers
+
+#include <deque>
+#include <testsuite_hooks.h>
+
+void erase(size_t num_elm, size_t elm_strt, size_t elm_end)
+{
+ bool test __attribute__((unused)) = true;
+ using __gnu_test::copy_tracker;
+ using __gnu_test::assignment_operator;
+
+ std::deque<copy_tracker> x(num_elm);
+ copy_tracker::reset();
+
+ x.erase(x.begin() + elm_strt, x.begin() + elm_end);
+
+ const size_t min_num_cpy
+ = elm_strt == elm_end ? 0 : std::min(elm_strt, num_elm - elm_end);
+
+ VERIFY( assignment_operator::count() == min_num_cpy );
+}
+
+// http://gcc.gnu.org/ml/libstdc++/2007-01/msg00098.html
+void test01()
+{
+ for (size_t num_elm = 0; num_elm <= 10; ++num_elm)
+ for (size_t elm_strt = 0; elm_strt <= num_elm; ++elm_strt)
+ for (size_t elm_end = elm_strt; elm_end <= num_elm; ++elm_end)
+ erase(num_elm, elm_strt, elm_end);
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/50529.cc b/libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/50529.cc
new file mode 100644
index 000000000..f534758a9
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/50529.cc
@@ -0,0 +1,38 @@
+// { dg-options "-std=gnu++0x" }
+
+// 2011-09-26 Paolo Carlini <paolo.carlini@oracle.com>
+
+// Copyright (C) 2011 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 3, 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <deque>
+#include <testsuite_rvalref.h>
+
+// libstdc++/50529
+void test01()
+{
+ std::deque<__gnu_test::rvalstruct> d(10);
+
+ for (auto it = d.begin(); it != d.end(); ++it)
+ d.erase(it, it);
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/moveable.cc b/libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/moveable.cc
new file mode 100644
index 000000000..e631000f6
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/deque/modifiers/erase/moveable.cc
@@ -0,0 +1,62 @@
+// { dg-options "-std=gnu++0x" }
+
+// 2007-10-28 Paolo Carlini <pcarlini@suse.de>
+
+// Copyright (C) 2007, 2009 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 3, 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <deque>
+#include <testsuite_hooks.h>
+#include <testsuite_rvalref.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+ using namespace __gnu_test;
+
+ std::deque<copycounter> a(40);
+ copycounter::copycount = 0;
+
+ a.erase(a.begin() + 20);
+ VERIFY( copycounter::copycount == 0 );
+
+ a.erase(a.begin());
+ VERIFY( copycounter::copycount == 0 );
+
+ a.erase(a.end() - 1);
+ VERIFY( copycounter::copycount == 0 );
+
+ a.erase(a.begin() + 10, a.end() - 10);
+ VERIFY( copycounter::copycount == 0 );
+
+ a.erase(a.begin(), a.begin() + 5);
+ VERIFY( copycounter::copycount == 0 );
+
+ a.erase(a.end() - 5, a.end());
+ VERIFY( copycounter::copycount == 0 );
+
+ a.erase(a.begin(), a.end());
+ VERIFY( copycounter::copycount == 0 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/deque/modifiers/moveable.cc b/libstdc++-v3/testsuite/23_containers/deque/modifiers/moveable.cc
new file mode 100644
index 000000000..6519600fb
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/deque/modifiers/moveable.cc
@@ -0,0 +1,134 @@
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2005, 2007, 2009 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 3, 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <deque>
+#include <testsuite_hooks.h>
+#include <testsuite_rvalref.h>
+
+using namespace __gnu_test;
+
+// Test deque::push_back makes no unneeded copies.
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::deque<copycounter> a;
+ copycounter c(1);
+ copycounter::copycount = 0;
+ for(int i = 0; i < 1000; ++i)
+ a.push_back(c);
+ VERIFY(copycounter::copycount == 1000);
+}
+
+// Test deque::push_front makes no unneeded copies.
+void
+test02()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::deque<copycounter> a;
+ copycounter c(1);
+ copycounter::copycount = 0;
+ for(int i = 0; i < 1000; ++i)
+ a.push_front(c);
+ VERIFY(copycounter::copycount == 1000);
+}
+
+// Test deque::insert makes no unneeded copies.
+void
+test03()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::deque<copycounter> a(1000);
+ copycounter c(1);
+ copycounter::copycount = 0;
+ a.insert(a.begin(),c);
+ a.insert(a.end(),c);
+ for(int i = 0; i < 500; ++i)
+ a.insert(a.begin() + i, c);
+ VERIFY(copycounter::copycount == 502);
+}
+
+// Test deque::insert(iterator, count, value) makes no unneeded copies
+// when it has to also reallocate the deque's internal buffer.
+void
+test04()
+{
+ bool test __attribute__((unused)) = true;
+
+ copycounter c(1);
+ std::deque<copycounter> a(10, c);
+ copycounter::copycount = 0;
+ a.insert(a.begin(), 20, c);
+ VERIFY(copycounter::copycount == 20);
+ a.insert(a.end(), 50, c);
+ VERIFY(copycounter::copycount == 70);
+ // NOTE : These values are each one higher than might be expected, as
+ // deque::insert(iterator, count, value) copies the value it is given
+ // when it has to move elements in the deque in case that value is
+ // in the deque.
+
+ // Near the start
+ a.insert(a.begin() + 10, 100, c);
+ VERIFY(copycounter::copycount == 170 + 1);
+ // Near the end
+ a.insert(a.end() - 10, 1000, c);
+ VERIFY(copycounter::copycount == 1170 + 2);
+}
+
+// Test deque::insert(iterator, count, value) makes no unneeded copies
+// when it doesn't have to reallocate the deque's internal buffer.
+void
+test05()
+{
+ bool test __attribute__((unused)) = true;
+
+ copycounter c(1);
+ std::deque<copycounter> a(10, c);
+ copycounter::copycount = 0;
+ //a.reserve(1000);
+ a.insert(a.begin(), 20, c);
+ VERIFY(copycounter::copycount == 20 );
+ a.insert(a.end(), 50, c);
+ VERIFY(copycounter::copycount == 70 );
+
+ // NOTE : These values are each one higher than might be expected, as
+ // deque::insert(iterator, count, value) copies the value it is given
+ // when it has to move elements in the deque in case that value is
+ // in the deque.
+ // Near the start
+ a.insert(a.begin() + 10, 100, c);
+ VERIFY(copycounter::copycount == 170 + 1);
+ // Near the end
+ a.insert(a.end() - 10, 200, c);
+ VERIFY(copycounter::copycount == 370 + 2);
+}
+
+int main()
+{
+ test01();
+ test02();
+ test03();
+ test04();
+ test05();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/deque/modifiers/swap/1.cc b/libstdc++-v3/testsuite/23_containers/deque/modifiers/swap/1.cc
new file mode 100644
index 000000000..3b176c869
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/deque/modifiers/swap/1.cc
@@ -0,0 +1,62 @@
+// Copyright (C) 2004, 2005, 2009 Free Software Foundation
+//
+// 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 3, 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <deque>
+#include <testsuite_hooks.h>
+
+struct T { int i; };
+
+int swap_calls;
+
+namespace std
+{
+ template<>
+ void
+ deque<T, allocator<T> >::swap(deque<T, allocator<T> >&)
+ { ++swap_calls; }
+}
+
+// Should use deque specialization for swap.
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ std::deque<T> A;
+ std::deque<T> B;
+ swap_calls = 0;
+ std::swap(A, B);
+ VERIFY(1 == swap_calls);
+}
+
+// Should use deque specialization for swap.
+void test02()
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+ deque<T> A;
+ deque<T> B;
+ swap_calls = 0;
+ swap(A, B);
+ VERIFY(1 == swap_calls);
+}
+
+// See c++/13658 for background info.
+int main()
+{
+ test01();
+ test02();
+ return 0;
+}
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 000000000..5721e2a53
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/deque/modifiers/swap/2.cc
@@ -0,0 +1,132 @@
+// 2005-12-20 Paolo Carlini <pcarlini@suse.de>
+
+// Copyright (C) 2005, 2009 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 3, 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 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 000000000..e4e1cba7e
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/deque/modifiers/swap/3.cc
@@ -0,0 +1,161 @@
+// 2005-12-20 Paolo Carlini <pcarlini@suse.de>
+
+// Copyright (C) 2005, 2009 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 3, 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 COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 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;
+}