summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/23_containers/deque/modifiers/erase
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /libstdc++-v3/testsuite/23_containers/deque/modifiers/erase
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'libstdc++-v3/testsuite/23_containers/deque/modifiers/erase')
-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
5 files changed, 402 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;
+}