This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Correct concept checks on count and search_n
- From: Christopher Jefferson <caj at cs dot york dot ac dot uk>
- To: libstdc++ <libstdc++ at gcc dot gnu dot org>, gcc-patches at gcc dot gnu dot org
- Date: Wed, 20 Apr 2005 22:57:39 +0100
- Subject: Correct concept checks on count and search_n
The concept checks on count and search_n were both too strong (I looked
for similar problems to the one reported on count by Jonathan, and found
the same problem on search_n). This implements the correct, slightly
weaker, concept check on both functions, and adds a test for search_n
(count already had one).
2005-04-20 Christopher Jefferson <chris@bubblescope.net>
* include/bits/stl_algo.h (count) : Correct concept checks.
(search_n) : Likewise.
* testsuite/25_algorithms/search_n/check_type.cc : New.
diff -urN -x *CVS* libstdc++-v3.so_7.clean/include/bits/stl_algo.h libstdc++-v3/include/bits/stl_algo.h
--- libstdc++-v3.so_7.clean/include/bits/stl_algo.h Fri Mar 25 21:25:09 2005
+++ libstdc++-v3/include/bits/stl_algo.h Wed Apr 20 22:40:14 2005
@@ -395,9 +395,8 @@
{
// concept requirements
__glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
- __glibcxx_function_requires(_EqualityComparableConcept<
- typename iterator_traits<_InputIterator>::value_type >)
- __glibcxx_function_requires(_EqualityComparableConcept<_Tp>)
+ __glibcxx_function_requires(_EqualOpConcept<
+ typename iterator_traits<_InputIterator>::value_type, _Tp>)
__glibcxx_requires_valid_range(__first, __last);
typename iterator_traits<_InputIterator>::difference_type __n = 0;
for ( ; __first != __last; ++__first)
@@ -638,9 +637,8 @@
_Integer __count, const _Tp& __val)
{
// concept requirements
- __glibcxx_function_requires(_EqualityComparableConcept<
- typename iterator_traits<_ForwardIterator>::value_type>)
- __glibcxx_function_requires(_EqualityComparableConcept<_Tp>)
+ __glibcxx_function_requires(_EqualOpConcept<
+ typename iterator_traits<_ForwardIterator>::value_type, _Tp>)
return std::search_n(__first, __last, __count, __val,
__gnu_cxx::__ops::equal_to());
}
diff -urN -x *CVS* libstdc++-v3.so_7.clean/testsuite/25_algorithms/search_n/check_type.cc libstdc++-v3/testsuite/25_algorithms/search_n/check_type.cc
--- libstdc++-v3.so_7.clean/testsuite/25_algorithms/search_n/check_type.cc Thu Jan 1 01:00:00 1970
+++ libstdc++-v3/testsuite/25_algorithms/search_n/check_type.cc Wed Apr 20 22:12:56 2005
@@ -0,0 +1,39 @@
+// 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 search_n
+
+// { dg-do compile }
+
+#include <algorithm>
+#include <testsuite_iterators.h>
+
+using __gnu_test::forward_iterator_wrapper;
+
+struct X { };
+
+struct Y { };
+
+bool
+operator==(const X&, const Y&)
+{ return true; }
+
+forward_iterator_wrapper<X>
+test1(forward_iterator_wrapper<X>& begin,
+ forward_iterator_wrapper<X>& end, int i, Y& value)
+{ return std::search_n(begin, end, i , value); }