+2008-04-24 Paolo Carlini <pcarlini@suse.de>
+
+ PR libstdc++/35969
+ * include/debug/list (merge): Use _M_transfer_iter, consistently
+ with the splice members.
+ * testsuite/23_containers/list/operations/35969.cc: New.
+
+ * testsuite/23_containers/list/operators: Rename to
+ testsuite/23_containers/list/operations.
+
2008-04-24 Benjamin Kosnik <bkoz@redhat.com>
* acinclude.m4 (GLIBCXX_ENABLE_ATOMIC_BUILTINS): Check for set of
// Debugging list implementation -*- C++ -*-
-// Copyright (C) 2003, 2004, 2005, 2006, 2007
+// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
merge(list& __x)
#endif
{
- __glibcxx_check_sorted(_Base::begin(), _Base::end());
- __glibcxx_check_sorted(__x.begin().base(), __x.end().base());
- for (iterator __tmp = __x.begin(); __tmp != __x.end(); )
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
+ // 300. list::merge() specification incomplete
+ if (this != &__x)
{
- iterator __victim = __tmp++;
- __victim._M_attach(&__x);
+ __glibcxx_check_sorted(_Base::begin(), _Base::end());
+ __glibcxx_check_sorted(__x.begin().base(), __x.end().base());
+ for (iterator __tmp = __x.begin(); __tmp != __x.end();)
+ {
+ iterator __victim = __tmp++;
+ this->_M_transfer_iter(__victim);
+ }
+ _Base::merge(_GLIBCXX_MOVE(__x._M_base()));
}
- _Base::merge(_GLIBCXX_MOVE(__x._M_base()));
}
template<class _Compare>
merge(list& __x, _Compare __comp)
#endif
{
- __glibcxx_check_sorted_pred(_Base::begin(), _Base::end(), __comp);
- __glibcxx_check_sorted_pred(__x.begin().base(), __x.end().base(),
- __comp);
- for (iterator __tmp = __x.begin(); __tmp != __x.end(); )
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
+ // 300. list::merge() specification incomplete
+ if (this != &__x)
{
- iterator __victim = __tmp++;
- __victim._M_attach(&__x);
+ __glibcxx_check_sorted_pred(_Base::begin(), _Base::end(),
+ __comp);
+ __glibcxx_check_sorted_pred(__x.begin().base(), __x.end().base(),
+ __comp);
+ for (iterator __tmp = __x.begin(); __tmp != __x.end();)
+ {
+ iterator __victim = __tmp++;
+ this->_M_transfer_iter(__victim);
+ }
+ _Base::merge(_GLIBCXX_MOVE(__x._M_base()), __comp);
}
- _Base::merge(_GLIBCXX_MOVE(__x._M_base()), __comp);
}
void
--- /dev/null
+// Copyright (C) 2001, 2004, 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 Pred 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 23.2.2.4 list operations [lib.list.ops]
+
+#include <list>
+#include <testsuite_hooks.h>
+
+bool test __attribute__((unused)) = true;
+
+// splice(p, x) + remove + reverse
+void
+test01()
+{
+ const int K = 417;
+ const int A[] = {1, 2, 3, 4, 5};
+ const int B[] = {K, K, K, K, K};
+ const std::size_t N = sizeof(A) / sizeof(int);
+ const std::size_t M = sizeof(B) / sizeof(int);
+
+ std::list<int> list0101(A, A + N);
+ std::list<int> list0102(B, B + M);
+ std::list<int>::iterator p = list0101.begin();
+
+ VERIFY(list0101.size() == N);
+ VERIFY(list0102.size() == M);
+
+ ++p;
+ list0101.splice(p, list0102); // [1 K K K K K 2 3 4 5]
+ VERIFY(list0101.size() == N + M);
+ VERIFY(list0102.size() == 0);
+
+ // remove range from middle
+ list0101.remove(K);
+ VERIFY(list0101.size() == N);
+
+ // remove first element
+ list0101.remove(1);
+ VERIFY(list0101.size() == N - 1);
+
+ // remove last element
+ list0101.remove(5);
+ VERIFY(list0101.size() == N - 2);
+
+ // reverse
+ list0101.reverse();
+ p = list0101.begin();
+ VERIFY(*p == 4); ++p;
+ VERIFY(*p == 3); ++p;
+ VERIFY(*p == 2); ++p;
+ VERIFY(p == list0101.end());
+}
+
+int main(void)
+{
+ test01();
+ return 0;
+}
+
--- /dev/null
+// Copyright (C) 2001, 2004, 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 Pred 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 23.2.2.4 list operations [lib.list.ops]
+
+#include <list>
+#include <testsuite_hooks.h>
+
+bool test __attribute__((unused)) = true;
+
+// splice(p, x, i) + remove_if + operator==
+void
+test02()
+{
+ const int A[] = {1, 2, 3, 4, 5};
+ const int B[] = {2, 1, 3, 4, 5};
+ const int C[] = {1, 3, 4, 5, 2};
+ const int N = sizeof(A) / sizeof(int);
+ std::list<int> list0201(A, A + N);
+ std::list<int> list0202(A, A + N);
+ std::list<int> list0203(B, B + N);
+ std::list<int> list0204(C, C + N);
+ std::list<int>::iterator i = list0201.begin();
+
+ // result should be unchanged
+ list0201.splice(list0201.begin(), list0201, i);
+ VERIFY(list0201 == list0202);
+
+ // result should be [2 1 3 4 5]
+ ++i;
+ list0201.splice(list0201.begin(), list0201, i);
+ VERIFY(list0201 != list0202);
+ VERIFY(list0201 == list0203);
+
+ // result should be [1 3 4 5 2]
+ list0201.splice(list0201.end(), list0201, i);
+ VERIFY(list0201 == list0204);
+}
+
+int main()
+{
+ test02();
+ return 0;
+}
--- /dev/null
+// Copyright (C) 2001, 2004, 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 Pred 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 23.2.2.4 list operations [lib.list.ops]
+
+#include <list>
+#include <testsuite_hooks.h>
+
+bool test __attribute__((unused)) = true;
+
+// splice(p, x, f, l) + sort + merge + unique
+void
+test03()
+{
+ const int A[] = {103, 203, 603, 303, 403, 503};
+ const int B[] = {417, 417, 417, 417, 417};
+ const int E[] = {103, 417, 417, 203, 603, 303, 403, 503};
+ const int F[] = {103, 203, 303, 403, 417, 417, 503, 603};
+ const int C[] = {103, 203, 303, 403, 417, 417, 417, 417, 417, 503, 603};
+ const int D[] = {103, 203, 303, 403, 417, 503, 603};
+ const int N = sizeof(A) / sizeof(int);
+ const int M = sizeof(B) / sizeof(int);
+ const int P = sizeof(C) / sizeof(int);
+ const int Q = sizeof(D) / sizeof(int);
+ const int R = sizeof(E) / sizeof(int);
+
+ std::list<int> list0301(A, A + N);
+ std::list<int> list0302(B, B + M);
+ std::list<int> list0303(C, C + P);
+ std::list<int> list0304(D, D + Q);
+ std::list<int> list0305(E, E + R);
+ std::list<int> list0306(F, F + R);
+ std::list<int>::iterator p = list0301.begin();
+ std::list<int>::iterator q = list0302.begin();
+
+ ++p; ++q; ++q;
+ list0301.splice(p, list0302, list0302.begin(), q);
+ VERIFY(list0301 == list0305);
+ VERIFY(list0301.size() == N + 2);
+ VERIFY(list0302.size() == M - 2);
+
+ list0301.sort();
+ VERIFY(list0301 == list0306);
+
+ list0301.merge(list0302);
+ VERIFY(list0301.size() == N + M);
+ VERIFY(list0302.size() == 0);
+ VERIFY(list0301 == list0303);
+
+ list0301.unique();
+ VERIFY(list0301 == list0304);
+}
+
+int main(void)
+{
+ test03();
+ return 0;
+}
--- /dev/null
+// Copyright (C) 2008 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 23.2.2.4 list operations [lib.list.ops]
+
+// { dg-options "-D_GLIBCXX_DEBUG" }
+
+#include <list>
+#include <functional>
+
+// libstdc++/35969
+void test01()
+{
+ {
+ std::list<int> list1;
+ std::list<int> list2;
+
+ for(int i = 0; i < 10; ++i)
+ {
+ list1.push_back(i);
+ list2.push_back(10 - i);
+ }
+
+ list1.sort();
+ list2.sort();
+
+ std::list<int>::iterator node_of_interest = list2.begin();
+
+ list1.splice(list1.begin(), list2, node_of_interest);
+ list2.splice(list2.begin(), list1, node_of_interest);
+
+ list1.merge(list2);
+
+ list2.splice(list2.begin(), list1, node_of_interest);
+ }
+
+ {
+ std::list<int> list1;
+ std::list<int> list2;
+
+ for(int i = 0; i < 10; ++i)
+ {
+ list1.push_back(i);
+ list2.push_back(10 - i);
+ }
+
+ list1.sort();
+ list2.sort();
+
+ std::list<int>::iterator node_of_interest = list2.begin();
+
+ list1.splice(list1.begin(), list2, node_of_interest);
+ list2.splice(list2.begin(), list1, node_of_interest);
+
+ list1.merge(list2, std::less<int>());
+
+ list2.splice(list2.begin(), list1, node_of_interest);
+ }
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
--- /dev/null
+// Copyright (C) 2001, 2004, 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 Pred 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 23.2.2.4 list operations [lib.list.ops]
+
+#include <list>
+#include <testsuite_hooks.h>
+
+bool test __attribute__((unused)) = true;
+
+// A comparison predicate to order by rightmost digit. Tracks call counts for
+// performance checks.
+struct CompLastLt
+{
+ bool operator()(const int x, const int y)
+ { ++itsCount; return x % 10 < y % 10; }
+ static int count() { return itsCount; }
+ static void reset() { itsCount = 0; }
+ static int itsCount;
+};
+
+int CompLastLt::itsCount;
+
+struct CompLastEq
+{
+ bool operator()(const int x, const int y)
+ { ++itsCount; return x % 10 == y % 10; }
+ static int count() { return itsCount; }
+ static void reset() { itsCount = 0; }
+ static int itsCount;
+};
+
+int CompLastEq::itsCount;
+
+// sort(pred) + merge(pred) + unique(pred)
+// also checks performance requirements
+void
+test04()
+{
+ const int A[] = {1, 2, 3, 4, 5, 6};
+ const int B[] = {12, 15, 13, 14, 11};
+ const int C[] = {11, 12, 13, 14, 15};
+ const int D[] = {1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6};
+ const int N = sizeof(A) / sizeof(int);
+ const int M = sizeof(B) / sizeof(int);
+ const int Q = sizeof(D) / sizeof(int);
+
+ std::list<int> list0401(A, A + N);
+ std::list<int> list0402(B, B + M);
+ std::list<int> list0403(C, C + M);
+ std::list<int> list0404(D, D + Q);
+ std::list<int> list0405(A, A + N);
+
+ // sort B
+ CompLastLt lt;
+
+ CompLastLt::reset();
+ list0402.sort(lt);
+ VERIFY(list0402 == list0403);
+
+ CompLastLt::reset();
+ list0401.merge(list0402, lt);
+ VERIFY(list0401 == list0404);
+#ifndef _GLIBCXX_DEBUG
+ VERIFY(lt.count() <= (N + M - 1));
+#endif
+
+ CompLastEq eq;
+
+ CompLastEq::reset();
+ list0401.unique(eq);
+ VERIFY(list0401 == list0405);
+#ifndef _GLIBCXX_DEBUG
+ VERIFY(eq.count() == (N + M - 1));
+#endif
+}
+
+int main()
+{
+ test04();
+ return 0;
+}
+
--- /dev/null
+// 2006-01-19 Paolo Carlini <pcarlini@suse.de>
+
+// Copyright (C) 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
+// 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 Pred 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 23.2.2.4 list operations [lib.list.ops]
+
+#include <list>
+#include <stdexcept>
+#include <testsuite_hooks.h>
+#include <testsuite_allocator.h>
+
+// Check the splice (and merge) bits of N1599.
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ typedef __gnu_test::uneq_allocator<int> my_alloc;
+ typedef std::list<int, my_alloc> my_list;
+
+ const int data1[] = {1, 2, 3, 4, 5};
+ const int data2[] = {6, 7, 8, 9, 10};
+ const size_t N1 = sizeof(data1) / sizeof(int);
+ const size_t N2 = sizeof(data2) / sizeof(int);
+
+ my_alloc alloc01(1), alloc02(2);
+
+ my_list l01(data1, data1 + N1, alloc01);
+ const my_list l01_ref = l01;
+
+ my_list l02(data2, data2 + N2, alloc02);
+ const my_list l02_ref = l02;
+
+ bool catched = false;
+
+ try
+ {
+ l01.splice(l01.begin(), l02);
+ }
+ catch(std::runtime_error&)
+ {
+ catched = true;
+ }
+ catch(...)
+ {
+ VERIFY( false );
+ }
+ VERIFY( catched );
+ VERIFY( l01 == l01_ref );
+ VERIFY( l02 == l02_ref );
+
+ catched = false;
+ try
+ {
+ l01.splice(l01.begin(), l02, l02.begin());
+ }
+ catch(std::runtime_error&)
+ {
+ catched = true;
+ }
+ catch(...)
+ {
+ VERIFY( false );
+ }
+ VERIFY( catched );
+ VERIFY( l01 == l01_ref );
+ VERIFY( l02 == l02_ref );
+
+ catched = false;
+ try
+ {
+ l01.splice(l01.begin(), l02, l02.begin(), l02.end());
+ }
+ catch(std::runtime_error&)
+ {
+ catched = true;
+ }
+ catch(...)
+ {
+ VERIFY( false );
+ }
+ VERIFY( catched );
+ VERIFY( l01 == l01_ref );
+ VERIFY( l02 == l02_ref );
+
+ catched = false;
+ try
+ {
+ l01.merge(l02);
+ }
+ catch(std::runtime_error&)
+ {
+ catched = true;
+ }
+ catch(...)
+ {
+ VERIFY( false );
+ }
+ VERIFY( catched );
+ VERIFY( l01 == l01_ref );
+ VERIFY( l02 == l02_ref );
+
+ catched = false;
+ try
+ {
+ l01.merge(l02, std::less<int>());
+ }
+ catch(std::runtime_error&)
+ {
+ catched = true;
+ }
+ catch(...)
+ {
+ VERIFY( false );
+ }
+ VERIFY( catched );
+ VERIFY( l01 == l01_ref );
+ VERIFY( l02 == l02_ref );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
+++ /dev/null
-// Copyright (C) 2001, 2004, 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 Pred 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
-// USA.
-
-// 23.2.2.4 list operations [lib.list.ops]
-
-#include <list>
-#include <testsuite_hooks.h>
-
-bool test __attribute__((unused)) = true;
-
-// splice(p, x) + remove + reverse
-void
-test01()
-{
- const int K = 417;
- const int A[] = {1, 2, 3, 4, 5};
- const int B[] = {K, K, K, K, K};
- const std::size_t N = sizeof(A) / sizeof(int);
- const std::size_t M = sizeof(B) / sizeof(int);
-
- std::list<int> list0101(A, A + N);
- std::list<int> list0102(B, B + M);
- std::list<int>::iterator p = list0101.begin();
-
- VERIFY(list0101.size() == N);
- VERIFY(list0102.size() == M);
-
- ++p;
- list0101.splice(p, list0102); // [1 K K K K K 2 3 4 5]
- VERIFY(list0101.size() == N + M);
- VERIFY(list0102.size() == 0);
-
- // remove range from middle
- list0101.remove(K);
- VERIFY(list0101.size() == N);
-
- // remove first element
- list0101.remove(1);
- VERIFY(list0101.size() == N - 1);
-
- // remove last element
- list0101.remove(5);
- VERIFY(list0101.size() == N - 2);
-
- // reverse
- list0101.reverse();
- p = list0101.begin();
- VERIFY(*p == 4); ++p;
- VERIFY(*p == 3); ++p;
- VERIFY(*p == 2); ++p;
- VERIFY(p == list0101.end());
-}
-
-int main(void)
-{
- test01();
- return 0;
-}
-
+++ /dev/null
-// Copyright (C) 2001, 2004, 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 Pred 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
-// USA.
-
-// 23.2.2.4 list operations [lib.list.ops]
-
-#include <list>
-#include <testsuite_hooks.h>
-
-bool test __attribute__((unused)) = true;
-
-// splice(p, x, i) + remove_if + operator==
-void
-test02()
-{
- const int A[] = {1, 2, 3, 4, 5};
- const int B[] = {2, 1, 3, 4, 5};
- const int C[] = {1, 3, 4, 5, 2};
- const int N = sizeof(A) / sizeof(int);
- std::list<int> list0201(A, A + N);
- std::list<int> list0202(A, A + N);
- std::list<int> list0203(B, B + N);
- std::list<int> list0204(C, C + N);
- std::list<int>::iterator i = list0201.begin();
-
- // result should be unchanged
- list0201.splice(list0201.begin(), list0201, i);
- VERIFY(list0201 == list0202);
-
- // result should be [2 1 3 4 5]
- ++i;
- list0201.splice(list0201.begin(), list0201, i);
- VERIFY(list0201 != list0202);
- VERIFY(list0201 == list0203);
-
- // result should be [1 3 4 5 2]
- list0201.splice(list0201.end(), list0201, i);
- VERIFY(list0201 == list0204);
-}
-
-int main()
-{
- test02();
- return 0;
-}
+++ /dev/null
-// Copyright (C) 2001, 2004, 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 Pred 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
-// USA.
-
-// 23.2.2.4 list operations [lib.list.ops]
-
-#include <list>
-#include <testsuite_hooks.h>
-
-bool test __attribute__((unused)) = true;
-
-// splice(p, x, f, l) + sort + merge + unique
-void
-test03()
-{
- const int A[] = {103, 203, 603, 303, 403, 503};
- const int B[] = {417, 417, 417, 417, 417};
- const int E[] = {103, 417, 417, 203, 603, 303, 403, 503};
- const int F[] = {103, 203, 303, 403, 417, 417, 503, 603};
- const int C[] = {103, 203, 303, 403, 417, 417, 417, 417, 417, 503, 603};
- const int D[] = {103, 203, 303, 403, 417, 503, 603};
- const int N = sizeof(A) / sizeof(int);
- const int M = sizeof(B) / sizeof(int);
- const int P = sizeof(C) / sizeof(int);
- const int Q = sizeof(D) / sizeof(int);
- const int R = sizeof(E) / sizeof(int);
-
- std::list<int> list0301(A, A + N);
- std::list<int> list0302(B, B + M);
- std::list<int> list0303(C, C + P);
- std::list<int> list0304(D, D + Q);
- std::list<int> list0305(E, E + R);
- std::list<int> list0306(F, F + R);
- std::list<int>::iterator p = list0301.begin();
- std::list<int>::iterator q = list0302.begin();
-
- ++p; ++q; ++q;
- list0301.splice(p, list0302, list0302.begin(), q);
- VERIFY(list0301 == list0305);
- VERIFY(list0301.size() == N + 2);
- VERIFY(list0302.size() == M - 2);
-
- list0301.sort();
- VERIFY(list0301 == list0306);
-
- list0301.merge(list0302);
- VERIFY(list0301.size() == N + M);
- VERIFY(list0302.size() == 0);
- VERIFY(list0301 == list0303);
-
- list0301.unique();
- VERIFY(list0301 == list0304);
-}
-
-int main(void)
-{
- test03();
- return 0;
-}
+++ /dev/null
-// Copyright (C) 2001, 2004, 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 Pred 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
-// USA.
-
-// 23.2.2.4 list operations [lib.list.ops]
-
-#include <list>
-#include <testsuite_hooks.h>
-
-bool test __attribute__((unused)) = true;
-
-// A comparison predicate to order by rightmost digit. Tracks call counts for
-// performance checks.
-struct CompLastLt
-{
- bool operator()(const int x, const int y)
- { ++itsCount; return x % 10 < y % 10; }
- static int count() { return itsCount; }
- static void reset() { itsCount = 0; }
- static int itsCount;
-};
-
-int CompLastLt::itsCount;
-
-struct CompLastEq
-{
- bool operator()(const int x, const int y)
- { ++itsCount; return x % 10 == y % 10; }
- static int count() { return itsCount; }
- static void reset() { itsCount = 0; }
- static int itsCount;
-};
-
-int CompLastEq::itsCount;
-
-// sort(pred) + merge(pred) + unique(pred)
-// also checks performance requirements
-void
-test04()
-{
- const int A[] = {1, 2, 3, 4, 5, 6};
- const int B[] = {12, 15, 13, 14, 11};
- const int C[] = {11, 12, 13, 14, 15};
- const int D[] = {1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6};
- const int N = sizeof(A) / sizeof(int);
- const int M = sizeof(B) / sizeof(int);
- const int Q = sizeof(D) / sizeof(int);
-
- std::list<int> list0401(A, A + N);
- std::list<int> list0402(B, B + M);
- std::list<int> list0403(C, C + M);
- std::list<int> list0404(D, D + Q);
- std::list<int> list0405(A, A + N);
-
- // sort B
- CompLastLt lt;
-
- CompLastLt::reset();
- list0402.sort(lt);
- VERIFY(list0402 == list0403);
-
- CompLastLt::reset();
- list0401.merge(list0402, lt);
- VERIFY(list0401 == list0404);
-#ifndef _GLIBCXX_DEBUG
- VERIFY(lt.count() <= (N + M - 1));
-#endif
-
- CompLastEq eq;
-
- CompLastEq::reset();
- list0401.unique(eq);
- VERIFY(list0401 == list0405);
-#ifndef _GLIBCXX_DEBUG
- VERIFY(eq.count() == (N + M - 1));
-#endif
-}
-
-int main()
-{
- test04();
- return 0;
-}
-
+++ /dev/null
-// 2006-01-19 Paolo Carlini <pcarlini@suse.de>
-
-// Copyright (C) 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
-// 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 Pred 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
-// USA.
-
-// 23.2.2.4 list operations [lib.list.ops]
-
-#include <list>
-#include <stdexcept>
-#include <testsuite_hooks.h>
-#include <testsuite_allocator.h>
-
-// Check the splice (and merge) bits of N1599.
-void
-test01()
-{
- bool test __attribute__((unused)) = true;
-
- typedef __gnu_test::uneq_allocator<int> my_alloc;
- typedef std::list<int, my_alloc> my_list;
-
- const int data1[] = {1, 2, 3, 4, 5};
- const int data2[] = {6, 7, 8, 9, 10};
- const size_t N1 = sizeof(data1) / sizeof(int);
- const size_t N2 = sizeof(data2) / sizeof(int);
-
- my_alloc alloc01(1), alloc02(2);
-
- my_list l01(data1, data1 + N1, alloc01);
- const my_list l01_ref = l01;
-
- my_list l02(data2, data2 + N2, alloc02);
- const my_list l02_ref = l02;
-
- bool catched = false;
-
- try
- {
- l01.splice(l01.begin(), l02);
- }
- catch(std::runtime_error&)
- {
- catched = true;
- }
- catch(...)
- {
- VERIFY( false );
- }
- VERIFY( catched );
- VERIFY( l01 == l01_ref );
- VERIFY( l02 == l02_ref );
-
- catched = false;
- try
- {
- l01.splice(l01.begin(), l02, l02.begin());
- }
- catch(std::runtime_error&)
- {
- catched = true;
- }
- catch(...)
- {
- VERIFY( false );
- }
- VERIFY( catched );
- VERIFY( l01 == l01_ref );
- VERIFY( l02 == l02_ref );
-
- catched = false;
- try
- {
- l01.splice(l01.begin(), l02, l02.begin(), l02.end());
- }
- catch(std::runtime_error&)
- {
- catched = true;
- }
- catch(...)
- {
- VERIFY( false );
- }
- VERIFY( catched );
- VERIFY( l01 == l01_ref );
- VERIFY( l02 == l02_ref );
-
- catched = false;
- try
- {
- l01.merge(l02);
- }
- catch(std::runtime_error&)
- {
- catched = true;
- }
- catch(...)
- {
- VERIFY( false );
- }
- VERIFY( catched );
- VERIFY( l01 == l01_ref );
- VERIFY( l02 == l02_ref );
-
- catched = false;
- try
- {
- l01.merge(l02, std::less<int>());
- }
- catch(std::runtime_error&)
- {
- catched = true;
- }
- catch(...)
- {
- VERIFY( false );
- }
- VERIFY( catched );
- VERIFY( l01 == l01_ref );
- VERIFY( l02 == l02_ref );
-}
-
-int main()
-{
- test01();
- return 0;
-}