This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[patch] Simplifying <algorithm>: Part 2
- From: Chris Jefferson <caj at cs dot york dot ac dot uk>
- To: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Sat, 29 Jan 2005 21:13:25 +0000
- Subject: [patch] Simplifying <algorithm>: Part 2
Here is part 2 of the <algorithm> simplification, this time it's stl_algo.h
I've seperated this patch into 2 parts. Firstly there is the patch to
stl_algo.h, which while large is hopefully not contraversal. Then there
is a couple of small fixes to testsuite_iterators.h that have come up,
and a big bunch of testcases for things I've changed in stl_algo.h These
aren't (yet) very deep tests, just enough to act as a sanity check that
algorithms are vaguely accepting and returning the right things.
Unfortunatly trying to read the patch to stl_algo.h is quite hard, as it
seems to confuse diff quite badly.
2005-01-29 Christopher Jefferson <chris@bubblescope.net>
* include/bits/stl_algo.h (__median, adjacent_find, search, search_n,
unique, unique_copy, partial_sort, partial_sort_copy, sort,
lower_bound, merge, inplace_merge, stable_sort, nth_element,
equal_range, binary_search, includes, set_union, set_intersection,
set_difference, set_symmetric_difference, min_element, max_element,
next_permutation, prev_permutation, find_first_of, find_end) :
Make non-predicated version call predicated version.
* include/bits/stl_algo.h (__unique_copy, __unguarded_partition,
__unguarded_linear_insert, __insertion_sort,
__unguarded_insertion_sort, __final_insertion_sort, __introsort_loop,
__merge_without_buffer, __inplace_stable_sort, __merge_sort_loop,
__chunk_insertion_sort, __merge_sort_with_buffer, __merge_backward,
__merge_adaptive, __stable_sort_adaptive, __find_end) :
Remove unused overloads.
2005-01-29 Christopher Jefferson <chris@bubblescope.net>
* testsuite/testsuite_iterators.h (random_access_iterator_wrapper::
operator--) : Fix typo.
(OutputContainer::OutputContainer) : Correct zeroing array.
(WritableObject::operator==) : Fix typo.
(WritableObject::operator=) : make operator= templated
to allow differing types to be assigned.
(WritableObject::operator++) : Fix checking if iterator is
written to multiple times.
(random_access_iterator_wrapper::operator+) : Add const.
(random_access_iterator_wrapper::operator-) : Likewise.
(random_access_iterator_wrapper::operator[]) : Add dereference.
* testsuite/ext/median.cc: New.
* testsuite/25_algorithms/adjacent_find/1.cc: New.
* testsuite/25_algorithms/adjacent_find/check_type.cc: New.
* testsuite/25_algorithms/search/1.cc: New.
* testsuite/25_algorithms/search/check_type.cc: New.
* testsuite/25_algorithms/unique_copy/1.cc: New.
* testsuite/25_algorithms/unique_copy/check_type.cc: New.
* testsuite/25_algorithms/partial_sort/1.cc: New.
* testsuite/25_algorithms/partial_sort/check_type.cc: New.
* testsuite/25_algorithms/partial_sort_copy/1.cc: New.
* testsuite/25_algorithms/partial_sort_copy/check_type.cc: New.
* testsuite/25_algorithms/lower_bound/1.cc: New.
* testsuite/25_algorithms/lower_bound/check_type.cc: New.
* testsuite/25_algorithms/upper_bound/1.cc: New.
* testsuite/25_algorithms/upper_bound/check_type.cc: New.
* testsuite/25_algorithms/merge/1.cc: New.
* testsuite/25_algorithms/merge/check_type.cc: New.
* testsuite/25_algorithms/inplace_merge/1.cc: New.
* testsuite/25_algorithms/inplace_merge/check_type.cc: New.
* testsuite/25_algorithms/stable_sort/1.cc: New.
* testsuite/25_algorithms/stable_sort/check_type.cc: New.
* testsuite/25_algorithms/nth_element/1.cc: New.
* testsuite/25_algorithms/nth_element/check_type.cc: New.
* testsuite/25_algorithms/equal_range/1.cc: New.
* testsuite/25_algorithms/equal_range/check_type.cc: New.
* testsuite/25_algorithms/binary_search/1.cc: New.
* testsuite/25_algorithms/binary_search/check_type.cc: New.
* testsuite/25_algorithms/includes/1.cc: New.
* testsuite/25_algorithms/includes/check_type.cc: New.
* testsuite/25_algorithms/set_union/1.cc: New.
* testsuite/25_algorithms/set_union/check_type.cc: New.
* testsuite/25_algorithms/set_intersection/1.cc: New.
* testsuite/25_algorithms/set_intersection/check_type.cc: New.
* testsuite/25_algorithms/set_difference/1.cc: New.
* testsuite/25_algorithms/set_difference/check_type.cc: New.
* testsuite/25_algorithms/set_symmetric_difference/1.cc: New.
* testsuite/25_algorithms/set_symmetric_difference/check_type.cc: New.
* testsuite/25_algorithms/min_element/1.cc: New.
* testsuite/25_algorithms/min_element/check_type.cc: New.
* testsuite/25_algorithms/max_element/1.cc: New.
* testsuite/25_algorithms/max_element/check_type.cc: New.
* testsuite/25_algorithms/prev_permutation/1.cc: New.
* testsuite/25_algorithms/prev_permutation/check_type.cc: New.
* testsuite/25_algorithms/next_permutation/1.cc: New.
* testsuite/25_algorithms/next_permutation/check_type.cc: New.
* testsuite/25_algorithms/find_first_of/1.cc: New.
* testsuite/25_algorithms/find_first_of/check_type.cc: New.
* testsuite/25_algorithms/find_end/1.cc: New.
* testsuite/25_algorithms/find_end/check_type.cc: New.
* testsuite/25_algorithms/equal/check_type.cc: Insert iterator type.
* testsuite/25_algorithms/lexicographical_compare/check_type.cc:
Likewise.
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/adjacent_find/1.cc libstdc++-v3.so_7/testsuite/25_algorithms/adjacent_find/1.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/adjacent_find/1.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/adjacent_find/1.cc 2005-01-29 19:16:32.000000000 +0000
@@ -0,0 +1,67 @@
+// 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.
+
+// 25.1.5 [lib.alg.adjacent_find]
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
+
+using __gnu_test::test_container;
+using __gnu_test::forward_iterator_wrapper;
+using std::adjacent_find;
+
+typedef test_container<int, forward_iterator_wrapper> Container;
+int array[] = {0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1};
+
+void
+test01()
+{
+ Container con(array, array);
+ VERIFY(adjacent_find(con.begin(), con.end()).ptr == array);
+}
+
+void
+test02()
+{
+ Container con(array, array + 1);
+ VERIFY(adjacent_find(con.begin(), con.end()).ptr == array + 1);
+}
+
+void
+test03()
+{
+ Container con(array, array + 2);
+ VERIFY(adjacent_find(con.begin(), con.end()).ptr == array);
+}
+
+void
+test04()
+{
+ Container con(array + 1, array + 10);
+ VERIFY(adjacent_find(con.begin(), con.end()).ptr == array + 10);
+}
+
+int
+main()
+{
+ test01();
+ test02();
+ test03();
+ test04();
+}
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/adjacent_find/check_type.cc libstdc++-v3.so_7/testsuite/25_algorithms/adjacent_find/check_type.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/adjacent_find/check_type.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/adjacent_find/check_type.cc 2005-01-29 19:16:44.000000000 +0000
@@ -0,0 +1,42 @@
+// 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.
+
+// 25.1.5 [lib.alg.adjacent_find]
+
+// { dg-do compile }
+
+#include <algorithm>
+#include <testsuite_iterators.h>
+
+using __gnu_test::forward_iterator_wrapper;
+
+struct S { };
+
+bool operator==(const S&, const S&) {return true;}
+
+struct X { };
+
+bool predicate(const X&, const X&) {return true;}
+
+forward_iterator_wrapper<S>
+test1(forward_iterator_wrapper<S>& s)
+{ return std::adjacent_find(s, s); }
+
+forward_iterator_wrapper<X>
+test2(forward_iterator_wrapper<X>& x)
+{ return std::adjacent_find(x, x, predicate); }
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/binary_search/1.cc libstdc++-v3.so_7/testsuite/25_algorithms/binary_search/1.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/binary_search/1.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/binary_search/1.cc 2005-01-29 16:30:11.000000000 +0000
@@ -0,0 +1,54 @@
+// 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.
+
+// 25.3.3.4 [lib.binary.search]
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
+
+using __gnu_test::test_container;
+using __gnu_test::forward_iterator_wrapper;
+using std::binary_search;
+
+typedef test_container<int, forward_iterator_wrapper> Container;
+
+void
+test1()
+{
+ int array[] = {0};
+ Container con(array, array);
+ VERIFY(!binary_search(con.begin(), con.end(), 1));
+}
+
+void
+test2()
+{
+ int array[] = {0, 2, 4, 6, 8};
+ Container con(array, array + 5);
+ for(int i = 0; i < 10; i += 2)
+ VERIFY(binary_search(con.begin(), con.end(), i));
+ for(int i = -1; i < 11; i += 2)
+ VERIFY(!binary_search(con.begin(), con.end(), i));
+}
+
+int main()
+{
+ test1();
+ test2();
+}
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/binary_search/check_type.cc libstdc++-v3.so_7/testsuite/25_algorithms/binary_search/check_type.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/binary_search/check_type.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/binary_search/check_type.cc 2005-01-29 19:17:04.000000000 +0000
@@ -0,0 +1,42 @@
+// 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.
+
+// 25.3.3.4 [lib.binary.search]
+
+// { dg-do compile }
+
+#include <algorithm>
+#include <testsuite_iterators.h>
+
+using __gnu_test::forward_iterator_wrapper;
+
+struct S { };
+
+bool operator<(const S&, const S&) {return true;}
+
+struct X { };
+
+bool predicate(const X&, const X&) {return true;}
+
+bool
+test1(forward_iterator_wrapper<S>& s)
+{ return std::binary_search(s, s, *s); }
+
+bool
+test2(forward_iterator_wrapper<X>& x)
+{ return std::binary_search(x, x, *x, predicate); }
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/equal/check_type.cc libstdc++-v3.so_7/testsuite/25_algorithms/equal/check_type.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/equal/check_type.cc 2005-01-10 10:52:15.000000000 +0000
+++ libstdc++-v3.so_7/testsuite/25_algorithms/equal/check_type.cc 2005-01-29 19:17:27.000000000 +0000
@@ -16,9 +16,13 @@
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
+// 25.1.8 [lib.alg.equal]
+
// { dg-do compile }
#include <algorithm>
+#include <testsuite_iterators.h>
+using __gnu_test::input_iterator_wrapper;
struct Lhs1 { };
@@ -30,15 +34,15 @@
struct Rhs2 { };
-bool predicate(const Lhs2&, const Rhs2&) {return true;}
+bool
+predicate(const Lhs2&, const Rhs2&) {return true;}
-void test1()
-{
- Lhs1 lhs1[1];
- Rhs1 rhs1[1];
- std::equal(lhs1, lhs1 + 1, rhs1);
+bool
+test1(input_iterator_wrapper<Lhs1>& lhs1,
+ input_iterator_wrapper<Rhs1>& rhs1)
+{ return std::equal(lhs1, lhs1, rhs1); }
- Lhs2 lhs2[1];
- Rhs2 rhs2[1];
- std::equal(lhs2, lhs2 + 1, rhs2, predicate);
-}
+bool
+test2(input_iterator_wrapper<Lhs2>& lhs2,
+ input_iterator_wrapper<Rhs2>& rhs2)
+{ return std::equal(lhs2, lhs2, rhs2, predicate); }
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/equal_range/1.cc libstdc++-v3.so_7/testsuite/25_algorithms/equal_range/1.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/equal_range/1.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/equal_range/1.cc 2005-01-29 16:16:45.000000000 +0000
@@ -0,0 +1,63 @@
+// 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.
+
+// 25.3.3.3 [lib.equal.range]
+
+#include <algorithm>
+#include <utility>
+#include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
+
+using __gnu_test::test_container;
+using __gnu_test::forward_iterator_wrapper;
+using std::equal_range;
+
+typedef test_container<int, forward_iterator_wrapper> Container;
+int array[] = {0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2};
+
+void
+test1()
+{
+ for(int i = 0; i < 6; ++i)
+ for(int j = 6; j < 12; ++j)
+ {
+ Container con(array + i, array + j);
+ VERIFY(equal_range(con.begin(), con.end(), 1).first.ptr ==
+ array + std::max(i, 4));
+ VERIFY(equal_range(con.begin(), con.end(), 1).second.ptr ==
+ array + std::min(j, 8));
+ }
+}
+
+void
+test2()
+{
+ int array[]={0, 0, 2, 2, 2};
+ Container con(array, array + 5);
+ VERIFY(equal_range(con.begin(), con.end(), 1).first.ptr ==
+ array + 2);
+ VERIFY(equal_range(con.begin(), con.end(), 1).second.ptr ==
+ array + 2);
+}
+
+int
+main()
+{
+ test1();
+ test2();
+}
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/equal_range/check_type.cc libstdc++-v3.so_7/testsuite/25_algorithms/equal_range/check_type.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/equal_range/check_type.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/equal_range/check_type.cc 2005-01-29 19:17:47.000000000 +0000
@@ -0,0 +1,43 @@
+// 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.
+
+// 25.3.3.3 [lib.equal.range]
+
+// { dg-do compile }
+
+#include <algorithm>
+#include <utility>
+#include <testsuite_iterators.h>
+
+using __gnu_test::forward_iterator_wrapper;
+
+struct S { };
+
+bool operator<(const S&, const S&) {return true;}
+
+struct X { };
+
+bool predicate(const X&, const X&) {return true;}
+
+std::pair<forward_iterator_wrapper<S>, forward_iterator_wrapper<S> >
+test1(forward_iterator_wrapper<S>& s)
+{ return std::equal_range(s, s, *s); }
+
+std::pair<forward_iterator_wrapper<X>, forward_iterator_wrapper<X> >
+test2(forward_iterator_wrapper<X>& x)
+{ return std::equal_range(x, x, *x, predicate); }
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/find_end/1.cc libstdc++-v3.so_7/testsuite/25_algorithms/find_end/1.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/find_end/1.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/find_end/1.cc 2005-01-29 19:15:06.000000000 +0000
@@ -0,0 +1,57 @@
+// 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.
+
+// 25.1.3 [lib.alg.find.end]
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
+
+using __gnu_test::test_container;
+using __gnu_test::forward_iterator_wrapper;
+
+typedef test_container<int, forward_iterator_wrapper> Container;
+
+using std::find_end;
+
+void
+test1()
+{
+ int array[] = {0};
+ Container con1(array, array);
+ Container con2(array, array + 1);
+ VERIFY(find_end(con1.begin(), con1.end(), con1.begin(), con1.end()).ptr == array);
+ VERIFY(find_end(con1.begin(), con1.end(), con2.begin(), con2.end()).ptr == array);
+ VERIFY(find_end(con2.begin(), con2.end(), con1.begin(), con1.end()).ptr == array + 1);
+}
+
+void
+test2()
+{
+ int array1[] = {2, 2, 1, 2, 2, 1};
+ int array2[] = {2, 2};
+ Container con1(array1, array1 + 6);
+ Container con2(array2, array2 + 2);
+ VERIFY(find_end(con1.begin(), con1.end(), con2.begin(), con2.end()).ptr == array1 + 3);
+}
+
+int main()
+{
+ test1();
+ test2();
+}
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/find_end/check_type.cc libstdc++-v3.so_7/testsuite/25_algorithms/find_end/check_type.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/find_end/check_type.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/find_end/check_type.cc 2005-01-29 18:58:49.000000000 +0000
@@ -0,0 +1,53 @@
+// 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.
+
+// 25.1.3 [lib.alg.find.end]
+
+// { dg-do compile }
+
+
+#include <algorithm>
+#include <testsuite_iterators.h>
+
+using __gnu_test::forward_iterator_wrapper;
+
+struct Lhs1 { };
+
+struct Rhs1 { };
+
+bool operator==(const Lhs1&, const Rhs1&) {return true;}
+
+struct X1 { };
+
+struct X2 { };
+
+bool predicate(const X1&, const X2&) {return true;}
+
+forward_iterator_wrapper<Lhs1>
+test1(forward_iterator_wrapper<Lhs1>& lhs1,
+ forward_iterator_wrapper<Rhs1>& rhs1)
+{
+ return std::find_end(lhs1, lhs1, rhs1, rhs1);
+}
+
+forward_iterator_wrapper<X1>
+test2(forward_iterator_wrapper<X1>& x1,
+ forward_iterator_wrapper<X2>& x2)
+{
+ return std::find_end(x1, x1, x2, x2, predicate);
+}
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/find_first_of/1.cc libstdc++-v3.so_7/testsuite/25_algorithms/find_first_of/1.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/find_first_of/1.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/find_first_of/1.cc 2005-01-29 19:12:11.000000000 +0000
@@ -0,0 +1,58 @@
+// 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.
+
+// 25.1.4 [lib.alg.find.first.of]
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
+
+using __gnu_test::test_container;
+using __gnu_test::forward_iterator_wrapper;
+
+typedef test_container<int, forward_iterator_wrapper> Container;
+
+using std::find_first_of;
+
+void
+test1()
+{
+ int array[] = {0};
+ Container con1(array, array);
+ Container con2(array, array + 1);
+ VERIFY(find_first_of(con1.begin(), con1.end(), con1.begin(), con1.end()).ptr == array);
+ VERIFY(find_first_of(con1.begin(), con1.end(), con2.begin(), con2.end()).ptr == array);
+ VERIFY(find_first_of(con2.begin(), con2.end(), con1.begin(), con1.end()).ptr == array + 1);
+}
+
+void
+test2()
+{
+ int array1[] = {1 ,2, 3, 4, 5, 6};
+ int array2[] = {3, 4, 9};
+ Container con1(array1, array1 + 6);
+ Container con2(array2, array2 + 3);
+ VERIFY(find_first_of(con1.begin(), con1.end(), con2.begin(), con2.end()).ptr == array1 + 2);
+}
+
+int
+main()
+{
+ test1();
+ test2();
+}
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/find_first_of/check_type.cc libstdc++-v3.so_7/testsuite/25_algorithms/find_first_of/check_type.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/find_first_of/check_type.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/find_first_of/check_type.cc 2005-01-29 19:18:23.000000000 +0000
@@ -0,0 +1,49 @@
+// 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.
+
+// 25.1.4 [lib.alg.find.first.of]
+
+// { dg-do compile }
+
+
+#include <algorithm>
+#include <testsuite_iterators.h>
+
+using __gnu_test::forward_iterator_wrapper;
+
+struct Lhs1 { };
+
+struct Rhs1 { };
+
+bool operator==(const Lhs1&, const Rhs1&) {return true;}
+
+struct X1 { };
+
+struct X2 { };
+
+bool predicate(const X1&, const X2&) {return true;}
+
+forward_iterator_wrapper<Lhs1>
+test1(forward_iterator_wrapper<Lhs1>& lhs1,
+ forward_iterator_wrapper<Rhs1>& rhs1)
+{ return std::find_first_of(lhs1, lhs1, rhs1, rhs1); }
+
+forward_iterator_wrapper<X1>
+test2(forward_iterator_wrapper<X1>& x1,
+ forward_iterator_wrapper<X2>& x2)
+{ return std::find_first_of(x1, x1, x2, x2, predicate); }
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/includes/1.cc libstdc++-v3.so_7/testsuite/25_algorithms/includes/1.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/includes/1.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/includes/1.cc 2005-01-29 16:44:06.000000000 +0000
@@ -0,0 +1,63 @@
+// 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.
+
+// 25.3.5.1 [lib.includes]
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
+
+using __gnu_test::test_container;
+using __gnu_test::input_iterator_wrapper;
+using std::includes;
+
+typedef test_container<int, input_iterator_wrapper> Container;
+
+void
+test1()
+{
+ int array[] = {0};
+ Container con1(array, array);
+ Container con2(array, array);
+ VERIFY(includes(con1.begin(), con1.end(), con2.begin(), con2.end()));
+}
+
+void
+test2()
+{
+ int array[] = {0, 1};
+ Container con1(array, array);
+ Container con2(array, array + 2);
+ VERIFY(!includes(con1.begin(), con1.end(), con2.begin(), con2.end()));
+}
+
+void
+test3()
+{
+ int array[] = {0, 1};
+ Container con1(array, array + 2);
+ Container con2(array, array);
+ VERIFY(includes(con1.begin(), con1.end(), con2.begin(), con2.end()));
+}
+
+int main()
+{
+ test1();
+ test2();
+ test3();
+}
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/includes/check_type.cc libstdc++-v3.so_7/testsuite/25_algorithms/includes/check_type.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/includes/check_type.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/includes/check_type.cc 2005-01-29 20:05:04.000000000 +0000
@@ -0,0 +1,46 @@
+// 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.
+
+// 25.3.5.1 [lib.includes]
+
+// { dg-do compile }
+
+#include <algorithm>
+#include <testsuite_iterators.h>
+
+using __gnu_test::input_iterator_wrapper;
+
+struct S { };
+
+bool
+operator<(const S&, const S&)
+{ return true; }
+
+struct X { };
+
+bool
+predicate(const X&, const X&)
+{ return true; }
+
+bool
+test1(input_iterator_wrapper<S>& s)
+{ return std::includes(s, s, s, s); }
+
+bool
+test2(input_iterator_wrapper<X>& x)
+{ return std::includes(x, x, x, x, predicate); }
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/inplace_merge/1.cc libstdc++-v3.so_7/testsuite/25_algorithms/inplace_merge/1.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/inplace_merge/1.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/inplace_merge/1.cc 2005-01-29 19:19:19.000000000 +0000
@@ -0,0 +1,84 @@
+// 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.
+
+// 25.3.4 [lib.alg.merge]
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
+
+using __gnu_test::test_container;
+using __gnu_test::bidirectional_iterator_wrapper;
+using std::inplace_merge;
+
+typedef test_container<int, bidirectional_iterator_wrapper> container;
+
+
+void
+test1()
+{
+ int array[]={1};
+ container con1(array, array);
+ inplace_merge(con1.begin(), con1.end(), con1.end());
+ container con2(array, array + 1);
+ inplace_merge(con2.begin(), con2.end(), con2.end());
+ inplace_merge(con2.begin(), con2.begin(), con2.end());
+}
+
+void
+test2()
+{
+ int array[]={0,2,4,1,3,5};
+ container con(array, array + 6);
+ inplace_merge(con.begin(), con.it(3), con.end());
+ VERIFY(array[0] == 0 && array[1] == 1 && array[2] == 2 &&
+ array[3] == 3 && array[4] == 4 && array[5] == 5);
+}
+
+struct S
+{
+ int a;
+ int b;
+ S(int _a, int _b) : a(_a), b(_b) { }
+ S() { }
+ bool
+ operator<(const S& _s) const
+ { return _s.a < a; }
+};
+
+void
+test3()
+{
+ S s[4];
+ s[0].a = 0;
+ s[1].a = 1;
+ s[2].a = 0;
+ s[3].a = 1;
+ s[0].b = 0;
+ s[1].b = 0;
+ s[2].b = 1;
+ s[3].b = 1;
+ inplace_merge(s, s + 2, s + 4);
+ VERIFY(s[0].b == 0 && s[1].b == 1 && s[2].b == 0 && s[3].b == 1);
+}
+
+int
+main()
+{
+ test1();
+}
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/inplace_merge/check_type.cc libstdc++-v3.so_7/testsuite/25_algorithms/inplace_merge/check_type.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/inplace_merge/check_type.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/inplace_merge/check_type.cc 2005-01-29 19:19:50.000000000 +0000
@@ -0,0 +1,48 @@
+// 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.
+
+// 25.3.4 [lib.alg.merge]
+
+// { dg-do compile }
+
+#include <algorithm>
+#include <testsuite_iterators.h>
+
+using __gnu_test::bidirectional_iterator_wrapper;
+
+struct S { };
+
+bool
+operator<(const S&, const S&) {return true;}
+
+struct X { };
+
+bool
+predicate(const X&, const X&) {return true;}
+
+void
+test1(bidirectional_iterator_wrapper<S>& s)
+{
+ std::inplace_merge(s, s, s);
+}
+
+void
+test2(bidirectional_iterator_wrapper<X>& x)
+{
+ std::inplace_merge(x, x, x, predicate);
+}
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/lexicographical_compare/1.cc libstdc++-v3.so_7/testsuite/25_algorithms/lexicographical_compare/1.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/lexicographical_compare/1.cc 2005-01-10 10:52:15.000000000 +0000
+++ libstdc++-v3.so_7/testsuite/25_algorithms/lexicographical_compare/1.cc 2005-01-29 19:20:15.000000000 +0000
@@ -16,6 +16,8 @@
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
+// 25.3.8 [lib.alg.lex.comparison]
+
#include <algorithm>
#include <testsuite_hooks.h>
#include <testsuite_iterators.h>
@@ -28,7 +30,8 @@
int array2[] = {1, 0};
int array3[] = {1, 0, 1};
-void test1()
+void
+test1()
{
Container con1(array1, array1);
Container con2(array2, array2);
@@ -36,7 +39,8 @@
con2.begin(), con2.end()) );
}
-void test2()
+void
+test2()
{
Container con1(array1, array1 + 2);
Container con2(array2, array2 + 2);
@@ -44,7 +48,8 @@
con2.begin(), con2.end()) );
}
-void test3()
+void
+test3()
{
Container con1(array1, array1 + 2);
Container con2(array2, array2 + 2);
@@ -52,7 +57,8 @@
con1.begin(), con1.end()) );
}
-void test4()
+void
+test4()
{
Container con3(array3, array3 + 3);
Container con2(array2, array2 + 2);
@@ -60,7 +66,8 @@
con3.begin(), con3.end()) );
}
-void test5()
+void
+test5()
{
Container con3(array3, array3 + 3);
Container con2(array2, array2 + 2);
@@ -68,7 +75,8 @@
con2.begin(), con2.end()) );
}
-int main()
+int
+main()
{
test1();
test2();
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/lexicographical_compare/check_type.cc libstdc++-v3.so_7/testsuite/25_algorithms/lexicographical_compare/check_type.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/lexicographical_compare/check_type.cc 2005-01-10 10:52:15.000000000 +0000
+++ libstdc++-v3.so_7/testsuite/25_algorithms/lexicographical_compare/check_type.cc 2005-01-29 19:20:40.000000000 +0000
@@ -16,31 +16,36 @@
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
+// 25.3.8 [lib.alg.lex.comparison]
+
// { dg-do compile }
+
#include <algorithm>
+#include <testsuite_iterators.h>
+
+using __gnu_test::input_iterator_wrapper;
struct Lhs1 { };
struct Rhs1 { };
-bool operator<(const Lhs1&, const Rhs1&) {return true;}
+bool
+operator<(const Lhs1&, const Rhs1&) {return true;}
-bool operator<(const Rhs1&, const Lhs1&) {return false;}
+bool
+operator<(const Rhs1&, const Lhs1&) {return false;}
struct X { };
-bool predicate(const X&, const X&) {return true;}
-
-void test1()
-{
- Lhs1 lhs1[1];
- Rhs1 rhs1[1];
-
- std::lexicographical_compare(lhs1, lhs1 + 1, rhs1, rhs1 + 1);
+bool
+predicate(const X&, const X&) {return true;}
- X x1[1];
- X x2[1];
+bool
+test1(input_iterator_wrapper<Lhs1>& lhs1,
+ input_iterator_wrapper<Rhs1>& rhs1)
+{ return std::lexicographical_compare(lhs1, lhs1, rhs1, rhs1); }
- std::lexicographical_compare(x1, x1 + 1, x2, x2 + 1, predicate);
-}
+bool
+test2(input_iterator_wrapper<X>& x)
+{ return std::lexicographical_compare(x, x, x, x, predicate); }
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/lower_bound/1.cc libstdc++-v3.so_7/testsuite/25_algorithms/lower_bound/1.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/lower_bound/1.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/lower_bound/1.cc 2005-01-29 19:20:52.000000000 +0000
@@ -0,0 +1,47 @@
+// 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.
+
+// 25.3.3.1 [lib.lower.bound]
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
+
+using __gnu_test::test_container;
+using __gnu_test::forward_iterator_wrapper;
+using std::lower_bound;
+
+typedef test_container<int, forward_iterator_wrapper> Container;
+int array[] = {0, 0, 0, 0, 1, 1, 1, 1};
+
+void
+test1()
+{
+ for(int i = 0; i < 5; ++i)
+ for(int j = 4; j < 7; ++j)
+ {
+ Container con(array + i, array + j);
+ VERIFY(lower_bound(con.begin(), con.end(), 1).ptr == array + 4);
+ }
+}
+
+int
+main()
+{
+ test1();
+}
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/lower_bound/check_type.cc libstdc++-v3.so_7/testsuite/25_algorithms/lower_bound/check_type.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/lower_bound/check_type.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/lower_bound/check_type.cc 2005-01-29 19:21:08.000000000 +0000
@@ -0,0 +1,44 @@
+// 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.
+
+// 25.3.3.1 [lib.lower.bound]
+
+// { dg-do compile }
+
+#include <algorithm>
+#include <testsuite_iterators.h>
+
+using __gnu_test::forward_iterator_wrapper;
+
+struct S { };
+
+bool
+operator<(const S&, const S&) {return true;}
+
+struct X { };
+
+bool
+predicate(const X&, const X&) {return true;}
+
+forward_iterator_wrapper<S>
+test1(forward_iterator_wrapper<S>& s)
+{ return std::lower_bound(s, s, *s); }
+
+forward_iterator_wrapper<X>
+test2(forward_iterator_wrapper<X>& x)
+{ return std::lower_bound(x, x, *x, predicate); }
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/max_element/1.cc libstdc++-v3.so_7/testsuite/25_algorithms/max_element/1.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/max_element/1.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/max_element/1.cc 2005-01-29 18:28:02.000000000 +0000
@@ -0,0 +1,71 @@
+// 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.
+
+// 25.3.7 [lib.alg.min.max]
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
+
+using __gnu_test::test_container;
+using __gnu_test::forward_iterator_wrapper;
+using std::max_element;
+
+typedef test_container<int, forward_iterator_wrapper> Container;
+
+void
+test1()
+{
+ // Note: The standard is unclear on what should happen in this case.
+ // This seems the only really sensible behaviour, and what is done.
+ int array[] = {0};
+ Container con(array, array);
+ VERIFY(max_element(con.begin(), con.end()).ptr == array);
+}
+
+void
+test2()
+{
+ int array[] = {0};
+ Container con(array, array + 1);
+ VERIFY(max_element(con.begin(), con.end()).ptr == array);
+}
+
+void
+test3()
+{
+ int array[] = {3, 0};
+ Container con(array, array + 2);
+ VERIFY(max_element(con.begin(), con.end()).ptr == array);
+}
+
+void
+test4()
+{
+ int array[] = {0, 3, 6, 2, 6, 4, 0};
+ Container con(array, array + 7);
+ VERIFY(max_element(con.begin(), con.end()).ptr == array + 2);
+}
+
+int main()
+{
+ test1();
+ test2();
+ test3();
+ test4();
+}
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/max_element/check_type.cc libstdc++-v3.so_7/testsuite/25_algorithms/max_element/check_type.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/max_element/check_type.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/max_element/check_type.cc 2005-01-29 19:21:41.000000000 +0000
@@ -0,0 +1,44 @@
+// 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.
+
+// 25.3.7 [lib.alg.min.max]
+
+// { dg-do compile }
+
+#include <algorithm>
+#include <testsuite_iterators.h>
+
+using __gnu_test::forward_iterator_wrapper;
+
+struct S { };
+
+bool
+operator<(const S&, const S&) {return true;}
+
+struct X { };
+
+bool
+predicate(const X&, const X&) {return true;}
+
+forward_iterator_wrapper<S>
+test1(forward_iterator_wrapper<S>& s)
+{ return std::max_element(s, s); }
+
+forward_iterator_wrapper<X>
+test2(forward_iterator_wrapper<X>& x)
+{ return std::max_element(x, x, predicate); }
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/merge/1.cc libstdc++-v3.so_7/testsuite/25_algorithms/merge/1.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/merge/1.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/merge/1.cc 2005-01-29 19:22:08.000000000 +0000
@@ -0,0 +1,101 @@
+// 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.
+
+// 25.3.4 [lib.alg.merge]
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
+
+using __gnu_test::test_container;
+using __gnu_test::input_iterator_wrapper;
+using __gnu_test::output_iterator_wrapper;
+using std::merge;
+
+typedef test_container<int, input_iterator_wrapper> Icontainer;
+typedef test_container<int, output_iterator_wrapper> Ocontainer;
+
+void
+test1()
+{
+ int array1[1], array2[1];
+ Icontainer con1(array1, array1);
+ Icontainer con2(array1, array1);
+ Ocontainer con3(array2, array2);
+ VERIFY(merge(con1.begin(), con1.end(), con2.begin(), con2.end(),
+ con3.begin()).ptr == array2);
+}
+
+void
+test2()
+{
+ int array1[]={0,1,4};
+ int array2[]={2,3};
+ int array3[5];
+ Icontainer con1(array1, array1 + 3);
+ Icontainer con2(array2, array2 + 2);
+ Ocontainer con3(array3, array3 + 5);
+ VERIFY(merge(con1.begin(), con1.end(), con2.begin(), con2.end(),
+ con3.begin()).ptr == array3 + 5);
+ VERIFY(array3[0] == 0 && array3[1] == 1 && array3[2] == 2 &&
+ array3[3] == 3 && array3[4] == 4);
+
+}
+
+struct S
+{
+ int i;
+ int j;
+ S() {}
+ S(int in)
+ {
+ if(in > 0)
+ {
+ i = in;
+ j = 1;
+ }
+ else
+ {
+ i = -in;
+ j = 0;
+ }
+ }
+};
+
+bool
+operator<(const S& s1, const S& s2)
+{ return s1.i < s2.i; }
+
+void
+test3()
+{
+ S array1[] = { -1 , -3};
+ S array2[] = { 1, 2, 3};
+ S array3[5];
+ merge(array1, array1 + 2, array2, array2 + 3, array3);
+ VERIFY(array3[0].j == 0 && array3[1].j == 1 && array3[2].j == 1 &&
+ array3[3].j == 0 && array3[4].j == 1);
+}
+
+int
+main()
+{
+ test1();
+ test2();
+ test3();
+}
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/merge/check_type.cc libstdc++-v3.so_7/testsuite/25_algorithms/merge/check_type.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/merge/check_type.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/merge/check_type.cc 2005-01-29 19:22:31.000000000 +0000
@@ -0,0 +1,46 @@
+// 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.
+
+// 25.3.4 [lib.alg.merge]
+
+// { dg-do compile }
+
+#include <algorithm>
+#include <testsuite_iterators.h>
+using __gnu_test::input_iterator_wrapper;
+using __gnu_test::output_iterator_wrapper;
+
+struct S { };
+
+bool
+operator<(const S&, const S&) {return true;}
+
+struct X { };
+
+bool
+predicate(const X&, const X&) {return true;}
+
+output_iterator_wrapper<S>
+test1(input_iterator_wrapper<S>& in,
+ output_iterator_wrapper<S>& out)
+{ return std::merge(in, in, in, in, out); }
+
+output_iterator_wrapper<X>
+test2(input_iterator_wrapper<X>& in,
+ output_iterator_wrapper<X>& out)
+{ return std::merge(in, in, in, in, out, predicate); }
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/min_element/1.cc libstdc++-v3.so_7/testsuite/25_algorithms/min_element/1.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/min_element/1.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/min_element/1.cc 2005-01-29 18:26:29.000000000 +0000
@@ -0,0 +1,71 @@
+// 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.
+
+// 25.3.7 [lib.alg.min.max]
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
+
+using __gnu_test::test_container;
+using __gnu_test::forward_iterator_wrapper;
+using std::min_element;
+
+typedef test_container<int, forward_iterator_wrapper> Container;
+
+void
+test1()
+{
+ // Note: The standard is unclear on what should happen in this case.
+ // This seems the only really sensible behaviour, and what is done.
+ int array[] = {0};
+ Container con(array, array);
+ VERIFY(min_element(con.begin(), con.end()).ptr == array);
+}
+
+void
+test2()
+{
+ int array[] = {0};
+ Container con(array, array + 1);
+ VERIFY(min_element(con.begin(), con.end()).ptr == array);
+}
+
+void
+test3()
+{
+ int array[] = {0, 3};
+ Container con(array, array + 2);
+ VERIFY(min_element(con.begin(), con.end()).ptr == array);
+}
+
+void
+test4()
+{
+ int array[] = {6, 3, 0, 2, 6, 4, 0};
+ Container con(array, array + 7);
+ VERIFY(min_element(con.begin(), con.end()).ptr == array + 2);
+}
+
+int main()
+{
+ test1();
+ test2();
+ test3();
+ test4();
+}
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/min_element/check_type.cc libstdc++-v3.so_7/testsuite/25_algorithms/min_element/check_type.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/min_element/check_type.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/min_element/check_type.cc 2005-01-29 19:22:52.000000000 +0000
@@ -0,0 +1,44 @@
+// 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.
+
+// 25.3.7 [lib.alg.min.max]
+
+// { dg-do compile }
+
+#include <algorithm>
+#include <testsuite_iterators.h>
+
+using __gnu_test::forward_iterator_wrapper;
+
+struct S { };
+
+bool
+operator<(const S&, const S&) {return true;}
+
+struct X { };
+
+bool
+predicate(const X&, const X&) {return true;}
+
+forward_iterator_wrapper<S>
+test1(forward_iterator_wrapper<S>& s)
+{ return std::min_element(s,s); }
+
+forward_iterator_wrapper<X>
+test2(forward_iterator_wrapper<X>& x)
+{ return std::min_element(x,x,predicate); }
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/mismatch/1.cc libstdc++-v3.so_7/testsuite/25_algorithms/mismatch/1.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/mismatch/1.cc 2005-01-10 10:52:15.000000000 +0000
+++ libstdc++-v3.so_7/testsuite/25_algorithms/mismatch/1.cc 2005-01-29 14:06:53.000000000 +0000
@@ -16,6 +16,8 @@
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
+// 25.1.7 [lib.mismatch]
+
#include <algorithm>
#include <testsuite_hooks.h>
#include <testsuite_iterators.h>
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/mismatch/check_type.cc libstdc++-v3.so_7/testsuite/25_algorithms/mismatch/check_type.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/mismatch/check_type.cc 2005-01-10 10:52:15.000000000 +0000
+++ libstdc++-v3.so_7/testsuite/25_algorithms/mismatch/check_type.cc 2005-01-29 14:05:59.000000000 +0000
@@ -16,9 +16,15 @@
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
+// 25.1.7 [lib.mismatch]
+
// { dg-do compile }
#include <algorithm>
+#include <utility>
+#include <testsuite_iterators.h>
+
+using __gnu_test::input_iterator_wrapper;
struct Lhs1 { };
@@ -32,15 +38,14 @@
bool predicate(const Lhs2&, const Rhs2&) {return true;}
-void test1()
+std::pair<input_iterator_wrapper<Lhs1>, input_iterator_wrapper<Rhs1> >
+test1(input_iterator_wrapper<Lhs1>& lhs1, input_iterator_wrapper<Rhs1>& rhs1)
{
- Lhs1 lhs1[1];
- Rhs1 rhs1[1];
-
- std::mismatch(lhs1, lhs1 + 1, rhs1);
-
- Lhs2 lhs2[1];
- Rhs2 rhs2[1];
+ return std::mismatch(lhs1, lhs1, rhs1);
+}
- std::mismatch(lhs2, lhs2 + 1, rhs2, predicate);
+std::pair<input_iterator_wrapper<Lhs2>, input_iterator_wrapper<Rhs2> >
+test2(input_iterator_wrapper<Lhs2>& lhs2, input_iterator_wrapper<Rhs2>& rhs2)
+{
+ return std::mismatch(lhs2, lhs2, rhs2, predicate);
}
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/next_permutation/1.cc libstdc++-v3.so_7/testsuite/25_algorithms/next_permutation/1.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/next_permutation/1.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/next_permutation/1.cc 2005-01-29 18:42:16.000000000 +0000
@@ -0,0 +1,84 @@
+// 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.
+
+// 25.3.9 [lib.alg.permutation.generators]
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
+
+using __gnu_test::test_container;
+using __gnu_test::bidirectional_iterator_wrapper;
+using std::next_permutation;
+
+typedef test_container<int, bidirectional_iterator_wrapper> Container;
+
+void
+test1()
+{
+ // Note: The standard is unclear on what should happen in this case.
+ // This seems the only really sensible behaviour, and what is done.
+ int array[] = {0};
+ Container con(array, array);
+ VERIFY(!next_permutation(con.begin(), con.end()));
+}
+
+void
+test2()
+{
+ int array[] = {0};
+ Container con(array, array + 1);
+ VERIFY(!next_permutation(con.begin(), con.end()));
+}
+
+void
+test3()
+{
+ int array[] = {0, 3};
+ Container con(array, array + 2);
+ VERIFY(next_permutation(con.begin(), con.end()));
+ VERIFY(array[0] == 3 && array[1] == 0);
+ VERIFY(!next_permutation(con.begin(), con.end()));
+ VERIFY(array[0] == 0 && array[1] == 3);
+}
+
+void
+test4()
+{
+ int array[6] = {0, 1, 2, 3, 4, 5};
+ Container con(array, array + 6);
+ for(int i = 0 ; i < 719; ++i)
+ {
+ int temp_array[6];
+ std::copy(array, array + 6, temp_array);
+ VERIFY(next_permutation(array, array + 6));
+ VERIFY(std::lexicographical_compare(temp_array, temp_array + 6,
+ array, array + 6));
+ }
+ VERIFY(!next_permutation(array,array + 6));
+ for(int i = 0; i < 6; ++i)
+ VERIFY(array[i] == i);
+}
+
+int main()
+{
+ test1();
+ test2();
+ test3();
+ test4();
+}
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/next_permutation/check_type.cc libstdc++-v3.so_7/testsuite/25_algorithms/next_permutation/check_type.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/next_permutation/check_type.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/next_permutation/check_type.cc 2005-01-29 19:23:12.000000000 +0000
@@ -0,0 +1,44 @@
+// 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.
+
+// 25.3.9 [lib.alg.permutation.generators]
+
+// { dg-do compile }
+
+#include <algorithm>
+#include <testsuite_iterators.h>
+
+using __gnu_test::bidirectional_iterator_wrapper;
+
+struct S { };
+
+bool
+operator<(const S&, const S&) {return true;}
+
+struct X { };
+
+bool
+predicate(const X&, const X&) {return true;}
+
+bool
+test1(bidirectional_iterator_wrapper<S>& s)
+{ return std::next_permutation(s,s); }
+
+bool
+test2(bidirectional_iterator_wrapper<X>& x)
+{ return std::next_permutation(x,x,predicate); }
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/nth_element/1.cc libstdc++-v3.so_7/testsuite/25_algorithms/nth_element/1.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/nth_element/1.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/nth_element/1.cc 2005-01-29 19:23:33.000000000 +0000
@@ -0,0 +1,79 @@
+// 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.
+
+// 25.3.2 [lib.alg.nth.element]
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
+
+using __gnu_test::test_container;
+using __gnu_test::random_access_iterator_wrapper;
+using std::nth_element;
+
+typedef test_container<int, random_access_iterator_wrapper> Container;
+
+void
+test1()
+{
+ int array[]={0};
+ Container con(array, array);
+ partial_sort(con.begin(), con.begin(), con.end());
+}
+
+void
+test2()
+{
+ int array[]={2,1,0};
+ Container con(array, array + 2);
+ partial_sort(con.begin(), con.begin(), con.end());
+ partial_sort(con.begin(), con.end(), con.end());
+}
+
+void
+test3()
+{
+ int array[] = {6, 5, 4, 3, 2, 1, 0};
+ Container con(array, array + 7);
+ nth_element(con.begin(), con.it(3), con.end());
+ for(int i = 0; i < 3; ++i)
+ VERIFY(array[i] < array[3]);
+ for(int i = 4; i < 7; ++i)
+ VERIFY(array[3] < array[i]);
+}
+
+void
+test4()
+{
+ int array[] = {0, 6, 1, 5, 2, 4, 3};
+ Container con(array,array + 7);
+ nth_element(con.begin(), con.it(3), con.end());
+ for(int i = 0; i < 3; ++i)
+ VERIFY(array[i] < array[3]);
+ for(int i = 4; i < 7; ++i)
+ VERIFY(array[3] < array[i]);
+}
+
+int
+main()
+{
+ test1();
+ test2();
+ test3();
+ test4();
+}
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/nth_element/check_type.cc libstdc++-v3.so_7/testsuite/25_algorithms/nth_element/check_type.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/nth_element/check_type.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/nth_element/check_type.cc 2005-01-29 19:23:49.000000000 +0000
@@ -0,0 +1,45 @@
+// 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.
+
+// 25.3.2 [lib.alg.nth.element]
+
+// { dg-do compile }
+
+#include <algorithm>
+#include <testsuite_iterators.h>
+
+using __gnu_test::random_access_iterator_wrapper;
+
+struct S { };
+
+bool
+operator<(const S&, const S&) {return true;}
+
+struct X { };
+
+bool
+predicate(const X&, const X&) {return true;}
+
+void
+test1(random_access_iterator_wrapper<S>& s)
+{ std::nth_element(s, s, s); }
+
+void
+test2(random_access_iterator_wrapper<X>& x)
+{ std::nth_element(x, x, x, predicate); }
+
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/partial_sort/1.cc libstdc++-v3.so_7/testsuite/25_algorithms/partial_sort/1.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/partial_sort/1.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/partial_sort/1.cc 2005-01-29 19:24:07.000000000 +0000
@@ -0,0 +1,66 @@
+// 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.
+
+// 25.3.1.3 [lib.partial.sort]
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
+
+using __gnu_test::test_container;
+using __gnu_test::random_access_iterator_wrapper;
+using std::partial_sort;
+
+typedef test_container<int, random_access_iterator_wrapper> Container;
+
+void
+test1()
+{
+ int array[]={2,1,0};
+ Container con1(array, array + 2);
+ Container con2(array, array);
+ partial_sort(con2.begin(), con2.begin(), con2.end());
+ partial_sort(con1.begin(), con1.begin(), con1.end());
+ partial_sort(con1.begin(), con1.end(), con1.end());
+}
+
+void
+test2()
+{
+ int array[] = {6, 5, 4, 3, 2, 1, 0};
+ Container con(array, array + 7);
+ partial_sort(con.begin(), con.it(3), con.end());
+ VERIFY(array[0] == 0 && array[1] == 1 && array[2] == 2);
+}
+
+void
+test3()
+{
+ int array[] = {0, 6, 1, 5, 2, 4, 3};
+ Container con(array,array + 7);
+ partial_sort(con.begin(), con.it(3), con.end());
+ VERIFY(array[0] == 0 && array[1] == 1 && array[2] == 2);
+}
+
+int
+main()
+{
+ test1();
+ test2();
+ test3();
+}
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/partial_sort/check_type.cc libstdc++-v3.so_7/testsuite/25_algorithms/partial_sort/check_type.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/partial_sort/check_type.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/partial_sort/check_type.cc 2005-01-29 19:24:25.000000000 +0000
@@ -0,0 +1,49 @@
+// 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.
+
+// 25.3.1.3 [lib.partial.sort]
+
+// { dg-do compile }
+
+#include <algorithm>
+#include <testsuite_iterators.h>
+
+using __gnu_test::random_access_iterator_wrapper;
+
+struct S { };
+
+bool
+operator<(const S&, const S&) {return true;}
+
+struct X { };
+
+bool
+predicate(const X&, const X&) {return true;}
+
+void
+test1(random_access_iterator_wrapper<S>& s)
+{
+ std::partial_sort(s, s, s);
+}
+
+void
+test2(random_access_iterator_wrapper<X>& x)
+{
+ std::partial_sort(x, x, x, predicate);
+}
+
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/partial_sort_copy/1.cc libstdc++-v3.so_7/testsuite/25_algorithms/partial_sort_copy/1.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/partial_sort_copy/1.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/partial_sort_copy/1.cc 2005-01-29 19:24:52.000000000 +0000
@@ -0,0 +1,89 @@
+// 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.
+
+// 25.3.1.4 [lib.partial.sort.copy]
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
+
+using __gnu_test::test_container;
+using __gnu_test::random_access_iterator_wrapper;
+using __gnu_test::input_iterator_wrapper;
+using std::partial_sort_copy;
+
+typedef test_container<int, random_access_iterator_wrapper> Rcontainer;
+typedef test_container<int, input_iterator_wrapper> Icontainer;
+
+void
+test1()
+{
+ int array[]={2,1,0};
+ Rcontainer rcon1(array, array);
+ Rcontainer rcon2(array, array + 2);
+ Icontainer icon1(array, array);
+ Icontainer icon2(array, array + 2);
+ partial_sort_copy(icon1.begin(), icon1.end(), rcon1.begin(), rcon1.end());
+ partial_sort_copy(icon1.begin(), icon1.end(), rcon2.begin(), rcon2.end());
+ partial_sort_copy(icon2.begin(), icon2.end(), rcon1.begin(), rcon1.end());
+ partial_sort_copy(icon2.begin(), icon2.end(), rcon2.begin(), rcon2.end());
+}
+
+void
+test2()
+{
+ int array1[] = {4, 3, 2, 1, 0};
+ int array2[5];
+ Icontainer icon(array1, array1 + 5);
+ Rcontainer rcon(array2, array2 + 5);
+ partial_sort_copy(icon.begin(), icon.end(), rcon.begin(), rcon.end());
+ VERIFY(array2[0] == 0 && array2[1] == 1 && array2[2] == 2 &&
+ array2[3] == 3 && array2[4] == 4);
+}
+
+void
+test3()
+{
+ int array1[] = {4, 0, 1, 3, 2};
+ int array2[5];
+ Icontainer icon(array1, array1 + 5);
+ Rcontainer rcon(array2, array2 + 2);
+ partial_sort_copy(icon.begin(), icon.end(), rcon.begin(), rcon.end());
+ VERIFY(array2[0] == 0 && array2[1] == 1);
+}
+
+void
+test4()
+{
+ int array1[] = {4, 1, 3, 2, 0};
+ int array2[20];
+ Icontainer icon(array1, array1 + 5);
+ Rcontainer rcon(array2, array2 + 20);
+ partial_sort_copy(icon.begin(), icon.end(), rcon.begin(), rcon.end());
+ VERIFY(array2[0] == 0 && array2[1] == 1 && array2[2] == 2 &&
+ array2[3] == 3 && array2[4] == 4);
+}
+
+int
+main()
+{
+ test1();
+ test2();
+ test3();
+ test4();
+}
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/partial_sort_copy/check_type.cc libstdc++-v3.so_7/testsuite/25_algorithms/partial_sort_copy/check_type.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/partial_sort_copy/check_type.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/partial_sort_copy/check_type.cc 2005-01-29 19:25:40.000000000 +0000
@@ -0,0 +1,68 @@
+// 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.
+
+// 25.3.1.4 [lib.partial.sort.copy]
+
+// { dg-do compile }
+
+#include <algorithm>
+#include <testsuite_iterators.h>
+
+using __gnu_test::input_iterator_wrapper;
+using __gnu_test::random_access_iterator_wrapper;
+
+struct S1 { };
+struct S2
+{
+ S2(const S1&) {}
+ S2() {}
+};
+
+bool
+operator<(const S1&, const S1&)
+{return true;}
+
+bool
+operator<(const S2&, const S2&)
+{return true;}
+
+struct X1 { };
+struct X2
+{
+ X2(const X1&) {}
+ X2() {}
+};
+
+struct predicate
+{
+ bool
+ operator()(const X1&, const X1&)
+ {return true;}
+
+ bool
+ operator()(const X2&, const X2&)
+ {return true;}
+};
+
+random_access_iterator_wrapper<S2>
+test1(input_iterator_wrapper<S1>& s1, random_access_iterator_wrapper<S2>& s2)
+{ return std::partial_sort_copy(s1, s1, s2, s2); }
+
+random_access_iterator_wrapper<X2>
+test2(input_iterator_wrapper<X1>& x1, random_access_iterator_wrapper<X2>& x2)
+{ return std::partial_sort_copy(x1, x1, x2, x2, predicate()); }
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/prev_permutation/1.cc libstdc++-v3.so_7/testsuite/25_algorithms/prev_permutation/1.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/prev_permutation/1.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/prev_permutation/1.cc 2005-01-29 18:44:03.000000000 +0000
@@ -0,0 +1,84 @@
+// 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.
+
+// 25.3.9 [lib.alg.permutation.generators]
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
+
+using __gnu_test::test_container;
+using __gnu_test::bidirectional_iterator_wrapper;
+using std::prev_permutation;
+
+typedef test_container<int, bidirectional_iterator_wrapper> Container;
+
+void
+test1()
+{
+ // Note: The standard is unclear on what should happen in this case.
+ // This seems the only really sensible behaviour, and what is done.
+ int array[] = {0};
+ Container con(array, array);
+ VERIFY(!prev_permutation(con.begin(), con.end()));
+}
+
+void
+test2()
+{
+ int array[] = {0};
+ Container con(array, array + 1);
+ VERIFY(!prev_permutation(con.begin(), con.end()));
+}
+
+void
+test3()
+{
+ int array[] = {3, 0};
+ Container con(array, array + 2);
+ VERIFY(prev_permutation(con.begin(), con.end()));
+ VERIFY(array[0] == 0 && array[1] == 3);
+ VERIFY(!prev_permutation(con.begin(), con.end()));
+ VERIFY(array[0] == 3 && array[1] == 0);
+}
+
+void
+test4()
+{
+ int array[6] = {5, 4, 3, 2, 1, 0};
+ Container con(array, array + 6);
+ for(int i = 0 ; i < 719; ++i)
+ {
+ int temp_array[6];
+ std::copy(array, array + 6, temp_array);
+ VERIFY(prev_permutation(array, array + 6));
+ VERIFY(std::lexicographical_compare(array, array + 6,
+ temp_array, temp_array + 6));
+ }
+ VERIFY(!prev_permutation(array,array + 6));
+ for(int i = 0; i < 6; ++i)
+ VERIFY(array[i] == 5 - i);
+}
+
+int main()
+{
+ test1();
+ test2();
+ test3();
+ test4();
+}
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/prev_permutation/check_type.cc libstdc++-v3.so_7/testsuite/25_algorithms/prev_permutation/check_type.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/prev_permutation/check_type.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/prev_permutation/check_type.cc 2005-01-29 19:26:05.000000000 +0000
@@ -0,0 +1,44 @@
+// 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.
+
+// 25.3.9 [lib.alg.permutation.generators]
+
+// { dg-do compile }
+
+#include <algorithm>
+#include <testsuite_iterators.h>
+
+using __gnu_test::bidirectional_iterator_wrapper;
+
+struct S { };
+
+bool
+operator<(const S&, const S&) {return true;}
+
+struct X { };
+
+bool
+predicate(const X&, const X&) {return true;}
+
+bool
+test1(bidirectional_iterator_wrapper<S>& s)
+{ return std::prev_permutation(s,s); }
+
+bool
+test2(bidirectional_iterator_wrapper<X>& x)
+{ return std::prev_permutation(x,x,predicate); }
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/search/1.cc libstdc++-v3.so_7/testsuite/25_algorithms/search/1.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/search/1.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/search/1.cc 2005-01-29 19:38:15.000000000 +0000
@@ -0,0 +1,66 @@
+// 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.
+
+// 25.1.5 [lib.alg.search]
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
+
+using __gnu_test::test_container;
+using __gnu_test::forward_iterator_wrapper;
+using std::search;
+
+typedef test_container<int, forward_iterator_wrapper> Container;
+int array1[] = {0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1};
+int array2[] = {0, 0, 0};
+
+void
+test1()
+{
+ Container con1(array1, array1);
+ Container con2(array1, array1 + 1);
+ VERIFY(search(con1.begin(), con1.end(), con2.begin(), con2.end()).ptr == array1);
+ VERIFY(search(con2.begin(), con2.end(), con1.begin(), con1.end()).ptr == array1);
+}
+
+void
+test2()
+{
+ Container con1(array1, array1 + 3);
+ Container con2(array2, array2 + 3);
+ VERIFY(search(con1.begin(), con1.end(), con2.begin(), con2.end()).ptr
+ == array1);
+}
+
+void
+test3()
+{
+ Container con1(array1 + 3, array1 + 10);
+ Container con2(array2, array2 + 3);
+ VERIFY(search(con1.begin(), con1.end(), con2.begin(), con2.end()).ptr
+ == array1 + 10);
+}
+
+int
+main()
+{
+ test1();
+ test2();
+ test3();
+}
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/search/check_type.cc libstdc++-v3.so_7/testsuite/25_algorithms/search/check_type.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/search/check_type.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/search/check_type.cc 2005-01-29 19:27:46.000000000 +0000
@@ -0,0 +1,46 @@
+// 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.
+
+// 25.1.9 [lib.alg.search]
+
+// { dg-do compile }
+
+#include <algorithm>
+#include <testsuite_iterators.h>
+
+using __gnu_test::forward_iterator_wrapper;
+
+struct S1 { };
+struct S2 { };
+
+bool
+operator==(const S1&, const S2&) {return true;}
+
+struct X1 { };
+struct X2 { };
+
+bool
+predicate(const X1&, const X2&) {return true;}
+
+forward_iterator_wrapper<S1>
+test1(forward_iterator_wrapper<S1>& s1, forward_iterator_wrapper<S2>& s2)
+{ return std::search(s1, s1, s2, s2); }
+
+forward_iterator_wrapper<X1>
+test2(forward_iterator_wrapper<X1>& x1, forward_iterator_wrapper<X2>& x2)
+{ return std::search(x1, x1, x2, x2, predicate); }
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/set_difference/1.cc libstdc++-v3.so_7/testsuite/25_algorithms/set_difference/1.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/set_difference/1.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/set_difference/1.cc 2005-01-29 19:28:26.000000000 +0000
@@ -0,0 +1,132 @@
+// 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.
+
+// 25.3.5.3 [lib.set.difference]
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
+
+using __gnu_test::test_container;
+using __gnu_test::input_iterator_wrapper;
+using __gnu_test::output_iterator_wrapper;
+using std::set_difference;
+
+typedef test_container<int, input_iterator_wrapper> Icontainer;
+typedef test_container<int, output_iterator_wrapper> Ocontainer;
+
+void
+test1()
+{
+ int array1[1], array2[1];
+ Icontainer con1(array1, array1);
+ Icontainer con2(array1, array1);
+ Ocontainer con3(array2, array2);
+ VERIFY(set_difference(con1.begin(), con1.end(), con2.begin(), con2.end(),
+ con3.begin()).ptr == array2);
+}
+
+void
+test2()
+{
+ int array1[] = {1};
+ int array2[] = {0};
+ Icontainer con1(array1, array1);
+ Icontainer con2(array1, array1 + 1);
+ Ocontainer con3(array2, array2);
+ VERIFY(set_difference(con1.begin(), con1.end(), con2.begin(), con2.end(),
+ con3.begin()).ptr == array2);
+}
+
+void
+test3()
+{
+ int array1[] = {1};
+ int array2[] = {0};
+ Icontainer con1(array1, array1 + 1);
+ Icontainer con2(array1, array1);
+ Ocontainer con3(array2, array2 + 1);
+ VERIFY(set_difference(con1.begin(), con1.end(), con2.begin(), con2.end(),
+ con3.begin()).ptr == array2 + 1);
+}
+
+void
+test4()
+{
+ int array1[]={0,1,1,2,4};
+ int array2[]={1,2,3};
+ int array3[6];
+ Icontainer con1(array1, array1 + 5);
+ Icontainer con2(array2, array2 + 3);
+ Ocontainer con3(array3, array3 + 3);
+ VERIFY(set_difference(con1.begin(), con1.end(), con2.begin(), con2.end(),
+ con3.begin()).ptr == array3 + 3);
+ VERIFY(array3[0] == 0 && array3[1] == 1 && array3[2] == 4);
+}
+
+struct S
+{
+ int i;
+ int j;
+ S() {}
+ S(int in)
+ {
+ if(in > 0)
+ {
+ i = in;
+ j = 1;
+ }
+ else
+ {
+ i = -in;
+ j = 0;
+ }
+ }
+};
+
+bool
+operator<(const S& s1, const S& s2)
+{ return s1.i < s2.i; }
+
+typedef test_container<S, input_iterator_wrapper> SIcontainer;
+typedef test_container<S, output_iterator_wrapper> SOcontainer;
+
+void
+test5()
+{
+ S array1[] = { -1, -1, -1, -2, -2, -3, -4};
+ S array2[] = { 1, 1, 1, 1, 2, 4, 4};
+ S array3[9];
+ SIcontainer con1(array1, array1 + 7);
+ SIcontainer con2(array2, array2 + 7);
+ SOcontainer con3(array3, array3 + 2);
+ VERIFY(set_difference(con1.begin(), con1.end(), con2.begin(), con2.end(),
+ con3.begin()).ptr == array3 + 2);
+ for(int i = 0; i < 2; ++i)
+ VERIFY(array3[i].j == 0);
+}
+
+int main()
+{
+ test1();
+ test2();
+ test3();
+ test4();
+ test5();
+}
+
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/set_difference/check_type.cc libstdc++-v3.so_7/testsuite/25_algorithms/set_difference/check_type.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/set_difference/check_type.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/set_difference/check_type.cc 2005-01-29 19:28:39.000000000 +0000
@@ -0,0 +1,44 @@
+// 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.
+
+// 25.3.5.4 [lib.set.difference]
+
+// { dg-do compile }
+
+#include <algorithm>
+#include <testsuite_iterators.h>
+using __gnu_test::input_iterator_wrapper;
+using __gnu_test::output_iterator_wrapper;
+
+struct S { };
+
+bool
+operator<(const S&, const S&) {return true;}
+
+struct X { };
+
+bool
+predicate(const X&, const X&) {return true;}
+
+output_iterator_wrapper<S>
+test1(input_iterator_wrapper<S>& in, output_iterator_wrapper<S>& out)
+{ return std::set_difference(in, in, in, in, out); }
+
+output_iterator_wrapper<X>
+test2(input_iterator_wrapper<X>& in, output_iterator_wrapper<X>& out)
+{ return std::set_difference(in, in, in, in, out, predicate); }
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/set_intersection/1.cc libstdc++-v3.so_7/testsuite/25_algorithms/set_intersection/1.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/set_intersection/1.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/set_intersection/1.cc 2005-01-29 19:29:18.000000000 +0000
@@ -0,0 +1,132 @@
+// 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.
+
+// 25.3.5.3 [lib.set.intersection]
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
+
+using __gnu_test::test_container;
+using __gnu_test::input_iterator_wrapper;
+using __gnu_test::output_iterator_wrapper;
+using std::set_intersection;
+
+typedef test_container<int, input_iterator_wrapper> Icontainer;
+typedef test_container<int, output_iterator_wrapper> Ocontainer;
+
+void
+test1()
+{
+ int array1[1], array2[1];
+ Icontainer con1(array1, array1);
+ Icontainer con2(array1, array1);
+ Ocontainer con3(array2, array2);
+ VERIFY(set_intersection(con1.begin(), con1.end(), con2.begin(), con2.end(),
+ con3.begin()).ptr == array2);
+}
+
+void
+test2()
+{
+ int array1[] = {1};
+ int array2[] = {0};
+ Icontainer con1(array1, array1);
+ Icontainer con2(array1, array1 + 1);
+ Ocontainer con3(array2, array2);
+ VERIFY(set_intersection(con1.begin(), con1.end(), con2.begin(), con2.end(),
+ con3.begin()).ptr == array2);
+}
+
+void
+test3()
+{
+ int array1[] = {1};
+ int array2[] = {0};
+ Icontainer con1(array1, array1 + 1);
+ Icontainer con2(array1, array1);
+ Ocontainer con3(array2, array2);
+ VERIFY(set_intersection(con1.begin(), con1.end(), con2.begin(), con2.end(),
+ con3.begin()).ptr == array2);
+}
+
+void
+test4()
+{
+ int array1[]={0,1,1,2,4};
+ int array2[]={1,2,3};
+ int array3[6];
+ Icontainer con1(array1, array1 + 5);
+ Icontainer con2(array2, array2 + 3);
+ Ocontainer con3(array3, array3 + 2);
+ VERIFY(set_intersection(con1.begin(), con1.end(), con2.begin(), con2.end(),
+ con3.begin()).ptr == array3 + 2);
+ VERIFY(array3[0] == 1 && array3[1] == 2);
+}
+
+struct S
+{
+ int i;
+ int j;
+ S() {}
+ S(int in)
+ {
+ if(in > 0)
+ {
+ i = in;
+ j = 1;
+ }
+ else
+ {
+ i = -in;
+ j = 0;
+ }
+ }
+};
+
+bool
+operator<(const S& s1, const S& s2)
+{ return s1.i < s2.i; }
+
+typedef test_container<S, input_iterator_wrapper> SIcontainer;
+typedef test_container<S, output_iterator_wrapper> SOcontainer;
+
+void
+test5()
+{
+ S array1[] = { -1, -1, -1, -2, -2, -4};
+ S array2[] = { 1, 1, 1, 1, 2, 3, 4, 4};
+ S array3[5];
+ SIcontainer con1(array1, array1 + 6);
+ SIcontainer con2(array2, array2 + 8);
+ SOcontainer con3(array3, array3 + 5);
+ VERIFY(set_intersection(con1.begin(), con1.end(), con2.begin(), con2.end(),
+ con3.begin()).ptr == array3 + 5);
+ for(int i = 0; i < 5; ++i)
+ VERIFY(array3[i].j == 0);
+}
+
+int main()
+{
+ test1();
+ test2();
+ test3();
+ test4();
+ test5();
+}
+
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/set_intersection/check_type.cc libstdc++-v3.so_7/testsuite/25_algorithms/set_intersection/check_type.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/set_intersection/check_type.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/set_intersection/check_type.cc 2005-01-29 19:29:32.000000000 +0000
@@ -0,0 +1,44 @@
+// 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.
+
+// 25.3.5.3 [lib.set.intersection]
+
+// { dg-do compile }
+
+#include <algorithm>
+#include <testsuite_iterators.h>
+using __gnu_test::input_iterator_wrapper;
+using __gnu_test::output_iterator_wrapper;
+
+struct S { };
+
+bool
+operator<(const S&, const S&) {return true;}
+
+struct X { };
+
+bool
+predicate(const X&, const X&) {return true;}
+
+output_iterator_wrapper<S>
+test1(input_iterator_wrapper<S>& in, output_iterator_wrapper<S>& out)
+{ return std::set_intersection(in, in, in, in, out); }
+
+output_iterator_wrapper<X>
+test2(input_iterator_wrapper<X>& in, output_iterator_wrapper<X>& out)
+{ return std::set_intersection(in, in, in, in, out, predicate); }
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/set_symmetric_difference/1.cc libstdc++-v3.so_7/testsuite/25_algorithms/set_symmetric_difference/1.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/set_symmetric_difference/1.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/set_symmetric_difference/1.cc 2005-01-29 18:10:44.000000000 +0000
@@ -0,0 +1,134 @@
+// 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.
+
+// 25.3.5.5 [lib.set.symmetric.difference]
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
+
+using __gnu_test::test_container;
+using __gnu_test::input_iterator_wrapper;
+using __gnu_test::output_iterator_wrapper;
+using std::set_symmetric_difference;
+
+typedef test_container<int, input_iterator_wrapper> Icontainer;
+typedef test_container<int, output_iterator_wrapper> Ocontainer;
+
+void
+test1()
+{
+ int array1[1], array2[1];
+ Icontainer con1(array1, array1);
+ Icontainer con2(array1, array1);
+ Ocontainer con3(array2, array2);
+ VERIFY(set_symmetric_difference(con1.begin(), con1.end(), con2.begin(),
+ con2.end(), con3.begin()).ptr == array2);
+}
+
+void
+test2()
+{
+ int array1[] = {1};
+ int array2[] = {0};
+ Icontainer con1(array1, array1);
+ Icontainer con2(array1, array1 + 1);
+ Ocontainer con3(array2, array2 + 1);
+ VERIFY(set_symmetric_difference(con1.begin(), con1.end(), con2.begin(),
+ con2.end(), con3.begin()).ptr == array2 + 1);
+}
+
+void
+test3()
+{
+ int array1[] = {1};
+ int array2[] = {0};
+ Icontainer con1(array1, array1 + 1);
+ Icontainer con2(array1, array1);
+ Ocontainer con3(array2, array2 + 1);
+ VERIFY(set_symmetric_difference(con1.begin(), con1.end(), con2.begin(),
+ con2.end(), con3.begin()).ptr == array2 + 1);
+}
+
+void
+test4()
+{
+ int array1[]={0,1,1,2,4};
+ int array2[]={1,2,2,3};
+ int array3[5];
+ Icontainer con1(array1, array1 + 5);
+ Icontainer con2(array2, array2 + 4);
+ Ocontainer con3(array3, array3 + 5);
+ VERIFY(set_symmetric_difference(con1.begin(), con1.end(), con2.begin(),
+ con2.end(), con3.begin()).ptr == array3 + 5);
+ VERIFY(array3[0] == 0 && array3[1] == 1 && array3[2] == 2 &&
+ array3[3] == 3 && array3[4] == 4);
+}
+
+struct S
+{
+ int i;
+ int j;
+ S() {}
+ S(int in)
+ {
+ if(in > 0)
+ {
+ i = in;
+ j = 1;
+ }
+ else
+ {
+ i = -in;
+ j = 0;
+ }
+ }
+};
+
+bool
+operator<(const S& s1, const S& s2)
+{ return s1.i < s2.i; }
+
+typedef test_container<S, input_iterator_wrapper> SIcontainer;
+typedef test_container<S, output_iterator_wrapper> SOcontainer;
+
+void
+test5()
+{
+ S array1[] = { -1, -1, -2, -2, -4, -5};
+ S array2[] = { 1, 1, 1, 2, 3, 4};
+ S array3[4];
+ SIcontainer con1(array1, array1 + 6);
+ SIcontainer con2(array2, array2 + 6);
+ SOcontainer con3(array3, array3 + 4);
+ VERIFY(set_symmetric_difference(con1.begin(), con1.end(), con2.begin(),
+ con2.end(), con3.begin()).ptr == array3 + 4);
+ VERIFY(array3[0].j == 1 && array3[1].j == 0 && array3[2].j == 1 &&
+ array3[3].j == 0);
+}
+
+int
+main()
+{
+ test1();
+ test2();
+ test3();
+ test4();
+ test5();
+}
+
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/set_symmetric_difference/check_type.cc libstdc++-v3.so_7/testsuite/25_algorithms/set_symmetric_difference/check_type.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/set_symmetric_difference/check_type.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/set_symmetric_difference/check_type.cc 2005-01-29 19:29:55.000000000 +0000
@@ -0,0 +1,45 @@
+// 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.
+
+// 25.3.5.5 [lib.set.symmetric.difference]
+
+// { dg-do compile }
+
+#include <algorithm>
+#include <testsuite_iterators.h>
+using __gnu_test::input_iterator_wrapper;
+using __gnu_test::output_iterator_wrapper;
+
+struct S { };
+
+bool
+operator<(const S&, const S&) {return true;}
+
+struct X { };
+
+bool
+predicate(const X&, const X&) {return true;}
+
+output_iterator_wrapper<S>
+test1(input_iterator_wrapper<S>& in, output_iterator_wrapper<S>& out)
+{ return std::set_symmetric_difference(in, in, in, in, out); }
+
+output_iterator_wrapper<X>
+test2(input_iterator_wrapper<X>& in, output_iterator_wrapper<X>& out)
+{ return std::set_symmetric_difference(in, in, in, in, out, predicate);
+}
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/set_union/1.cc libstdc++-v3.so_7/testsuite/25_algorithms/set_union/1.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/set_union/1.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/set_union/1.cc 2005-01-29 19:30:26.000000000 +0000
@@ -0,0 +1,137 @@
+// 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.
+
+// 25.3.5.2 [lib.set.union]
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
+
+using __gnu_test::test_container;
+using __gnu_test::input_iterator_wrapper;
+using __gnu_test::output_iterator_wrapper;
+using std::set_union;
+
+typedef test_container<int, input_iterator_wrapper> Icontainer;
+typedef test_container<int, output_iterator_wrapper> Ocontainer;
+
+void
+test1()
+{
+ int array1[1], array2[1];
+ Icontainer con1(array1, array1);
+ Icontainer con2(array1, array1);
+ Ocontainer con3(array2, array2);
+ VERIFY(set_union(con1.begin(), con1.end(), con2.begin(), con2.end(),
+ con3.begin()).ptr == array2);
+}
+
+void
+test2()
+{
+ int array1[] = {1};
+ int array2[] = {0};
+ Icontainer con1(array1, array1);
+ Icontainer con2(array1, array1 + 1);
+ Ocontainer con3(array2, array2 + 1);
+ VERIFY(set_union(con1.begin(), con1.end(), con2.begin(), con2.end(),
+ con3.begin()).ptr == array2 + 1);
+ VERIFY(array2[0] == 1);
+}
+
+void
+test3()
+{
+ int array1[] = {1};
+ int array2[] = {0};
+ Icontainer con1(array1, array1 + 1);
+ Icontainer con2(array1, array1);
+ Ocontainer con3(array2, array2 + 1);
+ VERIFY(set_union(con1.begin(), con1.end(), con2.begin(), con2.end(),
+ con3.begin()).ptr == array2 + 1);
+ VERIFY(array2[0] == 1);
+}
+
+void
+test4()
+{
+ int array1[]={0,1,1,2,4};
+ int array2[]={1,2,3};
+ int array3[6];
+ Icontainer con1(array1, array1 + 5);
+ Icontainer con2(array2, array2 + 3);
+ Ocontainer con3(array3, array3 + 6);
+ VERIFY(set_union(con1.begin(), con1.end(), con2.begin(), con2.end(),
+ con3.begin()).ptr == array3 + 6);
+ VERIFY(array3[0] == 0 && array3[1] == 1 && array3[2] == 1 &&
+ array3[3] == 2 && array3[4] == 3 && array3[5] == 4);
+}
+
+struct S
+{
+ int i;
+ int j;
+ S() {}
+ S(int in)
+ {
+ if(in > 0)
+ {
+ i = in;
+ j = 1;
+ }
+ else
+ {
+ i = -in;
+ j = 0;
+ }
+ }
+};
+
+bool
+operator<(const S& s1, const S& s2)
+{ return s1.i < s2.i; }
+
+typedef test_container<S, input_iterator_wrapper> SIcontainer;
+typedef test_container<S, output_iterator_wrapper> SOcontainer;
+
+void
+test5()
+{
+ S array1[] = { -1, -1, -1, -2, -2, -4};
+ S array2[] = { 1, 1, 1, 1, 2, 3, 4, 4};
+ S array3[9];
+ SIcontainer con1(array1, array1 + 6);
+ SIcontainer con2(array2, array2 + 8);
+ SOcontainer con3(array3, array3 + 9);
+ VERIFY(set_union(con1.begin(), con1.end(), con2.begin(), con2.end(),
+ con3.begin()).ptr == array3 + 9);
+ VERIFY(array3[0].j == 0 && array3[1].j == 0 && array3[2].j == 0 &&
+ array3[3].j == 1 && array3[4].j == 0 && array3[5].j == 0 &&
+ array3[6].j == 1 && array3[7].j == 0 && array3[8].j == 1);
+}
+
+int
+main()
+{
+ test1();
+ test2();
+ test3();
+ test4();
+ test5();
+}
+
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/set_union/check_type.cc libstdc++-v3.so_7/testsuite/25_algorithms/set_union/check_type.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/set_union/check_type.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/set_union/check_type.cc 2005-01-29 19:30:39.000000000 +0000
@@ -0,0 +1,44 @@
+// 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.
+
+// 25.3.5.2 [lib.set.union]
+
+// { dg-do compile }
+
+#include <algorithm>
+#include <testsuite_iterators.h>
+using __gnu_test::input_iterator_wrapper;
+using __gnu_test::output_iterator_wrapper;
+
+struct S { };
+
+bool
+operator<(const S&, const S&) {return true;}
+
+struct X { };
+
+bool
+predicate(const X&, const X&) {return true;}
+
+output_iterator_wrapper<S>
+test1(input_iterator_wrapper<S>& in, output_iterator_wrapper<S>& out)
+{ return std::set_union(in, in, in, in, out); }
+
+output_iterator_wrapper<X>
+test2(input_iterator_wrapper<X>& in, output_iterator_wrapper<X>& out)
+{ return std::set_union(in, in, in, in, out, predicate); }
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/stable_sort/1.cc libstdc++-v3.so_7/testsuite/25_algorithms/stable_sort/1.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/stable_sort/1.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/stable_sort/1.cc 2005-01-29 19:31:07.000000000 +0000
@@ -0,0 +1,90 @@
+// 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.
+
+// 25.3.1.2 [lib.stable.sort]
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
+
+using __gnu_test::test_container;
+using __gnu_test::random_access_iterator_wrapper;
+using std::stable_sort;
+
+typedef test_container<int, random_access_iterator_wrapper> Container;
+
+void
+test1()
+{
+ int array[]={0};
+ Container con(array, array);
+ stable_sort(con.begin(), con.end());
+}
+
+void
+test2()
+{
+ int array[] = {6, 5, 4, 3, 2, 1, 0};
+ Container con(array, array + 7);
+ stable_sort(con.begin(), con.end());
+ VERIFY(array[0] == 0 && array[1] == 1 && array[2] == 2 &&
+ array[3] == 3 && array[4] == 4 && array[5] == 5 &&
+ array[6] == 6);
+}
+struct S
+{
+ int i;
+ int j;
+ S() {}
+ S(int in)
+ {
+ if(in > 0)
+ {
+ i = in;
+ j = 1;
+ }
+ else
+ {
+ i = -in;
+ j = 0;
+ }
+ }
+};
+
+bool
+operator<(const S& s1, const S& s2)
+{ return s1.i < s2.i; }
+
+void
+test3()
+{
+
+ S array[] = {-1, -2, 1, 2, -3 ,-5 ,3 , -4, 5, 4};
+ test_container<S, random_access_iterator_wrapper> con(array,array + 10);
+ stable_sort(con.begin(), con.end());
+ for(int i = 0; i < 10; ++i)
+ VERIFY(array[i].j == i % 2);
+}
+
+int
+main()
+{
+ test1();
+ test2();
+ test3();
+}
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/stable_sort/check_type.cc libstdc++-v3.so_7/testsuite/25_algorithms/stable_sort/check_type.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/stable_sort/check_type.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/stable_sort/check_type.cc 2005-01-29 19:31:20.000000000 +0000
@@ -0,0 +1,49 @@
+// 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.
+
+// 25.3.1.1 [lib.stable.sort]
+
+// { dg-do compile }
+
+#include <algorithm>
+#include <testsuite_iterators.h>
+
+using __gnu_test::random_access_iterator_wrapper;
+
+struct S { };
+
+bool
+operator<(const S&, const S&) {return true;}
+
+struct X { };
+
+bool
+predicate(const X&, const X&) {return true;}
+
+void
+test1(random_access_iterator_wrapper<S>& s)
+{
+ std::stable_sort(s, s);
+}
+
+void
+test2(random_access_iterator_wrapper<X>& x)
+{
+ std::stable_sort(x, x, predicate);
+}
+
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/unique_copy/1.cc libstdc++-v3.so_7/testsuite/25_algorithms/unique_copy/1.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/unique_copy/1.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/unique_copy/1.cc 2005-01-29 19:32:39.000000000 +0000
@@ -0,0 +1,54 @@
+// 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.
+
+// 25.5.8 [lib.alg.unique]
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
+
+using __gnu_test::test_container;
+using __gnu_test::forward_iterator_wrapper;
+using std::unique;
+
+typedef test_container<int, forward_iterator_wrapper> Container;
+int array1[] = {0, 0, 0, 1, 1, 1};
+int array2[2];
+
+void
+test1()
+{
+ Container con1(array1, array1);
+ Container con2(array2, array2);
+ VERIFY(unique_copy(con1.begin(), con1.end(), con2.begin()).ptr == array2);
+}
+
+void
+test2()
+{
+ Container con1(array1, array1 + 6);
+ Container con2(array2, array2 + 2);
+ VERIFY(unique_copy(con1.begin(), con1.end(), con2.begin()).ptr
+ == array2 + 2);
+}
+
+int
+main()
+{
+ test1();
+}
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/unique_copy/check_type.cc libstdc++-v3.so_7/testsuite/25_algorithms/unique_copy/check_type.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/unique_copy/check_type.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/unique_copy/check_type.cc 2005-01-29 19:31:57.000000000 +0000
@@ -0,0 +1,55 @@
+// 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.
+
+// 25.5.8 [lib.alg.unique_copy]
+
+// { dg-do compile }
+
+#include <algorithm>
+#include <testsuite_iterators.h>
+
+using __gnu_test::input_iterator_wrapper;
+using __gnu_test::output_iterator_wrapper;
+
+struct S1 { };
+
+struct S2
+{
+ S2(const S1& s1) {}
+};
+
+bool
+operator==(const S1&, const S1&) {return true;}
+
+struct X1 { };
+
+struct X2
+{
+ X2(const X1& x1) {}
+};
+
+bool
+predicate(const X1&, const X1&) {return true;}
+
+output_iterator_wrapper<S2>
+test1(input_iterator_wrapper<S1>& s1, output_iterator_wrapper<S2>& s2)
+{ return std::unique_copy(s1, s1, s2); }
+
+output_iterator_wrapper<X2>
+test2(input_iterator_wrapper<X1>& x1, output_iterator_wrapper<X2>& x2)
+{ return std::unique_copy(x1, x1, x2, predicate); }
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/upper_bound/1.cc libstdc++-v3.so_7/testsuite/25_algorithms/upper_bound/1.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/upper_bound/1.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/upper_bound/1.cc 2005-01-29 19:32:50.000000000 +0000
@@ -0,0 +1,47 @@
+// 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.
+
+// 25.3.3.2 [lib.upper.bound]
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
+
+using __gnu_test::test_container;
+using __gnu_test::forward_iterator_wrapper;
+using std::upper_bound;
+
+typedef test_container<int, forward_iterator_wrapper> Container;
+int array[] = {0, 0, 0, 0, 1, 1, 1, 1};
+
+void
+test1()
+{
+ for(int i = 0; i < 5; ++i)
+ for(int j = 4; j < 7; ++j)
+ {
+ Container con(array + i, array + j);
+ VERIFY(upper_bound(con.begin(), con.end(), 0).ptr == array + 4);
+ }
+}
+
+int
+main()
+{
+ test1();
+}
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/25_algorithms/upper_bound/check_type.cc libstdc++-v3.so_7/testsuite/25_algorithms/upper_bound/check_type.cc
--- libstdc++-v3.so_7-clean/testsuite/25_algorithms/upper_bound/check_type.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/25_algorithms/upper_bound/check_type.cc 2005-01-29 19:39:06.000000000 +0000
@@ -0,0 +1,44 @@
+// 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.
+
+// 25.3.3.2 [lib.upper.bound]
+
+// { dg-do compile }
+
+#include <algorithm>
+#include <testsuite_iterators.h>
+
+using __gnu_test::forward_iterator_wrapper;
+
+struct S { };
+
+bool
+operator<(const S&, const S&) {return true;}
+
+struct X { };
+
+bool
+predicate(const X&, const X&) {return true;}
+
+forward_iterator_wrapper<S>
+test1(forward_iterator_wrapper<S>& s)
+{ return std::upper_bound(s, s, *s); }
+
+forward_iterator_wrapper<X>
+test2(forward_iterator_wrapper<X>& x)
+{ return std::upper_bound(x, x, *x, predicate); }
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/ext/median.cc libstdc++-v3.so_7/testsuite/ext/median.cc
--- libstdc++-v3.so_7-clean/testsuite/ext/median.cc 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/ext/median.cc 2005-01-22 14:01:51.000000000 +0000
@@ -0,0 +1,42 @@
+// 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.
+
+// median - SGI extension
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+
+bool pred(const int& l, const int& r)
+{
+ return l<r;
+}
+
+using std::__median;
+
+int main(void)
+{
+ const int i=1;
+ const int j=2;
+ const int k=3;
+ VERIFY(__median(i, j, k) == j && __median(i, j, k, pred) == j);
+ VERIFY(__median(i, k, j) == j && __median(i, k, j, pred) == j);
+ VERIFY(__median(j, i, k) == j && __median(j, i, k, pred) == j);
+ VERIFY(__median(j, k, i) == j && __median(j, k, i, pred) == j);
+ VERIFY(__median(k, i, j) == j && __median(k, i, j, pred) == j);
+ VERIFY(__median(k, j, i) == j && __median(k, j, i, pred) == j);
+}
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/ext/median.cc~ libstdc++-v3.so_7/testsuite/ext/median.cc~
--- libstdc++-v3.so_7-clean/testsuite/ext/median.cc~ 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/ext/median.cc~ 2005-01-22 13:57:51.000000000 +0000
@@ -0,0 +1,28 @@
+// 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.
+
+// median - SGI extension
+
+#include <algorithm>
+
+int main(void)
+{
+const int i=1;
+const int j=2;
+
+}
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/testsuite_iterators.h libstdc++-v3.so_7/testsuite/testsuite_iterators.h
--- libstdc++-v3.so_7-clean/testsuite/testsuite_iterators.h 2005-01-03 22:12:04.000000000 +0000
+++ libstdc++-v3.so_7/testsuite/testsuite_iterators.h 2005-01-29 19:58:52.000000000 +0000
@@ -77,7 +77,7 @@
{
writtento = new bool[this->last - this->first];
for(int i = 0; i < this->last - this->first; i++)
- writtento = false;
+ writtento[i] = false;
}
~OutputContainer()
@@ -96,12 +96,13 @@
ptr(ptr_in), SharedInfo(SharedInfo_in)
{ }
+ template<class U>
void
- operator=(T& new_val)
+ operator=(U& new_val)
{
ITERATOR_VERIFY(SharedInfo->writtento[ptr - SharedInfo->first] == 0);
SharedInfo->writtento[ptr - SharedInfo->first] = 1;
- ptr = new_val;
+ *ptr = new_val;
}
};
@@ -149,9 +150,9 @@
operator++()
{
ITERATOR_VERIFY(SharedInfo && ptr < SharedInfo->last);
- ITERATOR_VERIFY(ptr>=SharedInfo->first);
+ ITERATOR_VERIFY(ptr>=SharedInfo->incrementedto);
ptr++;
- SharedInfo->first=ptr;
+ SharedInfo->incrementedto=ptr;
return *this;
}
@@ -423,7 +424,7 @@
operator--(int)
{
random_access_iterator_wrapper<T> tmp = *this;
- ++*this;
+ --*this;
return tmp;
}
@@ -444,7 +445,7 @@
}
random_access_iterator_wrapper
- operator+(ptrdiff_t n)
+ operator+(ptrdiff_t n) const
{
random_access_iterator_wrapper<T> tmp = *this;
return tmp += n;
@@ -455,22 +456,22 @@
{ return *this += -n; }
random_access_iterator_wrapper
- operator-(ptrdiff_t n)
+ operator-(ptrdiff_t n) const
{
random_access_iterator_wrapper<T> tmp = *this;
return tmp -= n;
}
ptrdiff_t
- operator-(const random_access_iterator_wrapper<T>& in)
+ operator-(const random_access_iterator_wrapper<T>& in) const
{
ITERATOR_VERIFY(this->SharedInfo == in.SharedInfo);
return this->ptr - in.ptr;
}
T&
- operator[](ptrdiff_t n)
- { return *(this + n); }
+ operator[](ptrdiff_t n) const
+ { return *(*this + n); }
bool
operator<(const random_access_iterator_wrapper<T>& in) const
diff -x CVS -durN libstdc++-v3.so_7-clean/testsuite/testsuite_iterators.h~ libstdc++-v3.so_7/testsuite/testsuite_iterators.h~
--- libstdc++-v3.so_7-clean/testsuite/testsuite_iterators.h~ 1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3.so_7/testsuite/testsuite_iterators.h~ 2005-01-29 15:16:16.000000000 +0000
@@ -0,0 +1,540 @@
+// -*- C++ -*-
+// Iterator Wrappers for the C++ library testsuite.
+//
+// Copyright (C) 2004 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.
+//
+// As a special exception, you may use this file as part of a free software
+// library without restriction. Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License. This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+// This file provides the following:
+//
+// input_iterator_wrapper, output_iterator_wrapper
+// forward_iterator_wrapper, bidirectional_iterator_wrapper and
+// random_access_wrapper, which attempt to exactly perform the requirements
+// of these types of iterators. These are constructed from the class
+// test_container, which is given two pointers to T and an iterator type.
+
+#include <testsuite_hooks.h>
+#include <iterator>
+
+#ifndef _TESTSUITE_ITERATORS
+#define _TESTSUITE_ITERATORS
+
+#ifdef DISABLE_ITERATOR_DEBUG
+#define ITERATOR_VERIFY(x)
+#else
+#define ITERATOR_VERIFY(x) VERIFY(x)
+#endif
+
+namespace __gnu_test
+{
+ /**
+ * @brief Simple container for holding two pointers.
+ *
+ * Note that input_iterator_wrapper changes first to denote
+ * how the valid range of == , ++, etc. change as the iterators are used.
+ */
+ template<typename T>
+ struct BoundsContainer
+ {
+ T* first;
+ T* last;
+ BoundsContainer(T* _first, T* _last)
+ : first(_first), last(_last)
+ { }
+ };
+
+ // Simple container for holding state of a set of output iterators.
+ template<typename T>
+ struct OutputContainer : public BoundsContainer<T>
+ {
+ T* incrementedto;
+ bool* writtento;
+ OutputContainer(T* _first, T* _last)
+ : BoundsContainer<T>(_first, _last), incrementedto(_first)
+ {
+ writtento = new bool[this->last - this->first];
+ for(int i = 0; i < this->last - this->first; i++)
+ writtento[i] = false;
+ }
+
+ ~OutputContainer()
+ { delete[] writtento; }
+ };
+
+ // Produced by output_iterator to allow limited writing to pointer
+ template<class T>
+ class WritableObject
+ {
+ T* ptr;
+
+ public:
+ OutputContainer<T>* SharedInfo;
+ WritableObject(T* ptr_in,OutputContainer<T>* SharedInfo_in):
+ ptr(ptr_in), SharedInfo(SharedInfo_in)
+ { }
+
+ template<class U>
+ void
+ operator=(U& new_val)
+ {
+ ITERATOR_VERIFY(SharedInfo->writtento[ptr - SharedInfo->first] == 0);
+ SharedInfo->writtento[ptr - SharedInfo->first] = 1;
+ *ptr = new_val;
+ }
+ };
+
+ /**
+ * @brief output_iterator wrapper for pointer
+ *
+ * This class takes a pointer and wraps it to provide exactly
+ * the requirements of a output_iterator. It should not be
+ * instansiated directly, but generated from a test_container
+ */
+ template<class T>
+ struct output_iterator_wrapper: public std::iterator
+ <std::output_iterator_tag, T, ptrdiff_t, T*, T&>
+ {
+ typedef OutputContainer<T> ContainerType;
+ T* ptr;
+ ContainerType* SharedInfo;
+
+ output_iterator_wrapper(T* _ptr, ContainerType* SharedInfo_in)
+ :ptr(_ptr), SharedInfo(SharedInfo_in)
+ {
+ ITERATOR_VERIFY(ptr >= SharedInfo->first && ptr <= SharedInfo->last);
+ }
+
+ output_iterator_wrapper(const output_iterator_wrapper& in)
+ :ptr(in.ptr), SharedInfo(in.SharedInfo)
+ { }
+
+ WritableObject<T>
+ operator*() const
+ {
+ ITERATOR_VERIFY(ptr < SharedInfo->last);
+ ITERATOR_VERIFY(SharedInfo->writtento[ptr - SharedInfo->first] == false);
+ return WritableObject<T>(ptr, SharedInfo);
+ }
+
+ output_iterator_wrapper&
+ operator=(const output_iterator_wrapper& in)
+ {
+ ptr = in.ptr;
+ SharedInfo = in.SharedInfo;
+ }
+
+ output_iterator_wrapper&
+ operator++()
+ {
+ ITERATOR_VERIFY(SharedInfo && ptr < SharedInfo->last);
+ ITERATOR_VERIFY(ptr>=SharedInfo->incrementedto);
+ ptr++;
+ SharedInfo->incrementedto=ptr;
+ return *this;
+ }
+
+ output_iterator_wrapper
+ operator++(int)
+ {
+ output_iterator_wrapper<T> tmp = *this;
+ ++*this;
+ return tmp;
+ }
+
+ };
+
+ /**
+ * @brief input_iterator wrapper for pointer
+ *
+ * This class takes a pointer and wraps it to provide exactly
+ * the requirements of a input_iterator. It should not be
+ * instansiated directly, but generated from a test_container
+ */
+ template<class T>
+ class input_iterator_wrapper:public std::iterator
+ <std::input_iterator_tag, T, ptrdiff_t, T*, T&>
+ {
+ protected:
+ input_iterator_wrapper()
+ { }
+
+ public:
+ typedef BoundsContainer<T> ContainerType;
+ T* ptr;
+ ContainerType* SharedInfo;
+
+ input_iterator_wrapper(T* _ptr, ContainerType* SharedInfo_in)
+ : ptr(_ptr), SharedInfo(SharedInfo_in)
+ { ITERATOR_VERIFY(ptr >= SharedInfo->first && ptr <= SharedInfo->last); }
+
+ input_iterator_wrapper(const input_iterator_wrapper& in)
+ : ptr(in.ptr), SharedInfo(in.SharedInfo)
+ { }
+
+ bool
+ operator==(const input_iterator_wrapper& in) const
+ {
+ ITERATOR_VERIFY(SharedInfo != NULL && SharedInfo == in.SharedInfo);
+ ITERATOR_VERIFY(ptr>=SharedInfo->first && in.ptr>=SharedInfo->first);
+ return ptr == in.ptr;
+ }
+
+ bool
+ operator!=(const input_iterator_wrapper& in) const
+ {
+ return !(*this == in);
+ }
+
+ T&
+ operator*() const
+ {
+ ITERATOR_VERIFY(SharedInfo && ptr < SharedInfo->last);
+ ITERATOR_VERIFY(ptr >= SharedInfo->first);
+ return *ptr;
+ }
+
+ T*
+ operator->() const
+ {
+ return &**this;
+ }
+
+ input_iterator_wrapper&
+ operator=(const input_iterator_wrapper& in)
+ {
+ ptr = in.ptr;
+ SharedInfo = in.SharedInfo;
+ return *this;
+ }
+
+ input_iterator_wrapper&
+ operator++()
+ {
+ ITERATOR_VERIFY(SharedInfo && ptr < SharedInfo->last);
+ ITERATOR_VERIFY(ptr>=SharedInfo->first);
+ ptr++;
+ SharedInfo->first=ptr;
+ return *this;
+ }
+
+ void
+ operator++(int)
+ {
+ ++*this;
+ }
+ };
+
+
+ /**
+ * @brief forward_iterator wrapper for pointer
+ *
+ * This class takes a pointer and wraps it to provide exactly
+ * the requirements of a forward_iterator. It should not be
+ * instansiated directly, but generated from a test_container
+ */
+ template<class T>
+ struct forward_iterator_wrapper:public input_iterator_wrapper<T>
+ {
+ typedef BoundsContainer<T> ContainerType;
+ typedef std::forward_iterator_tag iterator_category;
+ forward_iterator_wrapper(T* _ptr, ContainerType* SharedInfo_in)
+ :input_iterator_wrapper<T>(_ptr, SharedInfo_in)
+ { }
+
+ forward_iterator_wrapper(const forward_iterator_wrapper& in)
+ :input_iterator_wrapper<T>(in)
+ { }
+
+ forward_iterator_wrapper()
+ {
+ this->ptr = NULL;
+ this->SharedInfo = NULL;
+ }
+
+ T&
+ operator*() const
+ {
+ ITERATOR_VERIFY(this->SharedInfo && this->ptr < this->SharedInfo->last);
+ return *(this->ptr);
+ }
+
+ T*
+ operator->() const
+ { return &**this; }
+
+ forward_iterator_wrapper&
+ operator++()
+ {
+ ITERATOR_VERIFY(this->SharedInfo && this->ptr < this->SharedInfo->last);
+ this->ptr++;
+ return *this;
+ }
+
+ forward_iterator_wrapper
+ operator++(int)
+ {
+ forward_iterator_wrapper<T> tmp = *this;
+ ++*this;
+ return tmp;
+ }
+ };
+
+ /**
+ * @brief bidirectional_iterator wrapper for pointer
+ *
+ * This class takes a pointer and wraps it to provide exactly
+ * the requirements of a forward_iterator. It should not be
+ * instansiated directly, but generated from a test_container
+ */
+ template<class T>
+ struct bidirectional_iterator_wrapper:public forward_iterator_wrapper<T>
+ {
+ typedef BoundsContainer<T> ContainerType;
+ typedef std::bidirectional_iterator_tag iterator_category;
+ bidirectional_iterator_wrapper(T* _ptr, ContainerType* SharedInfo_in)
+ :forward_iterator_wrapper<T>(_ptr, SharedInfo_in)
+ { }
+
+ bidirectional_iterator_wrapper(const bidirectional_iterator_wrapper& in)
+ :forward_iterator_wrapper<T>(in)
+ { }
+
+ bidirectional_iterator_wrapper(): forward_iterator_wrapper<T>()
+ { }
+
+ bidirectional_iterator_wrapper&
+ operator=(const bidirectional_iterator_wrapper& in)
+ {
+ this->ptr = in.ptr;
+ this->SharedInfo = in.SharedInfo;
+ return *this;
+ }
+
+ bidirectional_iterator_wrapper&
+ operator++()
+ {
+ ITERATOR_VERIFY(this->SharedInfo && this->ptr < this->SharedInfo->last);
+ this->ptr++;
+ return *this;
+ }
+
+ bidirectional_iterator_wrapper
+ operator++(int)
+ {
+ bidirectional_iterator_wrapper<T> tmp = *this;
+ ++*this;
+ return tmp;
+ }
+
+ bidirectional_iterator_wrapper&
+ operator--()
+ {
+ ITERATOR_VERIFY(this->SharedInfo && this->ptr > this->SharedInfo->first);
+ this->ptr--;
+ return *this;
+ }
+
+ bidirectional_iterator_wrapper
+ operator--(int)
+ {
+ bidirectional_iterator_wrapper<T> tmp = *this;
+ --*this;
+ return tmp;
+ }
+ };
+
+ /**
+ * @brief random_access_iterator wrapper for pointer
+ *
+ * This class takes a pointer and wraps it to provide exactly
+ * the requirements of a forward_iterator. It should not be
+ * instansiated directly, but generated from a test_container
+ */
+ template<class T>
+ struct random_access_iterator_wrapper:public bidirectional_iterator_wrapper<T>
+ {
+ typedef BoundsContainer<T> ContainerType;
+ typedef std::random_access_iterator_tag iterator_category;
+ random_access_iterator_wrapper(T* _ptr, ContainerType* SharedInfo_in)
+ : bidirectional_iterator_wrapper<T>(_ptr, SharedInfo_in)
+ { }
+
+ random_access_iterator_wrapper(const random_access_iterator_wrapper<T>& in)
+ : bidirectional_iterator_wrapper<T>(in)
+ { }
+
+ random_access_iterator_wrapper():bidirectional_iterator_wrapper<T>()
+ { }
+
+ random_access_iterator_wrapper&
+ operator=(const random_access_iterator_wrapper& in)
+ {
+ this->ptr = in.ptr;
+ this->SharedInfo = in.SharedInfo;
+ }
+
+ random_access_iterator_wrapper&
+ operator++()
+ {
+ ITERATOR_VERIFY(this->SharedInfo && this->ptr < this->SharedInfo->last);
+ this->ptr++;
+ return *this;
+ }
+
+ random_access_iterator_wrapper
+ operator++(int)
+ {
+ random_access_iterator_wrapper<T> tmp = *this;
+ ++*this;
+ return tmp;
+ }
+
+ random_access_iterator_wrapper&
+ operator--()
+ {
+ ITERATOR_VERIFY(this->SharedInfo && this->ptr > this->SharedInfo->first);
+ this->ptr--;
+ return *this;
+ }
+
+ random_access_iterator_wrapper
+ operator--(int)
+ {
+ random_access_iterator_wrapper<T> tmp = *this;
+ --*this;
+ return tmp;
+ }
+
+ random_access_iterator_wrapper&
+ operator+=(ptrdiff_t n)
+ {
+ if(n > 0)
+ {
+ ITERATOR_VERIFY(n <= this->SharedInfo->last - this->ptr);
+ this->ptr += n;
+ }
+ else
+ {
+ ITERATOR_VERIFY(n <= this->ptr - this->SharedInfo->first);
+ this->ptr += n;
+ }
+ return *this;
+ }
+
+ random_access_iterator_wrapper
+ operator+(ptrdiff_t n)
+ {
+ random_access_iterator_wrapper<T> tmp = *this;
+ return tmp += n;
+ }
+
+ random_access_iterator_wrapper&
+ operator-=(ptrdiff_t n)
+ { return *this += -n; }
+
+ random_access_iterator_wrapper
+ operator-(ptrdiff_t n)
+ {
+ random_access_iterator_wrapper<T> tmp = *this;
+ return tmp -= n;
+ }
+
+ ptrdiff_t
+ operator-(const random_access_iterator_wrapper<T>& in)
+ {
+ ITERATOR_VERIFY(this->SharedInfo == in.SharedInfo);
+ return this->ptr - in.ptr;
+ }
+
+ T&
+ operator[](ptrdiff_t n)
+ { return *(this + n); }
+
+ bool
+ operator<(const random_access_iterator_wrapper<T>& in) const
+ {
+ ITERATOR_VERIFY(this->SharedInfo == in.SharedInfo);
+ return this->ptr < in.ptr;
+ }
+
+ bool
+ operator>(const random_access_iterator_wrapper<T>& in) const
+ {
+ return in < *this;
+ }
+
+ bool
+ operator>=(const random_access_iterator_wrapper<T>& in) const
+ {
+ return !(*this < in);
+ }
+
+ bool
+ operator<=(const random_access_iterator_wrapper<T>& in) const
+ {
+ return !(*this > in);
+ }
+ };
+
+
+ /**
+ * @brief A container-type class for holding iterator wrappers
+ * test_container takes two parameters, a class T and an iterator
+ * wrapper templated by T (for example forward_iterator_wrapper<T>.
+ * It takes two pointers representing a range and presents them as
+ * a container of iterators.
+ */
+ template <class T, template<class T> class ItType>
+ struct test_container
+ {
+ typename ItType<T>::ContainerType bounds;
+ test_container(T* _first, T* _last):bounds(_first, _last)
+ { }
+
+ ItType<T>
+ it(int pos)
+ {
+ ITERATOR_VERIFY(pos >= 0 && pos <= (bounds.last - bounds.first));
+ return ItType<T>(bounds.first + pos, &bounds);
+ }
+
+ ItType<T>
+ it(T* pos)
+ {
+ ITERATOR_VERIFY(pos >= bounds.first && pos <= bounds.last);
+ return ItType<T>(pos, &bounds);
+ }
+
+ ItType<T>
+ begin()
+ { return it(bounds.first); }
+
+ ItType<T>
+ end()
+ { return it(bounds.last); }
+ };
+}
+#endif
Index: stl_algo.h
===================================================================
RCS file: /cvsroot/gcc/gcc/libstdc++-v3/include/bits/stl_algo.h,v
retrieving revision 1.47.6.4
diff -u -r1.47.6.4 stl_algo.h
--- stl_algo.h 8 Nov 2004 21:31:23 -0000 1.47.6.4
+++ stl_algo.h 29 Jan 2005 20:25:48 -0000
@@ -1,6 +1,6 @@
// Algorithm implementation -*- C++ -*-
-// Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+// Copyright (C) 2001, 2002, 2003, 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
@@ -64,44 +64,13 @@
#include <bits/stl_heap.h>
#include <bits/stl_tempbuf.h> // for _Temporary_buffer
#include <debug/debug.h>
+#include <bits/predefined_ops.h>
// See concept_check.h for the __glibcxx_*_requires macros.
namespace std
{
- /**
- * @brief Find the median of three values.
- * @param a A value.
- * @param b A value.
- * @param c A value.
- * @return One of @p a, @p b or @p c.
- *
- * If @c {l,m,n} is some convolution of @p {a,b,c} such that @c l<=m<=n
- * then the value returned will be @c m.
- * This is an SGI extension.
- * @ingroup SGIextensions
- */
- template<typename _Tp>
- inline const _Tp&
- __median(const _Tp& __a, const _Tp& __b, const _Tp& __c)
- {
- // concept requirements
- __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
- if (__a < __b)
- if (__b < __c)
- return __b;
- else if (__a < __c)
- return __c;
- else
- return __a;
- else if (__a < __c)
- return __a;
- else if (__b < __c)
- return __c;
- else
- return __b;
- }
-
+
/**
* @brief Find the median of three values using a predicate for comparison.
* @param a A value.
@@ -137,6 +106,27 @@
}
/**
+ * @brief Find the median of three values.
+ * @param a A value.
+ * @param b A value.
+ * @param c A value.
+ * @return One of @p a, @p b or @p c.
+ *
+ * If @c {l,m,n} is some convolution of @p {a,b,c} such that @c l<=m<=n
+ * then the value returned will be @c m.
+ * This is an SGI extension.
+ * @ingroup SGIextensions
+ */
+ template<typename _Tp>
+ inline const _Tp&
+ __median(const _Tp& __a, const _Tp& __b, const _Tp& __c)
+ {
+ // concept requirements
+ __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
+ return std::__median(__a, __b, __c, __gnu_cxx::__ops::less());
+ }
+
+ /**
* @brief Apply a function to every element of a sequence.
* @param first An input iterator.
* @param last An input iterator.
@@ -337,34 +327,7 @@
std::__iterator_category(__first));
}
- /**
- * @brief Find two adjacent values in a sequence that are equal.
- * @param first A forward iterator.
- * @param last A forward iterator.
- * @return The first iterator @c i such that @c i and @c i+1 are both
- * valid iterators in @p [first,last) and such that @c *i == @c *(i+1),
- * or @p last if no such iterator exists.
- */
- template<typename _ForwardIterator>
- _ForwardIterator
- adjacent_find(_ForwardIterator __first, _ForwardIterator __last)
- {
- // concept requirements
- __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
- __glibcxx_function_requires(_EqualityComparableConcept<
- typename iterator_traits<_ForwardIterator>::value_type>)
- __glibcxx_requires_valid_range(__first, __last);
- if (__first == __last)
- return __last;
- _ForwardIterator __next = __first;
- while(++__next != __last)
- {
- if (*__first == *__next)
- return __first;
- __first = __next;
- }
- return __last;
- }
+
/**
* @brief Find two adjacent values in a sequence using a predicate.
@@ -400,6 +363,24 @@
}
/**
+ * @brief Find two adjacent values in a sequence that are equal.
+ * @param first A forward iterator.
+ * @param last A forward iterator.
+ * @return The first iterator @c i such that @c i and @c i+1 are both
+ * valid iterators in @p [first,last) and such that @c *i == @c *(i+1),
+ * or @p last if no such iterator exists.
+ */
+ template<typename _ForwardIterator>
+ _ForwardIterator
+ adjacent_find(_ForwardIterator __first, _ForwardIterator __last)
+ {
+ // concept requirements
+ __glibcxx_function_requires(_EqualityComparableConcept<
+ typename iterator_traits<_ForwardIterator>::value_type>)
+ return std::adjacent_find(__first, __last, __gnu_cxx::__ops::equal_to());
+ }
+
+ /**
* @brief Count the number of copies of a value in a sequence.
* @param first An input iterator.
* @param last An input iterator.
@@ -448,81 +429,7 @@
return __n;
}
- /**
- * @brief Search a sequence for a matching sub-sequence.
- * @param first1 A forward iterator.
- * @param last1 A forward iterator.
- * @param first2 A forward iterator.
- * @param last2 A forward iterator.
- * @return The first iterator @c i in the range
- * @p [first1,last1-(last2-first2)) such that @c *(i+N) == @p *(first2+N)
- * for each @c N in the range @p [0,last2-first2), or @p last1 if no
- * such iterator exists.
- *
- * Searches the range @p [first1,last1) for a sub-sequence that compares
- * equal value-by-value with the sequence given by @p [first2,last2) and
- * returns an iterator to the first element of the sub-sequence, or
- * @p last1 if the sub-sequence is not found.
- *
- * Because the sub-sequence must lie completely within the range
- * @p [first1,last1) it must start at a position less than
- * @p last1-(last2-first2) where @p last2-first2 is the length of the
- * sub-sequence.
- * This means that the returned iterator @c i will be in the range
- * @p [first1,last1-(last2-first2))
- */
- template<typename _ForwardIterator1, typename _ForwardIterator2>
- _ForwardIterator1
- search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
- _ForwardIterator2 __first2, _ForwardIterator2 __last2)
- {
- // concept requirements
- __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
- __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
- __glibcxx_function_requires(_EqualOpConcept<
- typename iterator_traits<_ForwardIterator1>::value_type,
- typename iterator_traits<_ForwardIterator2>::value_type>)
- __glibcxx_requires_valid_range(__first1, __last1);
- __glibcxx_requires_valid_range(__first2, __last2);
- // Test for empty ranges
- if (__first1 == __last1 || __first2 == __last2)
- return __first1;
-
- // Test for a pattern of length 1.
- _ForwardIterator2 __tmp(__first2);
- ++__tmp;
- if (__tmp == __last2)
- return std::find(__first1, __last1, *__first2);
-
- // General case.
- _ForwardIterator2 __p1, __p;
- __p1 = __first2; ++__p1;
- _ForwardIterator1 __current = __first1;
-
- while (__first1 != __last1)
- {
- __first1 = std::find(__first1, __last1, *__first2);
- if (__first1 == __last1)
- return __last1;
-
- __p = __p1;
- __current = __first1;
- if (++__current == __last1)
- return __last1;
-
- while (*__current == *__p)
- {
- if (++__p == __last2)
- return __first1;
- if (++__current == __last1)
- return __last1;
- }
- ++__first1;
- }
- return __first1;
- }
-
- /**
+ /**
* @brief Search a sequence for a matching sub-sequence using a predicate.
* @param first1 A forward iterator.
* @param last1 A forward iterator.
@@ -608,55 +515,42 @@
}
/**
- * @brief Search a sequence for a number of consecutive values.
- * @param first A forward iterator.
- * @param last A forward iterator.
- * @param count The number of consecutive values.
- * @param val The value to find.
- * @return The first iterator @c i in the range @p [first,last-count)
- * such that @c *(i+N) == @p val for each @c N in the range @p [0,count),
- * or @p last if no such iterator exists.
+ * @brief Search a sequence for a matching sub-sequence.
+ * @param first1 A forward iterator.
+ * @param last1 A forward iterator.
+ * @param first2 A forward iterator.
+ * @param last2 A forward iterator.
+ * @return The first iterator @c i in the range
+ * @p [first1,last1-(last2-first2)) such that @c *(i+N) == @p *(first2+N)
+ * for each @c N in the range @p [0,last2-first2), or @p last1 if no
+ * such iterator exists.
*
- * Searches the range @p [first,last) for @p count consecutive elements
- * equal to @p val.
+ * Searches the range @p [first1,last1) for a sub-sequence that compares
+ * equal value-by-value with the sequence given by @p [first2,last2) and
+ * returns an iterator to the first element of the sub-sequence, or
+ * @p last1 if the sub-sequence is not found.
+ *
+ * Because the sub-sequence must lie completely within the range
+ * @p [first1,last1) it must start at a position less than
+ * @p last1-(last2-first2) where @p last2-first2 is the length of the
+ * sub-sequence.
+ * This means that the returned iterator @c i will be in the range
+ * @p [first1,last1-(last2-first2))
*/
- template<typename _ForwardIterator, typename _Integer, typename _Tp>
- _ForwardIterator
- search_n(_ForwardIterator __first, _ForwardIterator __last,
- _Integer __count, const _Tp& __val)
+ template<typename _ForwardIterator1, typename _ForwardIterator2>
+ _ForwardIterator1
+ search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
+ _ForwardIterator2 __first2, _ForwardIterator2 __last2)
{
// concept requirements
- __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
- __glibcxx_function_requires(_EqualityComparableConcept<
- typename iterator_traits<_ForwardIterator>::value_type>)
- __glibcxx_function_requires(_EqualityComparableConcept<_Tp>)
- __glibcxx_requires_valid_range(__first, __last);
-
- if (__count <= 0)
- return __first;
- else
- {
- __first = std::find(__first, __last, __val);
- while (__first != __last)
- {
- typename iterator_traits<_ForwardIterator>::difference_type
- __n = __count;
- _ForwardIterator __i = __first;
- ++__i;
- while (__i != __last && __n != 1 && *__i == __val)
- {
- ++__i;
- --__n;
- }
- if (__n == 1)
- return __first;
- else
- __first = std::find(__i, __last, __val);
- }
- return __last;
- }
+ __glibcxx_function_requires(_EqualOpConcept<
+ typename iterator_traits<_ForwardIterator1>::value_type,
+ typename iterator_traits<_ForwardIterator2>::value_type>)
+ return std::search(__first1, __last1, __first2, __last2, __gnu_cxx::__ops::equal_to());
}
+
+
/**
* @brief Search a sequence for a number of consecutive values using a
* predicate.
@@ -724,22 +618,48 @@
}
/**
- * @brief Swap the elements of two sequences.
- * @param first1 A forward iterator.
- * @param last1 A forward iterator.
- * @param first2 A forward iterator.
- * @return An iterator equal to @p first2+(last1-first1).
+ * @brief Search a sequence for a number of consecutive values.
+ * @param first A forward iterator.
+ * @param last A forward iterator.
+ * @param count The number of consecutive values.
+ * @param val The value to find.
+ * @return The first iterator @c i in the range @p [first,last-count)
+ * such that @c *(i+N) == @p val for each @c N in the range @p [0,count),
+ * or @p last if no such iterator exists.
*
- * Swaps each element in the range @p [first1,last1) with the
- * corresponding element in the range @p [first2,(last1-first1)).
- * The ranges must not overlap.
+ * Searches the range @p [first,last) for @p count consecutive elements
+ * equal to @p val.
*/
- template<typename _ForwardIterator1, typename _ForwardIterator2>
- _ForwardIterator2
- swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
- _ForwardIterator2 __first2)
- {
- // concept requirements
+ template<typename _ForwardIterator, typename _Integer, typename _Tp>
+ _ForwardIterator
+ search_n(_ForwardIterator __first, _ForwardIterator __last,
+ _Integer __count, const _Tp& __val)
+ {
+ // concept requirements
+ __glibcxx_function_requires(_EqualityComparableConcept<
+ typename iterator_traits<_ForwardIterator>::value_type>)
+ __glibcxx_function_requires(_EqualityComparableConcept<_Tp>)
+ return std::search_n(__first, __last, __count, __val, __gnu_cxx::__ops::equal_to());
+ }
+
+
+ /**
+ * @brief Swap the elements of two sequences.
+ * @param first1 A forward iterator.
+ * @param last1 A forward iterator.
+ * @param first2 A forward iterator.
+ * @return An iterator equal to @p first2+(last1-first1).
+ *
+ * Swaps each element in the range @p [first1,last1) with the
+ * corresponding element in the range @p [first2,(last1-first1)).
+ * The ranges must not overlap.
+ */
+ template<typename _ForwardIterator1, typename _ForwardIterator2>
+ _ForwardIterator2
+ swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
+ _ForwardIterator2 __first2)
+ {
+ // concept requirements
__glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
_ForwardIterator1>)
__glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
@@ -1151,52 +1071,6 @@
/**
* @if maint
- * This is an uglified unique_copy(_InputIterator, _InputIterator,
- * _OutputIterator)
- * overloaded for output iterators.
- * @endif
- */
- template<typename _InputIterator, typename _OutputIterator>
- _OutputIterator
- __unique_copy(_InputIterator __first, _InputIterator __last,
- _OutputIterator __result,
- output_iterator_tag)
- {
- // concept requirements -- taken care of in dispatching function
- typename iterator_traits<_InputIterator>::value_type __value = *__first;
- *__result = __value;
- while (++__first != __last)
- if (!(__value == *__first))
- {
- __value = *__first;
- *++__result = __value;
- }
- return ++__result;
- }
-
- /**
- * @if maint
- * This is an uglified unique_copy(_InputIterator, _InputIterator,
- * _OutputIterator)
- * overloaded for forward iterators.
- * @endif
- */
- template<typename _InputIterator, typename _ForwardIterator>
- _ForwardIterator
- __unique_copy(_InputIterator __first, _InputIterator __last,
- _ForwardIterator __result,
- forward_iterator_tag)
- {
- // concept requirements -- taken care of in dispatching function
- *__result = *__first;
- while (++__first != __last)
- if (!(*__result == *__first))
- *++__result = *__first;
- return ++__result;
- }
-
- /**
- * @if maint
* This is an uglified
* unique_copy(_InputIterator, _InputIterator, _OutputIterator,
* _BinaryPredicate)
@@ -1254,38 +1128,6 @@
return ++__result;
}
- /**
- * @brief Copy a sequence, removing consecutive duplicate values.
- * @param first An input iterator.
- * @param last An input iterator.
- * @param result An output iterator.
- * @return An iterator designating the end of the resulting sequence.
- *
- * Copies each element in the range @p [first,last) to the range
- * beginning at @p result, except that only the first element is copied
- * from groups of consecutive elements that compare equal.
- * unique_copy() is stable, so the relative order of elements that are
- * copied is unchanged.
- */
- template<typename _InputIterator, typename _OutputIterator>
- inline _OutputIterator
- unique_copy(_InputIterator __first, _InputIterator __last,
- _OutputIterator __result)
- {
- // concept requirements
- __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
- __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
- typename iterator_traits<_InputIterator>::value_type>)
- __glibcxx_function_requires(_EqualityComparableConcept<
- typename iterator_traits<_InputIterator>::value_type>)
- __glibcxx_requires_valid_range(__first, __last);
-
- typedef typename iterator_traits<_OutputIterator>::iterator_category
- _IterType;
-
- if (__first == __last) return __result;
- return std::__unique_copy(__first, __last, __result, _IterType());
- }
/**
* @brief Copy a sequence, removing consecutive values using a predicate.
@@ -1324,41 +1166,27 @@
}
/**
- * @brief Remove consecutive duplicate values from a sequence.
- * @param first A forward iterator.
- * @param last A forward iterator.
- * @return An iterator designating the end of the resulting sequence.
+ * @brief Copy a sequence, removing consecutive duplicate values.
+ * @param first An input iterator.
+ * @param last An input iterator.
+ * @param result An output iterator.
+ * @return An iterator designating the end of the resulting sequence.
*
- * Removes all but the first element from each group of consecutive
- * values that compare equal.
- * unique() is stable, so the relative order of elements that are
- * not removed is unchanged.
- * Elements between the end of the resulting sequence and @p last
- * are still present, but their value is unspecified.
+ * Copies each element in the range @p [first,last) to the range
+ * beginning at @p result, except that only the first element is copied
+ * from groups of consecutive elements that compare equal.
+ * unique_copy() is stable, so the relative order of elements that are
+ * copied is unchanged.
*/
- template<typename _ForwardIterator>
- _ForwardIterator
- unique(_ForwardIterator __first, _ForwardIterator __last)
+ template<typename _InputIterator, typename _OutputIterator>
+ inline _OutputIterator
+ unique_copy(_InputIterator __first, _InputIterator __last,
+ _OutputIterator __result)
{
// concept requirements
- __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
- _ForwardIterator>)
__glibcxx_function_requires(_EqualityComparableConcept<
- typename iterator_traits<_ForwardIterator>::value_type>)
- __glibcxx_requires_valid_range(__first, __last);
-
- // Skip the beginning, if already unique.
- __first = std::adjacent_find(__first, __last);
- if (__first == __last)
- return __last;
-
- // Do the real copy work.
- _ForwardIterator __dest = __first;
- ++__first;
- while (++__first != __last)
- if (!(*__dest == *__first))
- *++__dest = *__first;
- return ++__dest;
+ typename iterator_traits<_InputIterator>::value_type>)
+ return std::unique_copy(__first, __last, __result, __gnu_cxx::__ops::equal_to());
}
/**
@@ -1403,6 +1231,29 @@
}
/**
+ * @brief Remove consecutive duplicate values from a sequence.
+ * @param first A forward iterator.
+ * @param last A forward iterator.
+ * @return An iterator designating the end of the resulting sequence.
+ *
+ * Removes all but the first element from each group of consecutive
+ * values that compare equal.
+ * unique() is stable, so the relative order of elements that are
+ * not removed is unchanged.
+ * Elements between the end of the resulting sequence and @p last
+ * are still present, but their value is unspecified.
+ */
+ template<typename _ForwardIterator>
+ _ForwardIterator
+ unique(_ForwardIterator __first, _ForwardIterator __last)
+ {
+ // concept requirements
+ __glibcxx_function_requires(_EqualityComparableConcept<
+ typename iterator_traits<_ForwardIterator>::value_type>)
+ return std::unique(__first, __last, __gnu_cxx::__ops::equal_to());
+ }
+
+ /**
* @if maint
* This is an uglified reverse(_BidirectionalIterator,
* _BidirectionalIterator)
@@ -2021,30 +1872,6 @@
* This is a helper function...
* @endif
*/
- template<typename _RandomAccessIterator, typename _Tp>
- _RandomAccessIterator
- __unguarded_partition(_RandomAccessIterator __first,
- _RandomAccessIterator __last, _Tp __pivot)
- {
- while (true)
- {
- while (*__first < __pivot)
- ++__first;
- --__last;
- while (__pivot < *__last)
- --__last;
- if (!(__first < __last))
- return __first;
- std::iter_swap(__first, __last);
- ++__first;
- }
- }
-
- /**
- * @if maint
- * This is a helper function...
- * @endif
- */
template<typename _RandomAccessIterator, typename _Tp, typename _Compare>
_RandomAccessIterator
__unguarded_partition(_RandomAccessIterator __first,
@@ -2078,26 +1905,6 @@
* This is a helper function for the sort routine.
* @endif
*/
- template<typename _RandomAccessIterator, typename _Tp>
- void
- __unguarded_linear_insert(_RandomAccessIterator __last, _Tp __val)
- {
- _RandomAccessIterator __next = __last;
- --__next;
- while (__val < *__next)
- {
- *__last = *__next;
- __last = __next;
- --__next;
- }
- *__last = __val;
- }
-
- /**
- * @if maint
- * This is a helper function for the sort routine.
- * @endif
- */
template<typename _RandomAccessIterator, typename _Tp, typename _Compare>
void
__unguarded_linear_insert(_RandomAccessIterator __last, _Tp __val,
@@ -2119,33 +1926,6 @@
* This is a helper function for the sort routine.
* @endif
*/
- template<typename _RandomAccessIterator>
- void
- __insertion_sort(_RandomAccessIterator __first,
- _RandomAccessIterator __last)
- {
- if (__first == __last)
- return;
-
- for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i)
- {
- typename iterator_traits<_RandomAccessIterator>::value_type
- __val = *__i;
- if (__val < *__first)
- {
- std::copy_backward(__first, __i, __i + 1);
- *__first = __val;
- }
- else
- std::__unguarded_linear_insert(__i, __val);
- }
- }
-
- /**
- * @if maint
- * This is a helper function for the sort routine.
- * @endif
- */
template<typename _RandomAccessIterator, typename _Compare>
void
__insertion_sort(_RandomAccessIterator __first,
@@ -2172,23 +1952,6 @@
* This is a helper function for the sort routine.
* @endif
*/
- template<typename _RandomAccessIterator>
- inline void
- __unguarded_insertion_sort(_RandomAccessIterator __first,
- _RandomAccessIterator __last)
- {
- typedef typename iterator_traits<_RandomAccessIterator>::value_type
- _ValueType;
-
- for (_RandomAccessIterator __i = __first; __i != __last; ++__i)
- std::__unguarded_linear_insert(__i, _ValueType(*__i));
- }
-
- /**
- * @if maint
- * This is a helper function for the sort routine.
- * @endif
- */
template<typename _RandomAccessIterator, typename _Compare>
inline void
__unguarded_insertion_sort(_RandomAccessIterator __first,
@@ -2206,25 +1969,6 @@
* This is a helper function for the sort routine.
* @endif
*/
- template<typename _RandomAccessIterator>
- void
- __final_insertion_sort(_RandomAccessIterator __first,
- _RandomAccessIterator __last)
- {
- if (__last - __first > _S_threshold)
- {
- std::__insertion_sort(__first, __first + _S_threshold);
- std::__unguarded_insertion_sort(__first + _S_threshold, __last);
- }
- else
- std::__insertion_sort(__first, __last);
- }
-
- /**
- * @if maint
- * This is a helper function for the sort routine.
- * @endif
- */
template<typename _RandomAccessIterator, typename _Compare>
void
__final_insertion_sort(_RandomAccessIterator __first,
@@ -2255,44 +1999,7 @@
return __k;
}
- /**
- * @brief Sort the smallest elements of a sequence.
- * @param first An iterator.
- * @param middle Another iterator.
- * @param last Another iterator.
- * @return Nothing.
- *
- * Sorts the smallest @p (middle-first) elements in the range
- * @p [first,last) and moves them to the range @p [first,middle). The
- * order of the remaining elements in the range @p [middle,last) is
- * undefined.
- * After the sort if @p i and @j are iterators in the range
- * @p [first,middle) such that @i precedes @j and @k is an iterator in
- * the range @p [middle,last) then @p *j<*i and @p *k<*i are both false.
- */
- template<typename _RandomAccessIterator>
- void
- partial_sort(_RandomAccessIterator __first,
- _RandomAccessIterator __middle,
- _RandomAccessIterator __last)
- {
- typedef typename iterator_traits<_RandomAccessIterator>::value_type
- _ValueType;
-
- // concept requirements
- __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
- _RandomAccessIterator>)
- __glibcxx_function_requires(_LessThanComparableConcept<_ValueType>)
- __glibcxx_requires_valid_range(__first, __middle);
- __glibcxx_requires_valid_range(__middle, __last);
-
- std::make_heap(__first, __middle);
- for (_RandomAccessIterator __i = __middle; __i < __last; ++__i)
- if (*__i < *__first)
- std::__pop_heap(__first, __middle, __i, _ValueType(*__i));
- std::sort_heap(__first, __middle);
- }
-
+
/**
* @brief Sort the smallest elements of a sequence using a predicate
* for comparison.
@@ -2337,67 +2044,34 @@
}
/**
- * @brief Copy the smallest elements of a sequence.
+ * @brief Sort the smallest elements of a sequence.
* @param first An iterator.
+ * @param middle Another iterator.
* @param last Another iterator.
- * @param result_first A random-access iterator.
- * @param result_last Another random-access iterator.
- * @return An iterator indicating the end of the resulting sequence.
+ * @return Nothing.
*
- * Copies and sorts the smallest N values from the range @p [first,last)
- * to the range beginning at @p result_first, where the number of
- * elements to be copied, @p N, is the smaller of @p (last-first) and
- * @p (result_last-result_first).
+ * Sorts the smallest @p (middle-first) elements in the range
+ * @p [first,last) and moves them to the range @p [first,middle). The
+ * order of the remaining elements in the range @p [middle,last) is
+ * undefined.
* After the sort if @p i and @j are iterators in the range
- * @p [result_first,result_first+N) such that @i precedes @j then
- * @p *j<*i is false.
- * The value returned is @p result_first+N.
+ * @p [first,middle) such that @i precedes @j and @k is an iterator in
+ * the range @p [middle,last) then @p *j<*i and @p *k<*i are both false.
*/
- template<typename _InputIterator, typename _RandomAccessIterator>
- _RandomAccessIterator
- partial_sort_copy(_InputIterator __first, _InputIterator __last,
- _RandomAccessIterator __result_first,
- _RandomAccessIterator __result_last)
+ template<typename _RandomAccessIterator>
+ void
+ partial_sort(_RandomAccessIterator __first,
+ _RandomAccessIterator __middle,
+ _RandomAccessIterator __last)
{
- typedef typename iterator_traits<_InputIterator>::value_type
- _InputValueType;
typedef typename iterator_traits<_RandomAccessIterator>::value_type
- _OutputValueType;
- typedef typename iterator_traits<_RandomAccessIterator>::difference_type
- _DistanceType;
+ _ValueType;
// concept requirements
- __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
- __glibcxx_function_requires(_ConvertibleConcept<_InputValueType,
- _OutputValueType>)
- __glibcxx_function_requires(_LessThanComparableConcept<_OutputValueType>)
- __glibcxx_function_requires(_LessThanComparableConcept<_InputValueType>)
- __glibcxx_requires_valid_range(__first, __last);
- __glibcxx_requires_valid_range(__result_first, __result_last);
-
- if (__result_first == __result_last)
- return __result_last;
- _RandomAccessIterator __result_real_last = __result_first;
- while(__first != __last && __result_real_last != __result_last)
- {
- *__result_real_last = *__first;
- ++__result_real_last;
- ++__first;
- }
- std::make_heap(__result_first, __result_real_last);
- while (__first != __last)
- {
- if (*__first < *__result_first)
- std::__adjust_heap(__result_first, _DistanceType(0),
- _DistanceType(__result_real_last
- - __result_first),
- _InputValueType(*__first));
- ++__first;
- }
- std::sort_heap(__result_first, __result_real_last);
- return __result_real_last;
+ __glibcxx_function_requires(_LessThanComparableConcept<_ValueType>)
+ std::partial_sort(__first, __middle, __last, __gnu_cxx::__ops::less());
}
-
+
/**
* @brief Copy the smallest elements of a sequence using a predicate for
* comparison.
@@ -2467,39 +2141,41 @@
}
/**
- * @if maint
- * This is a helper function for the sort routine.
- * @endif
+ * @brief Copy the smallest elements of a sequence.
+ * @param first An iterator.
+ * @param last Another iterator.
+ * @param result_first A random-access iterator.
+ * @param result_last Another random-access iterator.
+ * @return An iterator indicating the end of the resulting sequence.
+ *
+ * Copies and sorts the smallest N values from the range @p [first,last)
+ * to the range beginning at @p result_first, where the number of
+ * elements to be copied, @p N, is the smaller of @p (last-first) and
+ * @p (result_last-result_first).
+ * After the sort if @p i and @j are iterators in the range
+ * @p [result_first,result_first+N) such that @i precedes @j then
+ * @p *j<*i is false.
+ * The value returned is @p result_first+N.
*/
- template<typename _RandomAccessIterator, typename _Size>
- void
- __introsort_loop(_RandomAccessIterator __first,
- _RandomAccessIterator __last,
- _Size __depth_limit)
+ template<typename _InputIterator, typename _RandomAccessIterator>
+ _RandomAccessIterator
+ partial_sort_copy(_InputIterator __first, _InputIterator __last,
+ _RandomAccessIterator __result_first,
+ _RandomAccessIterator __result_last)
{
+ typedef typename iterator_traits<_InputIterator>::value_type
+ _InputValueType;
typedef typename iterator_traits<_RandomAccessIterator>::value_type
- _ValueType;
+ _OutputValueType;
+ typedef typename iterator_traits<_RandomAccessIterator>::difference_type
+ _DistanceType;
- while (__last - __first > _S_threshold)
- {
- if (__depth_limit == 0)
- {
- std::partial_sort(__first, __last, __last);
- return;
- }
- --__depth_limit;
- _RandomAccessIterator __cut =
- std::__unguarded_partition(__first, __last,
- _ValueType(std::__median(*__first,
- *(__first
- + (__last
- - __first)
- / 2),
- *(__last
- - 1))));
- std::__introsort_loop(__cut, __last, __depth_limit);
- __last = __cut;
- }
+ // concept requirements
+ __glibcxx_function_requires(_LessThanComparableConcept<_OutputValueType>)
+ __glibcxx_function_requires(_LessThanComparableConcept<_InputValueType>)
+
+ std::partial_sort_copy(__first, __last, __result_first, __result_last,
+ __gnu_cxx::__ops::less());
}
/**
@@ -2540,21 +2216,23 @@
}
/**
- * @brief Sort the elements of a sequence.
+ * @brief Sort the elements of a sequence using a predicate for comparison.
* @param first An iterator.
* @param last Another iterator.
+ * @param comp A comparison functor.
* @return Nothing.
*
* Sorts the elements in the range @p [first,last) in ascending order,
- * such that @p *(i+1)<*i is false for each iterator @p i in the range
- * @p [first,last-1).
+ * such that @p comp(*(i+1),*i) is false for every iterator @p i in the
+ * range @p [first,last-1).
*
* The relative ordering of equivalent elements is not preserved, use
* @p stable_sort() if this is needed.
*/
- template<typename _RandomAccessIterator>
+ template<typename _RandomAccessIterator, typename _Compare>
inline void
- sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
+ sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
+ _Compare __comp)
{
typedef typename iterator_traits<_RandomAccessIterator>::value_type
_ValueType;
@@ -2562,67 +2240,62 @@
// concept requirements
__glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
_RandomAccessIterator>)
- __glibcxx_function_requires(_LessThanComparableConcept<_ValueType>)
+ __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, _ValueType,
+ _ValueType>)
__glibcxx_requires_valid_range(__first, __last);
if (__first != __last)
{
- std::__introsort_loop(__first, __last, __lg(__last - __first) * 2);
- std::__final_insertion_sort(__first, __last);
+ std::__introsort_loop(__first, __last, __lg(__last - __first) * 2,
+ __comp);
+ std::__final_insertion_sort(__first, __last, __comp);
}
}
/**
- * @brief Sort the elements of a sequence using a predicate for comparison.
+ * @brief Sort the elements of a sequence.
* @param first An iterator.
* @param last Another iterator.
- * @param comp A comparison functor.
* @return Nothing.
*
* Sorts the elements in the range @p [first,last) in ascending order,
- * such that @p comp(*(i+1),*i) is false for every iterator @p i in the
- * range @p [first,last-1).
+ * such that @p *(i+1)<*i is false for each iterator @p i in the range
+ * @p [first,last-1).
*
* The relative ordering of equivalent elements is not preserved, use
* @p stable_sort() if this is needed.
*/
- template<typename _RandomAccessIterator, typename _Compare>
+ template<typename _RandomAccessIterator>
inline void
- sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
- _Compare __comp)
+ sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
{
typedef typename iterator_traits<_RandomAccessIterator>::value_type
_ValueType;
// concept requirements
- __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
- _RandomAccessIterator>)
- __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, _ValueType,
- _ValueType>)
- __glibcxx_requires_valid_range(__first, __last);
-
- if (__first != __last)
- {
- std::__introsort_loop(__first, __last, __lg(__last - __first) * 2,
- __comp);
- std::__final_insertion_sort(__first, __last, __comp);
- }
+ __glibcxx_function_requires(_LessThanComparableConcept<_ValueType>)
+ std::sort(__first, __last, __gnu_cxx::__ops::less());
}
+
/**
* @brief Finds the first position in which @a val could be inserted
* without changing the ordering.
* @param first An iterator.
* @param last Another iterator.
* @param val The search term.
+ * @param comp A functor to use for comparisons.
* @return An iterator pointing to the first element "not less than" @a val,
* or end() if every element is less than @a val.
* @ingroup binarysearch
+ *
+ * The comparison function should have the same effects on ordering as
+ * the function used for the initial sort.
*/
- template<typename _ForwardIterator, typename _Tp>
+ template<typename _ForwardIterator, typename _Tp, typename _Compare>
_ForwardIterator
lower_bound(_ForwardIterator __first, _ForwardIterator __last,
- const _Tp& __val)
+ const _Tp& __val, _Compare __comp)
{
typedef typename iterator_traits<_ForwardIterator>::value_type
_ValueType;
@@ -2630,14 +2303,10 @@
_DistanceType;
// concept requirements
- // Note that these are slightly stricter than those of the 4-argument
- // version, defined next. The difference is in the strictness of the
- // comparison operations... so for looser checking, define your own
- // comparison function, as was intended.
__glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
- __glibcxx_function_requires(_SameTypeConcept<_Tp, _ValueType>)
- __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
- __glibcxx_requires_partitioned(__first, __last, __val);
+ __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
+ _ValueType, _Tp>)
+ __glibcxx_requires_partitioned_pred(__first, __last, __val, __comp);
_DistanceType __len = std::distance(__first, __last);
_DistanceType __half;
@@ -2648,7 +2317,7 @@
__half = __len >> 1;
__middle = __first;
std::advance(__middle, __half);
- if (*__middle < __val)
+ if (__comp(*__middle, __val))
{
__first = __middle;
++__first;
@@ -2666,17 +2335,47 @@
* @param first An iterator.
* @param last Another iterator.
* @param val The search term.
- * @param comp A functor to use for comparisons.
* @return An iterator pointing to the first element "not less than" @a val,
* or end() if every element is less than @a val.
* @ingroup binarysearch
+ */
+ template<typename _ForwardIterator, typename _Tp>
+ _ForwardIterator
+ lower_bound(_ForwardIterator __first, _ForwardIterator __last,
+ const _Tp& __val)
+ {
+ typedef typename iterator_traits<_ForwardIterator>::value_type
+ _ValueType;
+ typedef typename iterator_traits<_ForwardIterator>::difference_type
+ _DistanceType;
+
+ // concept requirements
+ // Note that these are slightly stricter than those of the 4-argument
+ // version, defined previously. The difference is in the strictness of
+ // the comparison operations... so for looser checking, define your own
+ // comparison function, as was intended.
+ __glibcxx_function_requires(_SameTypeConcept<_Tp, _ValueType>)
+ __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
+ return lower_bound(__first, __last, __val, __gnu_cxx::__ops::less());
+ }
+
+ /**
+ * @brief Finds the last position in which @a val could be inserted
+ * without changing the ordering.
+ * @param first An iterator.
+ * @param last Another iterator.
+ * @param val The search term.
+ * @param comp A functor to use for comparisons.
+ * @return An iterator pointing to the first element greater than @a val,
+ * or end() if no elements are greater than @a val.
+ * @ingroup binarysearch
*
* The comparison function should have the same effects on ordering as
* the function used for the initial sort.
*/
template<typename _ForwardIterator, typename _Tp, typename _Compare>
_ForwardIterator
- lower_bound(_ForwardIterator __first, _ForwardIterator __last,
+ upper_bound(_ForwardIterator __first, _ForwardIterator __last,
const _Tp& __val, _Compare __comp)
{
typedef typename iterator_traits<_ForwardIterator>::value_type
@@ -2687,7 +2386,7 @@
// concept requirements
__glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
__glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
- _ValueType, _Tp>)
+ _Tp, _ValueType>)
__glibcxx_requires_partitioned_pred(__first, __last, __val, __comp);
_DistanceType __len = std::distance(__first, __last);
@@ -2699,19 +2398,19 @@
__half = __len >> 1;
__middle = __first;
std::advance(__middle, __half);
- if (__comp(*__middle, __val))
+ if (__comp(__val, *__middle))
+ __len = __half;
+ else
{
__first = __middle;
++__first;
__len = __len - __half - 1;
}
- else
- __len = __half;
}
return __first;
}
- /**
+ /**
* @brief Finds the last position in which @a val could be inserted
* without changing the ordering.
* @param first An iterator.
@@ -2733,129 +2432,10 @@
// concept requirements
// See comments on lower_bound.
- __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
__glibcxx_function_requires(_SameTypeConcept<_Tp, _ValueType>)
__glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
- __glibcxx_requires_partitioned(__first, __last, __val);
-
- _DistanceType __len = std::distance(__first, __last);
- _DistanceType __half;
- _ForwardIterator __middle;
-
- while (__len > 0)
- {
- __half = __len >> 1;
- __middle = __first;
- std::advance(__middle, __half);
- if (__val < *__middle)
- __len = __half;
- else
- {
- __first = __middle;
- ++__first;
- __len = __len - __half - 1;
- }
- }
- return __first;
- }
-
- /**
- * @brief Finds the last position in which @a val could be inserted
- * without changing the ordering.
- * @param first An iterator.
- * @param last Another iterator.
- * @param val The search term.
- * @param comp A functor to use for comparisons.
- * @return An iterator pointing to the first element greater than @a val,
- * or end() if no elements are greater than @a val.
- * @ingroup binarysearch
- *
- * The comparison function should have the same effects on ordering as
- * the function used for the initial sort.
- */
- template<typename _ForwardIterator, typename _Tp, typename _Compare>
- _ForwardIterator
- upper_bound(_ForwardIterator __first, _ForwardIterator __last,
- const _Tp& __val, _Compare __comp)
- {
- typedef typename iterator_traits<_ForwardIterator>::value_type
- _ValueType;
- typedef typename iterator_traits<_ForwardIterator>::difference_type
- _DistanceType;
-
- // concept requirements
- __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
- __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
- _Tp, _ValueType>)
- __glibcxx_requires_partitioned_pred(__first, __last, __val, __comp);
-
- _DistanceType __len = std::distance(__first, __last);
- _DistanceType __half;
- _ForwardIterator __middle;
-
- while (__len > 0)
- {
- __half = __len >> 1;
- __middle = __first;
- std::advance(__middle, __half);
- if (__comp(__val, *__middle))
- __len = __half;
- else
- {
- __first = __middle;
- ++__first;
- __len = __len - __half - 1;
- }
- }
- return __first;
- }
-
- /**
- * @if maint
- * This is a helper function for the merge routines.
- * @endif
- */
- template<typename _BidirectionalIterator, typename _Distance>
- void
- __merge_without_buffer(_BidirectionalIterator __first,
- _BidirectionalIterator __middle,
- _BidirectionalIterator __last,
- _Distance __len1, _Distance __len2)
- {
- if (__len1 == 0 || __len2 == 0)
- return;
- if (__len1 + __len2 == 2)
- {
- if (*__middle < *__first)
- std::iter_swap(__first, __middle);
- return;
- }
- _BidirectionalIterator __first_cut = __first;
- _BidirectionalIterator __second_cut = __middle;
- _Distance __len11 = 0;
- _Distance __len22 = 0;
- if (__len1 > __len2)
- {
- __len11 = __len1 / 2;
- std::advance(__first_cut, __len11);
- __second_cut = std::lower_bound(__middle, __last, *__first_cut);
- __len22 = std::distance(__middle, __second_cut);
- }
- else
- {
- __len22 = __len2 / 2;
- std::advance(__second_cut, __len22);
- __first_cut = std::upper_bound(__first, __middle, *__second_cut);
- __len11 = std::distance(__first, __first_cut);
- }
- std::rotate(__first_cut, __middle, __second_cut);
- _BidirectionalIterator __new_middle = __first_cut;
- std::advance(__new_middle, std::distance(__middle, __second_cut));
- std::__merge_without_buffer(__first, __first_cut, __new_middle,
- __len11, __len22);
- std::__merge_without_buffer(__new_middle, __second_cut, __last,
- __len1 - __len11, __len2 - __len22);
- }
+ return std::upper_bound(__first, __last, __val, __gnu_cxx::__ops::less());
+ }
/**
* @if maint
@@ -2913,29 +2493,6 @@
* This is a helper function for the stable sorting routines.
* @endif
*/
- template<typename _RandomAccessIterator>
- void
- __inplace_stable_sort(_RandomAccessIterator __first,
- _RandomAccessIterator __last)
- {
- if (__last - __first < 15)
- {
- std::__insertion_sort(__first, __last);
- return;
- }
- _RandomAccessIterator __middle = __first + (__last - __first) / 2;
- std::__inplace_stable_sort(__first, __middle);
- std::__inplace_stable_sort(__middle, __last);
- std::__merge_without_buffer(__first, __middle, __last,
- __middle - __first,
- __last - __middle);
- }
-
- /**
- * @if maint
- * This is a helper function for the stable sorting routines.
- * @endif
- */
template<typename _RandomAccessIterator, typename _Compare>
void
__inplace_stable_sort(_RandomAccessIterator __first,
@@ -2962,6 +2519,7 @@
* @param last1 Another iterator.
* @param last2 Another iterator.
* @param result An iterator pointing to the end of the merged range.
+ * @param comp A functor to use for comparisons.
* @return An iterator pointing to the first element "not less than" @a val.
*
* Merges the ranges [first1,last1) and [first2,last2) into the sorted range
@@ -2970,30 +2528,34 @@
* the input ranges. The sort is @e stable, that is, for equivalent
* elements in the two ranges, elements from the first range will always
* come before elements from the second.
+ *
+ * The comparison function should have the same effects on ordering as
+ * the function used for the initial sort.
*/
template<typename _InputIterator1, typename _InputIterator2,
- typename _OutputIterator>
+ typename _OutputIterator, typename _Compare>
_OutputIterator
merge(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2,
- _OutputIterator __result)
+ _OutputIterator __result, _Compare __comp)
{
// concept requirements
__glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
__glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
- __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
- typename iterator_traits<_InputIterator1>::value_type>)
__glibcxx_function_requires(_SameTypeConcept<
typename iterator_traits<_InputIterator1>::value_type,
typename iterator_traits<_InputIterator2>::value_type>)
- __glibcxx_function_requires(_LessThanComparableConcept<
+ __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
typename iterator_traits<_InputIterator1>::value_type>)
- __glibcxx_requires_sorted(__first1, __last1);
- __glibcxx_requires_sorted(__first2, __last2);
+ __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
+ typename iterator_traits<_InputIterator1>::value_type,
+ typename iterator_traits<_InputIterator2>::value_type>)
+ __glibcxx_requires_sorted_pred(__first1, __last1, __comp);
+ __glibcxx_requires_sorted_pred(__first2, __last2, __comp);
while (__first1 != __last1 && __first2 != __last2)
{
- if (*__first2 < *__first1)
+ if (__comp(*__first2, *__first1))
{
*__result = *__first2;
++__first2;
@@ -3016,7 +2578,6 @@
* @param last1 Another iterator.
* @param last2 Another iterator.
* @param result An iterator pointing to the end of the merged range.
- * @param comp A functor to use for comparisons.
* @return An iterator pointing to the first element "not less than" @a val.
*
* Merges the ranges [first1,last1) and [first2,last2) into the sorted range
@@ -3025,70 +2586,19 @@
* the input ranges. The sort is @e stable, that is, for equivalent
* elements in the two ranges, elements from the first range will always
* come before elements from the second.
- *
- * The comparison function should have the same effects on ordering as
- * the function used for the initial sort.
*/
template<typename _InputIterator1, typename _InputIterator2,
- typename _OutputIterator, typename _Compare>
+ typename _OutputIterator>
_OutputIterator
merge(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2,
- _OutputIterator __result, _Compare __comp)
+ _OutputIterator __result)
{
// concept requirements
- __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
- __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
- __glibcxx_function_requires(_SameTypeConcept<
- typename iterator_traits<_InputIterator1>::value_type,
- typename iterator_traits<_InputIterator2>::value_type>)
- __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
+ __glibcxx_function_requires(_LessThanComparableConcept<
typename iterator_traits<_InputIterator1>::value_type>)
- __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
- typename iterator_traits<_InputIterator1>::value_type,
- typename iterator_traits<_InputIterator2>::value_type>)
- __glibcxx_requires_sorted_pred(__first1, __last1, __comp);
- __glibcxx_requires_sorted_pred(__first2, __last2, __comp);
-
- while (__first1 != __last1 && __first2 != __last2)
- {
- if (__comp(*__first2, *__first1))
- {
- *__result = *__first2;
- ++__first2;
- }
- else
- {
- *__result = *__first1;
- ++__first1;
- }
- ++__result;
- }
- return std::copy(__first2, __last2, std::copy(__first1, __last1,
- __result));
- }
-
- template<typename _RandomAccessIterator1, typename _RandomAccessIterator2,
- typename _Distance>
- void
- __merge_sort_loop(_RandomAccessIterator1 __first,
- _RandomAccessIterator1 __last,
- _RandomAccessIterator2 __result,
- _Distance __step_size)
- {
- const _Distance __two_step = 2 * __step_size;
-
- while (__last - __first >= __two_step)
- {
- __result = std::merge(__first, __first + __step_size,
- __first + __step_size, __first + __two_step,
- __result);
- __first += __two_step;
- }
-
- __step_size = std::min(_Distance(__last - __first), __step_size);
- std::merge(__first, __first + __step_size, __first + __step_size, __last,
- __result);
+ return std::merge(__first1, __last1, __first2, __last2, __result,
+ __gnu_cxx::__ops::less());
}
template<typename _RandomAccessIterator1, typename _RandomAccessIterator2,
@@ -3119,20 +2629,6 @@
enum { _S_chunk_size = 7 };
- template<typename _RandomAccessIterator, typename _Distance>
- void
- __chunk_insertion_sort(_RandomAccessIterator __first,
- _RandomAccessIterator __last,
- _Distance __chunk_size)
- {
- while (__last - __first >= __chunk_size)
- {
- std::__insertion_sort(__first, __first + __chunk_size);
- __first += __chunk_size;
- }
- std::__insertion_sort(__first, __last);
- }
-
template<typename _RandomAccessIterator, typename _Distance, typename _Compare>
void
__chunk_insertion_sort(_RandomAccessIterator __first,
@@ -3147,30 +2643,6 @@
std::__insertion_sort(__first, __last, __comp);
}
- template<typename _RandomAccessIterator, typename _Pointer>
- void
- __merge_sort_with_buffer(_RandomAccessIterator __first,
- _RandomAccessIterator __last,
- _Pointer __buffer)
- {
- typedef typename iterator_traits<_RandomAccessIterator>::difference_type
- _Distance;
-
- const _Distance __len = __last - __first;
- const _Pointer __buffer_last = __buffer + __len;
-
- _Distance __step_size = _S_chunk_size;
- std::__chunk_insertion_sort(__first, __last, __step_size);
-
- while (__step_size < __len)
- {
- std::__merge_sort_loop(__first, __last, __buffer, __step_size);
- __step_size *= 2;
- std::__merge_sort_loop(__buffer, __buffer_last, __first, __step_size);
- __step_size *= 2;
- }
- }
-
template<typename _RandomAccessIterator, typename _Pointer, typename _Compare>
void
__merge_sort_with_buffer(_RandomAccessIterator __first,
@@ -3203,45 +2675,6 @@
* @endif
*/
template<typename _BidirectionalIterator1, typename _BidirectionalIterator2,
- typename _BidirectionalIterator3>
- _BidirectionalIterator3
- __merge_backward(_BidirectionalIterator1 __first1,
- _BidirectionalIterator1 __last1,
- _BidirectionalIterator2 __first2,
- _BidirectionalIterator2 __last2,
- _BidirectionalIterator3 __result)
- {
- if (__first1 == __last1)
- return std::copy_backward(__first2, __last2, __result);
- if (__first2 == __last2)
- return std::copy_backward(__first1, __last1, __result);
- --__last1;
- --__last2;
- while (true)
- {
- if (*__last2 < *__last1)
- {
- *--__result = *__last1;
- if (__first1 == __last1)
- return std::copy_backward(__first2, ++__last2, __result);
- --__last1;
- }
- else
- {
- *--__result = *__last2;
- if (__first2 == __last2)
- return std::copy_backward(__first1, ++__last1, __result);
- --__last2;
- }
- }
- }
-
- /**
- * @if maint
- * This is a helper function for the merge routines.
- * @endif
- */
- template<typename _BidirectionalIterator1, typename _BidirectionalIterator2,
typename _BidirectionalIterator3, typename _Compare>
_BidirectionalIterator3
__merge_backward(_BidirectionalIterator1 __first1,
@@ -3317,65 +2750,6 @@
* This is a helper function for the merge routines.
* @endif
*/
- template<typename _BidirectionalIterator, typename _Distance,
- typename _Pointer>
- void
- __merge_adaptive(_BidirectionalIterator __first,
- _BidirectionalIterator __middle,
- _BidirectionalIterator __last,
- _Distance __len1, _Distance __len2,
- _Pointer __buffer, _Distance __buffer_size)
- {
- if (__len1 <= __len2 && __len1 <= __buffer_size)
- {
- _Pointer __buffer_end = std::copy(__first, __middle, __buffer);
- std::merge(__buffer, __buffer_end, __middle, __last, __first);
- }
- else if (__len2 <= __buffer_size)
- {
- _Pointer __buffer_end = std::copy(__middle, __last, __buffer);
- std::__merge_backward(__first, __middle, __buffer,
- __buffer_end, __last);
- }
- else
- {
- _BidirectionalIterator __first_cut = __first;
- _BidirectionalIterator __second_cut = __middle;
- _Distance __len11 = 0;
- _Distance __len22 = 0;
- if (__len1 > __len2)
- {
- __len11 = __len1 / 2;
- std::advance(__first_cut, __len11);
- __second_cut = std::lower_bound(__middle, __last,
- *__first_cut);
- __len22 = std::distance(__middle, __second_cut);
- }
- else
- {
- __len22 = __len2 / 2;
- std::advance(__second_cut, __len22);
- __first_cut = std::upper_bound(__first, __middle,
- *__second_cut);
- __len11 = std::distance(__first, __first_cut);
- }
- _BidirectionalIterator __new_middle =
- std::__rotate_adaptive(__first_cut, __middle, __second_cut,
- __len1 - __len11, __len22, __buffer,
- __buffer_size);
- std::__merge_adaptive(__first, __first_cut, __new_middle, __len11,
- __len22, __buffer, __buffer_size);
- std::__merge_adaptive(__new_middle, __second_cut, __last,
- __len1 - __len11,
- __len2 - __len22, __buffer, __buffer_size);
- }
- }
-
- /**
- * @if maint
- * This is a helper function for the merge routines.
- * @endif
- */
template<typename _BidirectionalIterator, typename _Distance, typename _Pointer,
typename _Compare>
void
@@ -3437,6 +2811,7 @@
* @param first An iterator.
* @param middle Another iterator.
* @param last Another iterator.
+ * @param comp A functor to use for comparisons.
* @return Nothing.
*
* Merges two sorted and consecutive ranges, [first,middle) and
@@ -3448,12 +2823,16 @@
* If enough additional memory is available, this takes (last-first)-1
* comparisons. Otherwise an NlogN algorithm is used, where N is
* distance(first,last).
+ *
+ * The comparison function should have the same effects on ordering as
+ * the function used for the initial sort.
*/
- template<typename _BidirectionalIterator>
+ template<typename _BidirectionalIterator, typename _Compare>
void
inplace_merge(_BidirectionalIterator __first,
_BidirectionalIterator __middle,
- _BidirectionalIterator __last)
+ _BidirectionalIterator __last,
+ _Compare __comp)
{
typedef typename iterator_traits<_BidirectionalIterator>::value_type
_ValueType;
@@ -3463,23 +2842,26 @@
// concept requirements
__glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<
_BidirectionalIterator>)
- __glibcxx_function_requires(_LessThanComparableConcept<_ValueType>)
- __glibcxx_requires_sorted(__first, __middle);
- __glibcxx_requires_sorted(__middle, __last);
+ __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
+ _ValueType, _ValueType>)
+ __glibcxx_requires_sorted_pred(__first, __middle, __comp);
+ __glibcxx_requires_sorted_pred(__middle, __last, __comp);
if (__first == __middle || __middle == __last)
return;
- _DistanceType __len1 = std::distance(__first, __middle);
- _DistanceType __len2 = std::distance(__middle, __last);
+ const _DistanceType __len1 = std::distance(__first, __middle);
+ const _DistanceType __len2 = std::distance(__middle, __last);
_Temporary_buffer<_BidirectionalIterator, _ValueType> __buf(__first,
__last);
if (__buf.begin() == 0)
- std::__merge_without_buffer(__first, __middle, __last, __len1, __len2);
+ std::__merge_without_buffer(__first, __middle, __last, __len1,
+ __len2, __comp);
else
std::__merge_adaptive(__first, __middle, __last, __len1, __len2,
- __buf.begin(), _DistanceType(__buf.size()));
+ __buf.begin(), _DistanceType(__buf.size()),
+ __comp);
}
/**
@@ -3487,7 +2869,6 @@
* @param first An iterator.
* @param middle Another iterator.
* @param last Another iterator.
- * @param comp A functor to use for comparisons.
* @return Nothing.
*
* Merges two sorted and consecutive ranges, [first,middle) and
@@ -3499,72 +2880,19 @@
* If enough additional memory is available, this takes (last-first)-1
* comparisons. Otherwise an NlogN algorithm is used, where N is
* distance(first,last).
- *
- * The comparison function should have the same effects on ordering as
- * the function used for the initial sort.
*/
- template<typename _BidirectionalIterator, typename _Compare>
+ template<typename _BidirectionalIterator>
void
inplace_merge(_BidirectionalIterator __first,
_BidirectionalIterator __middle,
- _BidirectionalIterator __last,
- _Compare __comp)
+ _BidirectionalIterator __last)
{
typedef typename iterator_traits<_BidirectionalIterator>::value_type
_ValueType;
- typedef typename iterator_traits<_BidirectionalIterator>::difference_type
- _DistanceType;
// concept requirements
- __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept<
- _BidirectionalIterator>)
- __glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
- _ValueType, _ValueType>)
- __glibcxx_requires_sorted_pred(__first, __middle, __comp);
- __glibcxx_requires_sorted_pred(__middle, __last, __comp);
-
- if (__first == __middle || __middle == __last)
- return;
-
- const _DistanceType __len1 = std::distance(__first, __middle);
- const _DistanceType __len2 = std::distance(__middle, __last);
-
- _Temporary_buffer<_BidirectionalIterator, _ValueType> __buf(__first,
- __last);
- if (__buf.begin() == 0)
- std::__merge_without_buffer(__first, __middle, __last, __len1,
- __len2, __comp);
- else
- std::__merge_adaptive(__first, __middle, __last, __len1, __len2,
- __buf.begin(), _DistanceType(__buf.size()),
- __comp);
- }
-
- template<typename _RandomAccessIterator, typename _Pointer,
- typename _Distance>
- void
- __stable_sort_adaptive(_RandomAccessIterator __first,
- _RandomAccessIterator __last,
- _Pointer __buffer, _Distance __buffer_size)
- {
- const _Distance __len = (__last - __first + 1) / 2;
- const _RandomAccessIterator __middle = __first + __len;
- if (__len > __buffer_size)
- {
- std::__stable_sort_adaptive(__first, __middle,
- __buffer, __buffer_size);
- std::__stable_sort_adaptive(__middle, __last,
- __buffer, __buffer_size);
- }
- else
- {
- std::__merge_sort_with_buffer(__first, __middle, __buffer);
- std::__merge_sort_with_buffer(__middle, __last, __buffer);
- }
- std::__merge_adaptive(__first, __middle, __last,
- _Distance(__middle - __first),
- _Distance(__last - __middle),
- __buffer, __buffer_size);
+ __glibcxx_function_requires(_LessThanComparableConcept<_ValueType>)
+ std::inplace_merge(__first, __middle, __last, __gnu_cxx::__ops::less());
}
template<typename _RandomAccessIterator, typename _Pointer,
@@ -3593,47 +2921,7 @@
_Distance(__middle - __first),
_Distance(__last - __middle),
__buffer, __buffer_size,
- __comp);
- }
-
- /**
- * @brief Sort the elements of a sequence, preserving the relative order
- * of equivalent elements.
- * @param first An iterator.
- * @param last Another iterator.
- * @return Nothing.
- *
- * Sorts the elements in the range @p [first,last) in ascending order,
- * such that @p *(i+1)<*i is false for each iterator @p i in the range
- * @p [first,last-1).
- *
- * The relative ordering of equivalent elements is preserved, so any two
- * elements @p x and @p y in the range @p [first,last) such that
- * @p x<y is false and @p y<x is false will have the same relative
- * ordering after calling @p stable_sort().
- */
- template<typename _RandomAccessIterator>
- inline void
- stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
- {
- typedef typename iterator_traits<_RandomAccessIterator>::value_type
- _ValueType;
- typedef typename iterator_traits<_RandomAccessIterator>::difference_type
- _DistanceType;
-
- // concept requirements
- __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
- _RandomAccessIterator>)
- __glibcxx_function_requires(_LessThanComparableConcept<_ValueType>)
- __glibcxx_requires_valid_range(__first, __last);
-
- _Temporary_buffer<_RandomAccessIterator, _ValueType>
- buf(__first, __last);
- if (buf.begin() == 0)
- std::__inplace_stable_sort(__first, __last);
- else
- std::__stable_sort_adaptive(__first, __last, buf.begin(),
- _DistanceType(buf.size()));
+ __comp);
}
/**
@@ -3679,54 +2967,33 @@
_DistanceType(buf.size()), __comp);
}
+
/**
- * @brief Sort a sequence just enough to find a particular position.
+ * @brief Sort the elements of a sequence, preserving the relative order
+ * of equivalent elements.
* @param first An iterator.
- * @param nth Another iterator.
* @param last Another iterator.
* @return Nothing.
*
- * Rearranges the elements in the range @p [first,last) so that @p *nth
- * is the same element that would have been in that position had the
- * whole sequence been sorted.
- * whole sequence been sorted. The elements either side of @p *nth are
- * not completely sorted, but for any iterator @i in the range
- * @p [first,nth) and any iterator @j in the range @p [nth,last) it
- * holds that @p *j<*i is false.
+ * Sorts the elements in the range @p [first,last) in ascending order,
+ * such that @p *(i+1)<*i is false for each iterator @p i in the range
+ * @p [first,last-1).
+ *
+ * The relative ordering of equivalent elements is preserved, so any two
+ * elements @p x and @p y in the range @p [first,last) such that
+ * @p x<y is false and @p y<x is false will have the same relative
+ * ordering after calling @p stable_sort().
*/
template<typename _RandomAccessIterator>
- void
- nth_element(_RandomAccessIterator __first,
- _RandomAccessIterator __nth,
- _RandomAccessIterator __last)
+ inline void
+ stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
{
typedef typename iterator_traits<_RandomAccessIterator>::value_type
_ValueType;
// concept requirements
- __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
- _RandomAccessIterator>)
__glibcxx_function_requires(_LessThanComparableConcept<_ValueType>)
- __glibcxx_requires_valid_range(__first, __nth);
- __glibcxx_requires_valid_range(__nth, __last);
-
- while (__last - __first > 3)
- {
- _RandomAccessIterator __cut =
- std::__unguarded_partition(__first, __last,
- _ValueType(std::__median(*__first,
- *(__first
- + (__last
- - __first)
- / 2),
- *(__last
- - 1))));
- if (__cut <= __nth)
- __first = __cut;
- else
- __last = __cut;
- }
- std::__insertion_sort(__first, __last);
+ return stable_sort(__first, __last, __gnu_cxx::__ops::less());
}
/**
@@ -3783,64 +3050,32 @@
}
/**
- * @brief Finds the largest subrange in which @a val could be inserted
- * at any place in it without changing the ordering.
+ * @brief Sort a sequence just enough to find a particular position.
* @param first An iterator.
+ * @param nth Another iterator.
* @param last Another iterator.
- * @param val The search term.
- * @return An pair of iterators defining the subrange.
- * @ingroup binarysearch
+ * @return Nothing.
*
- * This is equivalent to
- * @code
- * std::make_pair(lower_bound(first, last, val),
- * upper_bound(first, last, val))
- * @endcode
- * but does not actually call those functions.
+ * Rearranges the elements in the range @p [first,last) so that @p *nth
+ * is the same element that would have been in that position had the
+ * whole sequence been sorted.
+ * whole sequence been sorted. The elements either side of @p *nth are
+ * not completely sorted, but for any iterator @i in the range
+ * @p [first,nth) and any iterator @j in the range @p [nth,last) it
+ * holds that @p *j<*i is false.
*/
- template<typename _ForwardIterator, typename _Tp>
- pair<_ForwardIterator, _ForwardIterator>
- equal_range(_ForwardIterator __first, _ForwardIterator __last,
- const _Tp& __val)
+ template<typename _RandomAccessIterator>
+ void
+ nth_element(_RandomAccessIterator __first,
+ _RandomAccessIterator __nth,
+ _RandomAccessIterator __last)
{
- typedef typename iterator_traits<_ForwardIterator>::value_type
+ typedef typename iterator_traits<_RandomAccessIterator>::value_type
_ValueType;
- typedef typename iterator_traits<_ForwardIterator>::difference_type
- _DistanceType;
// concept requirements
- // See comments on lower_bound.
- __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
- __glibcxx_function_requires(_SameTypeConcept<_Tp, _ValueType>)
- __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
- __glibcxx_requires_partitioned(__first, __last, __val);
-
- _DistanceType __len = std::distance(__first, __last);
- _DistanceType __half;
- _ForwardIterator __middle, __left, __right;
-
- while (__len > 0)
- {
- __half = __len >> 1;
- __middle = __first;
- std::advance(__middle, __half);
- if (*__middle < __val)
- {
- __first = __middle;
- ++__first;
- __len = __len - __half - 1;
- }
- else if (__val < *__middle)
- __len = __half;
- else
- {
- __left = std::lower_bound(__first, __middle, __val);
- std::advance(__first, __len);
- __right = std::upper_bound(++__middle, __first, __val);
- return pair<_ForwardIterator, _ForwardIterator>(__left, __right);
- }
- }
- return pair<_ForwardIterator, _ForwardIterator>(__first, __first);
+ __glibcxx_function_requires(_LessThanComparableConcept<_ValueType>)
+ std::nth_element(__first, __nth, __last, __gnu_cxx::__ops::less());
}
/**
@@ -3908,31 +3143,37 @@
}
/**
- * @brief Determines whether an element exists in a range.
+ * @brief Finds the largest subrange in which @a val could be inserted
+ * at any place in it without changing the ordering.
* @param first An iterator.
* @param last Another iterator.
* @param val The search term.
- * @return True if @a val (or its equivelent) is in [@a first,@a last ].
+ * @return An pair of iterators defining the subrange.
* @ingroup binarysearch
*
- * Note that this does not actually return an iterator to @a val. For
- * that, use std::find or a container's specialized find member functions.
+ * This is equivalent to
+ * @code
+ * std::make_pair(lower_bound(first, last, val),
+ * upper_bound(first, last, val))
+ * @endcode
+ * but does not actually call those functions.
*/
template<typename _ForwardIterator, typename _Tp>
- bool
- binary_search(_ForwardIterator __first, _ForwardIterator __last,
- const _Tp& __val)
+ pair<_ForwardIterator, _ForwardIterator>
+ equal_range(_ForwardIterator __first, _ForwardIterator __last,
+ const _Tp& __val)
{
+ typedef typename iterator_traits<_ForwardIterator>::value_type
+ _ValueType;
+ typedef typename iterator_traits<_ForwardIterator>::difference_type
+ _DistanceType;
+
// concept requirements
// See comments on lower_bound.
- __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
- __glibcxx_function_requires(_SameTypeConcept<_Tp,
- typename iterator_traits<_ForwardIterator>::value_type>)
+ __glibcxx_function_requires(_SameTypeConcept<_Tp, _ValueType>)
__glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
- __glibcxx_requires_partitioned(__first, __last, __val);
-
- _ForwardIterator __i = std::lower_bound(__first, __last, __val);
- return __i != __last && !(__val < *__i);
+
+ return std::equal_range(__first, __last, __val, __gnu_cxx::__ops::less());
}
/**
@@ -3967,54 +3208,35 @@
return __i != __last && !__comp(__val, *__i);
}
- // Set algorithms: includes, set_union, set_intersection, set_difference,
- // set_symmetric_difference. All of these algorithms have the precondition
- // that their input ranges are sorted and the postcondition that their output
- // ranges are sorted.
-
/**
- * @brief Determines whether all elements of a sequence exists in a range.
- * @param first1 Start of search range.
- * @param last1 End of search range.
- * @param first2 Start of sequence
- * @param last2 End of sequence.
- * @return True if each element in [first2,last2) is contained in order
- * within [first1,last1). False otherwise.
- * @ingroup setoperations
+ * @brief Determines whether an element exists in a range.
+ * @param first An iterator.
+ * @param last Another iterator.
+ * @param val The search term.
+ * @return True if @a val (or its equivelent) is in [@a first,@a last ].
+ * @ingroup binarysearch
*
- * This operation expects both [first1,last1) and [first2,last2) to be
- * sorted. Searches for the presence of each element in [first2,last2)
- * within [first1,last1). The iterators over each range only move forward,
- * so this is a linear algorithm. If an element in [first2,last2) is not
- * found before the search iterator reaches @a last2, false is returned.
+ * Note that this does not actually return an iterator to @a val. For
+ * that, use std::find or a container's specialized find member functions.
*/
- template<typename _InputIterator1, typename _InputIterator2>
+ template<typename _ForwardIterator, typename _Tp>
bool
- includes(_InputIterator1 __first1, _InputIterator1 __last1,
- _InputIterator2 __first2, _InputIterator2 __last2)
+ binary_search(_ForwardIterator __first, _ForwardIterator __last,
+ const _Tp& __val)
{
// concept requirements
- __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
- __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
- __glibcxx_function_requires(_SameTypeConcept<
- typename iterator_traits<_InputIterator1>::value_type,
- typename iterator_traits<_InputIterator2>::value_type>)
- __glibcxx_function_requires(_LessThanComparableConcept<
- typename iterator_traits<_InputIterator1>::value_type>)
- __glibcxx_requires_sorted(__first1, __last1);
- __glibcxx_requires_sorted(__first2, __last2);
-
- while (__first1 != __last1 && __first2 != __last2)
- if (*__first2 < *__first1)
- return false;
- else if(*__first1 < *__first2)
- ++__first1;
- else
- ++__first1, ++__first2;
-
- return __first2 == __last2;
+ // See comments on lower_bound.
+ __glibcxx_function_requires(_SameTypeConcept<_Tp,
+ typename iterator_traits<_ForwardIterator>::value_type>)
+ __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
+ return std::binary_search(__first, __last, __val, __gnu_cxx::__ops::less());
}
+ // Set algorithms: includes, set_union, set_intersection, set_difference,
+ // set_symmetric_difference. All of these algorithms have the precondition
+ // that their input ranges are sorted and the postcondition that their output
+ // ranges are sorted.
+
/**
* @brief Determines whether all elements of a sequence exists in a range
* using comparison.
@@ -4064,64 +3286,32 @@
}
/**
- * @brief Return the union of two sorted ranges.
- * @param first1 Start of first range.
- * @param last1 End of first range.
- * @param first2 Start of second range.
- * @param last2 End of second range.
- * @return End of the output range.
+ * @brief Determines whether all elements of a sequence exists in a range.
+ * @param first1 Start of search range.
+ * @param last1 End of search range.
+ * @param first2 Start of sequence
+ * @param last2 End of sequence.
+ * @return True if each element in [first2,last2) is contained in order
+ * within [first1,last1). False otherwise.
* @ingroup setoperations
*
- * This operation iterates over both ranges, copying elements present in
- * each range in order to the output range. Iterators increment for each
- * range. When the current element of one range is less than the other,
- * that element is copied and the iterator advanced. If an element is
- * contained in both ranges, the element from the first range is copied and
- * both ranges advance. The output range may not overlap either input
- * range.
- */
- template<typename _InputIterator1, typename _InputIterator2,
- typename _OutputIterator>
- _OutputIterator
- set_union(_InputIterator1 __first1, _InputIterator1 __last1,
- _InputIterator2 __first2, _InputIterator2 __last2,
- _OutputIterator __result)
- {
- // concept requirements
- __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
- __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
- __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
- typename iterator_traits<_InputIterator1>::value_type>)
- __glibcxx_function_requires(_SameTypeConcept<
- typename iterator_traits<_InputIterator1>::value_type,
- typename iterator_traits<_InputIterator2>::value_type>)
- __glibcxx_function_requires(_LessThanComparableConcept<
- typename iterator_traits<_InputIterator1>::value_type>)
- __glibcxx_requires_sorted(__first1, __last1);
- __glibcxx_requires_sorted(__first2, __last2);
-
- while (__first1 != __last1 && __first2 != __last2)
- {
- if (*__first1 < *__first2)
- {
- *__result = *__first1;
- ++__first1;
- }
- else if (*__first2 < *__first1)
- {
- *__result = *__first2;
- ++__first2;
- }
- else
- {
- *__result = *__first1;
- ++__first1;
- ++__first2;
- }
- ++__result;
- }
- return std::copy(__first2, __last2, std::copy(__first1, __last1,
- __result));
+ * This operation expects both [first1,last1) and [first2,last2) to be
+ * sorted. Searches for the presence of each element in [first2,last2)
+ * within [first1,last1). The iterators over each range only move forward,
+ * so this is a linear algorithm. If an element in [first2,last2) is not
+ * found before the search iterator reaches @a last2, false is returned.
+ */
+ template<typename _InputIterator1, typename _InputIterator2>
+ bool
+ includes(_InputIterator1 __first1, _InputIterator1 __last1,
+ _InputIterator2 __first2, _InputIterator2 __last2)
+ {
+ // concept requirements
+ __glibcxx_function_requires(_LessThanComparableConcept<
+ typename iterator_traits<_InputIterator1>::value_type>)
+ ;
+ return std::includes(__first1, __last1, __first2, __last2,
+ __gnu_cxx::__ops::less());
}
/**
@@ -4188,7 +3378,7 @@
}
/**
- * @brief Return the intersection of two sorted ranges.
+ * @brief Return the union of two sorted ranges.
* @param first1 Start of first range.
* @param last1 End of first range.
* @param first2 Start of second range.
@@ -4197,45 +3387,25 @@
* @ingroup setoperations
*
* This operation iterates over both ranges, copying elements present in
- * both ranges in order to the output range. Iterators increment for each
+ * each range in order to the output range. Iterators increment for each
* range. When the current element of one range is less than the other,
- * that iterator advances. If an element is contained in both ranges, the
- * element from the first range is copied and both ranges advance. The
- * output range may not overlap either input range.
+ * that element is copied and the iterator advanced. If an element is
+ * contained in both ranges, the element from the first range is copied and
+ * both ranges advance. The output range may not overlap either input
+ * range.
*/
template<typename _InputIterator1, typename _InputIterator2,
typename _OutputIterator>
_OutputIterator
- set_intersection(_InputIterator1 __first1, _InputIterator1 __last1,
- _InputIterator2 __first2, _InputIterator2 __last2,
- _OutputIterator __result)
+ set_union(_InputIterator1 __first1, _InputIterator1 __last1,
+ _InputIterator2 __first2, _InputIterator2 __last2,
+ _OutputIterator __result)
{
// concept requirements
- __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
- __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
- __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
- typename iterator_traits<_InputIterator1>::value_type>)
- __glibcxx_function_requires(_SameTypeConcept<
- typename iterator_traits<_InputIterator1>::value_type,
- typename iterator_traits<_InputIterator2>::value_type>)
__glibcxx_function_requires(_LessThanComparableConcept<
typename iterator_traits<_InputIterator1>::value_type>)
- __glibcxx_requires_sorted(__first1, __last1);
- __glibcxx_requires_sorted(__first2, __last2);
-
- while (__first1 != __last1 && __first2 != __last2)
- if (*__first1 < *__first2)
- ++__first1;
- else if (*__first2 < *__first1)
- ++__first2;
- else
- {
- *__result = *__first1;
- ++__first1;
- ++__first2;
- ++__result;
- }
- return __result;
+ return std::set_union(__first1, __last1, __first2, __last2, __result,
+ __gnu_cxx::__ops::less());
}
/**
@@ -4294,7 +3464,7 @@
}
/**
- * @brief Return the difference of two sorted ranges.
+ * @brief Return the intersection of two sorted ranges.
* @param first1 Start of first range.
* @param last1 End of first range.
* @param first2 Start of second range.
@@ -4303,49 +3473,24 @@
* @ingroup setoperations
*
* This operation iterates over both ranges, copying elements present in
- * the first range but not the second in order to the output range.
- * Iterators increment for each range. When the current element of the
- * first range is less than the second, that element is copied and the
- * iterator advances. If the current element of the second range is less,
- * the iterator advances, but no element is copied. If an element is
- * contained in both ranges, no elements are copied and both ranges
- * advance. The output range may not overlap either input range.
+ * both ranges in order to the output range. Iterators increment for each
+ * range. When the current element of one range is less than the other,
+ * that iterator advances. If an element is contained in both ranges, the
+ * element from the first range is copied and both ranges advance. The
+ * output range may not overlap either input range.
*/
template<typename _InputIterator1, typename _InputIterator2,
typename _OutputIterator>
_OutputIterator
- set_difference(_InputIterator1 __first1, _InputIterator1 __last1,
- _InputIterator2 __first2, _InputIterator2 __last2,
- _OutputIterator __result)
+ set_intersection(_InputIterator1 __first1, _InputIterator1 __last1,
+ _InputIterator2 __first2, _InputIterator2 __last2,
+ _OutputIterator __result)
{
// concept requirements
- __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
- __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
- __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
- typename iterator_traits<_InputIterator1>::value_type>)
- __glibcxx_function_requires(_SameTypeConcept<
- typename iterator_traits<_InputIterator1>::value_type,
- typename iterator_traits<_InputIterator2>::value_type>)
__glibcxx_function_requires(_LessThanComparableConcept<
typename iterator_traits<_InputIterator1>::value_type>)
- __glibcxx_requires_sorted(__first1, __last1);
- __glibcxx_requires_sorted(__first2, __last2);
-
- while (__first1 != __last1 && __first2 != __last2)
- if (*__first1 < *__first2)
- {
- *__result = *__first1;
- ++__first1;
- ++__result;
- }
- else if (*__first2 < *__first1)
- ++__first2;
- else
- {
- ++__first1;
- ++__first2;
- }
- return std::copy(__first1, __last1, __result);
+ return std::set_intersection(__first1, __last1, __first2, __last2,
+ __result, __gnu_cxx::__ops::less());
}
/**
@@ -4408,7 +3553,7 @@
}
/**
- * @brief Return the symmetric difference of two sorted ranges.
+ * @brief Return the difference of two sorted ranges.
* @param first1 Start of first range.
* @param last1 End of first range.
* @param first2 Start of second range.
@@ -4417,52 +3562,26 @@
* @ingroup setoperations
*
* This operation iterates over both ranges, copying elements present in
- * one range but not the other in order to the output range. Iterators
- * increment for each range. When the current element of one range is less
- * than the other, that element is copied and the iterator advances. If an
- * element is contained in both ranges, no elements are copied and both
- * ranges advance. The output range may not overlap either input range.
+ * the first range but not the second in order to the output range.
+ * Iterators increment for each range. When the current element of the
+ * first range is less than the second, that element is copied and the
+ * iterator advances. If the current element of the second range is less,
+ * the iterator advances, but no element is copied. If an element is
+ * contained in both ranges, no elements are copied and both ranges
+ * advance. The output range may not overlap either input range.
*/
template<typename _InputIterator1, typename _InputIterator2,
typename _OutputIterator>
_OutputIterator
- set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1,
- _InputIterator2 __first2, _InputIterator2 __last2,
- _OutputIterator __result)
+ set_difference(_InputIterator1 __first1, _InputIterator1 __last1,
+ _InputIterator2 __first2, _InputIterator2 __last2,
+ _OutputIterator __result)
{
// concept requirements
- __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
- __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
- __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
- typename iterator_traits<_InputIterator1>::value_type>)
- __glibcxx_function_requires(_SameTypeConcept<
- typename iterator_traits<_InputIterator1>::value_type,
- typename iterator_traits<_InputIterator2>::value_type>)
__glibcxx_function_requires(_LessThanComparableConcept<
typename iterator_traits<_InputIterator1>::value_type>)
- __glibcxx_requires_sorted(__first1, __last1);
- __glibcxx_requires_sorted(__first2, __last2);
-
- while (__first1 != __last1 && __first2 != __last2)
- if (*__first1 < *__first2)
- {
- *__result = *__first1;
- ++__first1;
- ++__result;
- }
- else if (*__first2 < *__first1)
- {
- *__result = *__first2;
- ++__first2;
- ++__result;
- }
- else
- {
- ++__first1;
- ++__first2;
- }
- return std::copy(__first2, __last2, std::copy(__first1,
- __last1, __result));
+ return std::set_difference(__first1, __last1, __first2, __last2,
+ __result, __gnu_cxx::__ops::less());
}
/**
@@ -4528,34 +3647,39 @@
__last1, __result));
}
- // min_element and max_element, with and without an explicitly supplied
- // comparison function.
-
/**
- * @brief Return the maximum element in a range.
- * @param first Start of range.
- * @param last End of range.
- * @return Iterator referencing the first instance of the largest value.
+ * @brief Return the symmetric difference of two sorted ranges.
+ * @param first1 Start of first range.
+ * @param last1 End of first range.
+ * @param first2 Start of second range.
+ * @param last2 End of second range.
+ * @return End of the output range.
+ * @ingroup setoperations
+ *
+ * This operation iterates over both ranges, copying elements present in
+ * one range but not the other in order to the output range. Iterators
+ * increment for each range. When the current element of one range is less
+ * than the other, that element is copied and the iterator advances. If an
+ * element is contained in both ranges, no elements are copied and both
+ * ranges advance. The output range may not overlap either input range.
*/
- template<typename _ForwardIterator>
- _ForwardIterator
- max_element(_ForwardIterator __first, _ForwardIterator __last)
+ template<typename _InputIterator1, typename _InputIterator2,
+ typename _OutputIterator>
+ _OutputIterator
+ set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1,
+ _InputIterator2 __first2, _InputIterator2 __last2,
+ _OutputIterator __result)
{
// concept requirements
- __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
__glibcxx_function_requires(_LessThanComparableConcept<
- typename iterator_traits<_ForwardIterator>::value_type>)
- __glibcxx_requires_valid_range(__first, __last);
-
- if (__first == __last)
- return __first;
- _ForwardIterator __result = __first;
- while (++__first != __last)
- if (*__result < *__first)
- __result = __first;
- return __result;
+ typename iterator_traits<_InputIterator1>::value_type>)
+ return std::set_symmetric_difference(__first1, __last1, __first2, __last2,
+ __result, __gnu_cxx::__ops::less());
}
+ // min_element and max_element, with and without an explicitly supplied
+ // comparison function.
+
/**
* @brief Return the maximum element in a range using comparison functor.
* @param first Start of range.
@@ -4584,28 +3708,19 @@
}
/**
- * @brief Return the minimum element in a range.
+ * @brief Return the maximum element in a range.
* @param first Start of range.
* @param last End of range.
- * @return Iterator referencing the first instance of the smallest value.
+ * @return Iterator referencing the first instance of the largest value.
*/
template<typename _ForwardIterator>
_ForwardIterator
- min_element(_ForwardIterator __first, _ForwardIterator __last)
+ max_element(_ForwardIterator __first, _ForwardIterator __last)
{
// concept requirements
- __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
__glibcxx_function_requires(_LessThanComparableConcept<
typename iterator_traits<_ForwardIterator>::value_type>)
- __glibcxx_requires_valid_range(__first, __last);
-
- if (__first == __last)
- return __first;
- _ForwardIterator __result = __first;
- while (++__first != __last)
- if (*__first < *__result)
- __result = __first;
- return __result;
+ return std::max_element(__first, __last, __gnu_cxx::__ops::less());
}
/**
@@ -4625,74 +3740,37 @@
__glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
__glibcxx_function_requires(_BinaryPredicateConcept<_Compare,
typename iterator_traits<_ForwardIterator>::value_type,
- typename iterator_traits<_ForwardIterator>::value_type>)
- __glibcxx_requires_valid_range(__first, __last);
-
- if (__first == __last)
- return __first;
- _ForwardIterator __result = __first;
- while (++__first != __last)
- if (__comp(*__first, *__result))
- __result = __first;
- return __result;
- }
-
- // next_permutation and prev_permutation, with and without an explicitly
- // supplied comparison function.
-
- /**
- * @brief Permute range into the next "dictionary" ordering.
- * @param first Start of range.
- * @param last End of range.
- * @return False if wrapped to first permutation, true otherwise.
- *
- * Treats all permutations of the range as a set of "dictionary" sorted
- * sequences. Permutes the current sequence into the next one of this set.
- * Returns true if there are more sequences to generate. If the sequence
- * is the largest of the set, the smallest is generated and false returned.
- */
- template<typename _BidirectionalIterator>
- bool
- next_permutation(_BidirectionalIterator __first,
- _BidirectionalIterator __last)
- {
- // concept requirements
- __glibcxx_function_requires(_BidirectionalIteratorConcept<
- _BidirectionalIterator>)
- __glibcxx_function_requires(_LessThanComparableConcept<
- typename iterator_traits<_BidirectionalIterator>::value_type>)
- __glibcxx_requires_valid_range(__first, __last);
-
- if (__first == __last)
- return false;
- _BidirectionalIterator __i = __first;
- ++__i;
- if (__i == __last)
- return false;
- __i = __last;
- --__i;
-
- for(;;)
- {
- _BidirectionalIterator __ii = __i;
- --__i;
- if (*__i < *__ii)
- {
- _BidirectionalIterator __j = __last;
- while (!(*__i < *--__j))
- {}
- std::iter_swap(__i, __j);
- std::reverse(__ii, __last);
- return true;
- }
- if (__i == __first)
- {
- std::reverse(__first, __last);
- return false;
- }
- }
+ typename iterator_traits<_ForwardIterator>::value_type>)
+ __glibcxx_requires_valid_range(__first, __last);
+
+ if (__first == __last)
+ return __first;
+ _ForwardIterator __result = __first;
+ while (++__first != __last)
+ if (__comp(*__first, *__result))
+ __result = __first;
+ return __result;
+ }
+
+ /**
+ * @brief Return the minimum element in a range.
+ * @param first Start of range.
+ * @param last End of range.
+ * @return Iterator referencing the first instance of the smallest value.
+ */
+ template<typename _ForwardIterator>
+ _ForwardIterator
+ min_element(_ForwardIterator __first, _ForwardIterator __last)
+ {
+ // concept requirements
+ __glibcxx_function_requires(_LessThanComparableConcept<
+ typename iterator_traits<_ForwardIterator>::value_type>)
+ return std::min_element(__first, __last, __gnu_cxx::__ops::less());
}
+ // next_permutation and prev_permutation, with and without an explicitly
+ // supplied comparison function.
+
/**
* @brief Permute range into the next "dictionary" ordering using
* comparison functor.
@@ -4751,57 +3829,25 @@
}
/**
- * @brief Permute range into the previous "dictionary" ordering.
+ * @brief Permute range into the next "dictionary" ordering.
* @param first Start of range.
* @param last End of range.
- * @return False if wrapped to last permutation, true otherwise.
+ * @return False if wrapped to first permutation, true otherwise.
*
* Treats all permutations of the range as a set of "dictionary" sorted
- * sequences. Permutes the current sequence into the previous one of this
- * set. Returns true if there are more sequences to generate. If the
- * sequence is the smallest of the set, the largest is generated and false
- * returned.
+ * sequences. Permutes the current sequence into the next one of this set.
+ * Returns true if there are more sequences to generate. If the sequence
+ * is the largest of the set, the smallest is generated and false returned.
*/
template<typename _BidirectionalIterator>
bool
- prev_permutation(_BidirectionalIterator __first,
+ next_permutation(_BidirectionalIterator __first,
_BidirectionalIterator __last)
{
// concept requirements
- __glibcxx_function_requires(_BidirectionalIteratorConcept<
- _BidirectionalIterator>)
__glibcxx_function_requires(_LessThanComparableConcept<
typename iterator_traits<_BidirectionalIterator>::value_type>)
- __glibcxx_requires_valid_range(__first, __last);
-
- if (__first == __last)
- return false;
- _BidirectionalIterator __i = __first;
- ++__i;
- if (__i == __last)
- return false;
- __i = __last;
- --__i;
-
- for(;;)
- {
- _BidirectionalIterator __ii = __i;
- --__i;
- if (*__ii < *__i)
- {
- _BidirectionalIterator __j = __last;
- while (!(*--__j < *__i))
- {}
- std::iter_swap(__i, __j);
- std::reverse(__ii, __last);
- return true;
- }
- if (__i == __first)
- {
- std::reverse(__first, __last);
- return false;
- }
- }
+ return std::next_permutation(__first, __last, __gnu_cxx::__ops::less());
}
/**
@@ -4861,31 +3907,57 @@
}
}
+ /**
+ * @brief Permute range into the previous "dictionary" ordering.
+ * @param first Start of range.
+ * @param last End of range.
+ * @return False if wrapped to last permutation, true otherwise.
+ *
+ * Treats all permutations of the range as a set of "dictionary" sorted
+ * sequences. Permutes the current sequence into the previous one of this
+ * set. Returns true if there are more sequences to generate. If the
+ * sequence is the smallest of the set, the largest is generated and false
+ * returned.
+ */
+ template<typename _BidirectionalIterator>
+ bool
+ prev_permutation(_BidirectionalIterator __first,
+ _BidirectionalIterator __last)
+ {
+ // concept requirements
+ __glibcxx_function_requires(_LessThanComparableConcept<
+ typename iterator_traits<_BidirectionalIterator>::value_type>)
+ return std::prev_permutation(__first, __last, __gnu_cxx::__ops::less());
+ }
+
// find_first_of, with and without an explicitly supplied comparison function.
/**
- * @brief Find element from a set in a sequence.
+ * @brief Find element from a set in a sequence using a predicate.
* @param first1 Start of range to search.
* @param last1 End of range to search.
* @param first2 Start of match candidates.
* @param last2 End of match candidates.
+ * @param comp Predicate to use.
* @return The first iterator @c i in the range
- * @p [first1,last1) such that @c *i == @p *(i2) such that i2 is an
+ * @p [first1,last1) such that @c comp(*i, @p *(i2)) is true and i2 is an
* interator in [first2,last2), or @p last1 if no such iterator exists.
*
* Searches the range @p [first1,last1) for an element that is equal to
- * some element in the range [first2,last2). If found, returns an iterator
- * in the range [first1,last1), otherwise returns @p last1.
+ * some element in the range [first2,last2). If found, returns an iterator in
+ * the range [first1,last1), otherwise returns @p last1.
*/
- template<typename _InputIterator, typename _ForwardIterator>
+ template<typename _InputIterator, typename _ForwardIterator,
+ typename _BinaryPredicate>
_InputIterator
find_first_of(_InputIterator __first1, _InputIterator __last1,
- _ForwardIterator __first2, _ForwardIterator __last2)
+ _ForwardIterator __first2, _ForwardIterator __last2,
+ _BinaryPredicate __comp)
{
// concept requirements
__glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
__glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
- __glibcxx_function_requires(_EqualOpConcept<
+ __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
typename iterator_traits<_InputIterator>::value_type,
typename iterator_traits<_ForwardIterator>::value_type>)
__glibcxx_requires_valid_range(__first1, __last1);
@@ -4893,83 +3965,44 @@
for ( ; __first1 != __last1; ++__first1)
for (_ForwardIterator __iter = __first2; __iter != __last2; ++__iter)
- if (*__first1 == *__iter)
+ if (__comp(*__first1, *__iter))
return __first1;
return __last1;
}
/**
- * @brief Find element from a set in a sequence using a predicate.
+ * @brief Find element from a set in a sequence.
* @param first1 Start of range to search.
* @param last1 End of range to search.
* @param first2 Start of match candidates.
* @param last2 End of match candidates.
- * @param comp Predicate to use.
* @return The first iterator @c i in the range
- * @p [first1,last1) such that @c comp(*i, @p *(i2)) is true and i2 is an
+ * @p [first1,last1) such that @c *i == @p *(i2) such that i2 is an
* interator in [first2,last2), or @p last1 if no such iterator exists.
*
* Searches the range @p [first1,last1) for an element that is equal to
- * some element in the range [first2,last2). If found, returns an iterator in
- * the range [first1,last1), otherwise returns @p last1.
+ * some element in the range [first2,last2). If found, returns an iterator
+ * in the range [first1,last1), otherwise returns @p last1.
*/
- template<typename _InputIterator, typename _ForwardIterator,
- typename _BinaryPredicate>
+ template<typename _InputIterator, typename _ForwardIterator>
_InputIterator
find_first_of(_InputIterator __first1, _InputIterator __last1,
- _ForwardIterator __first2, _ForwardIterator __last2,
- _BinaryPredicate __comp)
+ _ForwardIterator __first2, _ForwardIterator __last2)
{
// concept requirements
- __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
- __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>)
- __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
+ __glibcxx_function_requires(_EqualOpConcept<
typename iterator_traits<_InputIterator>::value_type,
typename iterator_traits<_ForwardIterator>::value_type>)
- __glibcxx_requires_valid_range(__first1, __last1);
- __glibcxx_requires_valid_range(__first2, __last2);
-
- for ( ; __first1 != __last1; ++__first1)
- for (_ForwardIterator __iter = __first2; __iter != __last2; ++__iter)
- if (__comp(*__first1, *__iter))
- return __first1;
- return __last1;
+ return std::find_first_of(__first1, __last1, __first2, __last2,
+ __gnu_cxx::__ops::equal_to());
}
-
// find_end, with and without an explicitly supplied comparison function.
// Search [first2, last2) as a subsequence in [first1, last1), and return
// the *last* possible match. Note that find_end for bidirectional iterators
// is much faster than for forward iterators.
// find_end for forward iterators.
- template<typename _ForwardIterator1, typename _ForwardIterator2>
- _ForwardIterator1
- __find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
- _ForwardIterator2 __first2, _ForwardIterator2 __last2,
- forward_iterator_tag, forward_iterator_tag)
- {
- if (__first2 == __last2)
- return __last1;
- else
- {
- _ForwardIterator1 __result = __last1;
- while (1)
- {
- _ForwardIterator1 __new_result
- = std::search(__first1, __last1, __first2, __last2);
- if (__new_result == __last1)
- return __result;
- else
- {
- __result = __new_result;
- __first1 = __new_result;
- ++__first1;
- }
- }
- }
- }
-
template<typename _ForwardIterator1, typename _ForwardIterator2,
typename _BinaryPredicate>
_ForwardIterator1
@@ -5000,38 +4033,6 @@
}
// find_end for bidirectional iterators. Requires partial specialization.
- template<typename _BidirectionalIterator1, typename _BidirectionalIterator2>
- _BidirectionalIterator1
- __find_end(_BidirectionalIterator1 __first1,
- _BidirectionalIterator1 __last1,
- _BidirectionalIterator2 __first2,
- _BidirectionalIterator2 __last2,
- bidirectional_iterator_tag, bidirectional_iterator_tag)
- {
- // concept requirements
- __glibcxx_function_requires(_BidirectionalIteratorConcept<
- _BidirectionalIterator1>)
- __glibcxx_function_requires(_BidirectionalIteratorConcept<
- _BidirectionalIterator2>)
-
- typedef reverse_iterator<_BidirectionalIterator1> _RevIterator1;
- typedef reverse_iterator<_BidirectionalIterator2> _RevIterator2;
-
- _RevIterator1 __rlast1(__first1);
- _RevIterator2 __rlast2(__first2);
- _RevIterator1 __rresult = std::search(_RevIterator1(__last1), __rlast1,
- _RevIterator2(__last2), __rlast2);
-
- if (__rresult == __rlast1)
- return __last1;
- else
- {
- _BidirectionalIterator1 __result = __rresult.base();
- std::advance(__result, -std::distance(__first2, __last2));
- return __result;
- }
- }
-
template<typename _BidirectionalIterator1, typename _BidirectionalIterator2,
typename _BinaryPredicate>
_BidirectionalIterator1
@@ -5070,21 +4071,23 @@
// Dispatching functions for find_end.
/**
- * @brief Find last matching subsequence in a sequence.
+ * @brief Find last matching subsequence in a sequence using a predicate.
* @param first1 Start of range to search.
* @param last1 End of range to search.
* @param first2 Start of sequence to match.
* @param last2 End of sequence to match.
+ * @param comp The predicate to use.
* @return The last iterator @c i in the range
- * @p [first1,last1-(last2-first2)) such that @c *(i+N) == @p *(first2+N)
- * for each @c N in the range @p [0,last2-first2), or @p last1 if no
- * such iterator exists.
+ * @p [first1,last1-(last2-first2)) such that @c predicate(*(i+N), @p
+ * (first2+N)) is true for each @c N in the range @p [0,last2-first2), or
+ * @p last1 if no such iterator exists.
*
* Searches the range @p [first1,last1) for a sub-sequence that compares
- * equal value-by-value with the sequence given by @p [first2,last2) and
- * returns an iterator to the first element of the sub-sequence, or
- * @p last1 if the sub-sequence is not found. The sub-sequence will be the
- * last such subsequence contained in [first,last1).
+ * equal value-by-value with the sequence given by @p [first2,last2) using
+ * comp as a predicate and returns an iterator to the first element of the
+ * sub-sequence, or @p last1 if the sub-sequence is not found. The
+ * sub-sequence will be the last such subsequence contained in
+ * [first,last1).
*
* Because the sub-sequence must lie completely within the range
* @p [first1,last1) it must start at a position less than
@@ -5093,15 +4096,17 @@
* This means that the returned iterator @c i will be in the range
* @p [first1,last1-(last2-first2))
*/
- template<typename _ForwardIterator1, typename _ForwardIterator2>
+ template<typename _ForwardIterator1, typename _ForwardIterator2,
+ typename _BinaryPredicate>
inline _ForwardIterator1
find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
- _ForwardIterator2 __first2, _ForwardIterator2 __last2)
+ _ForwardIterator2 __first2, _ForwardIterator2 __last2,
+ _BinaryPredicate __comp)
{
// concept requirements
__glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
__glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
- __glibcxx_function_requires(_EqualOpConcept<
+ __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
typename iterator_traits<_ForwardIterator1>::value_type,
typename iterator_traits<_ForwardIterator2>::value_type>)
__glibcxx_requires_valid_range(__first1, __last1);
@@ -5109,27 +4114,26 @@
return std::__find_end(__first1, __last1, __first2, __last2,
std::__iterator_category(__first1),
- std::__iterator_category(__first2));
+ std::__iterator_category(__first2),
+ __comp);
}
/**
- * @brief Find last matching subsequence in a sequence using a predicate.
+ * @brief Find last matching subsequence in a sequence.
* @param first1 Start of range to search.
* @param last1 End of range to search.
* @param first2 Start of sequence to match.
* @param last2 End of sequence to match.
- * @param comp The predicate to use.
* @return The last iterator @c i in the range
- * @p [first1,last1-(last2-first2)) such that @c predicate(*(i+N), @p
- * (first2+N)) is true for each @c N in the range @p [0,last2-first2), or
- * @p last1 if no such iterator exists.
+ * @p [first1,last1-(last2-first2)) such that @c *(i+N) == @p *(first2+N)
+ * for each @c N in the range @p [0,last2-first2), or @p last1 if no
+ * such iterator exists.
*
* Searches the range @p [first1,last1) for a sub-sequence that compares
- * equal value-by-value with the sequence given by @p [first2,last2) using
- * comp as a predicate and returns an iterator to the first element of the
- * sub-sequence, or @p last1 if the sub-sequence is not found. The
- * sub-sequence will be the last such subsequence contained in
- * [first,last1).
+ * equal value-by-value with the sequence given by @p [first2,last2) and
+ * returns an iterator to the first element of the sub-sequence, or
+ * @p last1 if the sub-sequence is not found. The sub-sequence will be the
+ * last such subsequence contained in [first,last1).
*
* Because the sub-sequence must lie completely within the range
* @p [first1,last1) it must start at a position less than
@@ -5138,26 +4142,17 @@
* This means that the returned iterator @c i will be in the range
* @p [first1,last1-(last2-first2))
*/
- template<typename _ForwardIterator1, typename _ForwardIterator2,
- typename _BinaryPredicate>
+ template<typename _ForwardIterator1, typename _ForwardIterator2>
inline _ForwardIterator1
find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
- _ForwardIterator2 __first2, _ForwardIterator2 __last2,
- _BinaryPredicate __comp)
+ _ForwardIterator2 __first2, _ForwardIterator2 __last2)
{
// concept requirements
- __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator1>)
- __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator2>)
- __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate,
+ __glibcxx_function_requires(_EqualOpConcept<
typename iterator_traits<_ForwardIterator1>::value_type,
typename iterator_traits<_ForwardIterator2>::value_type>)
- __glibcxx_requires_valid_range(__first1, __last1);
- __glibcxx_requires_valid_range(__first2, __last2);
-
- return std::__find_end(__first1, __last1, __first2, __last2,
- std::__iterator_category(__first1),
- std::__iterator_category(__first2),
- __comp);
+ return std::find_end(__first1, __last1, __first2, __last2,
+ __gnu_cxx::__ops::equal_to());
}
} // namespace std