This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Merging predicated and non-predicated algorithms


Benjamin Kosnik wrote:

I think this looks pretty good!

004-12-31 Christopher Jefferson <chris@bubblescope.net>

* include/bits/predefined_ops: New.


predefined_ops.h


The below is what I have eventually committed. Also noticed yet another
wrong concept check (in lexicographical_compare), which I shall fix also
in mainline.

Paolo.

////////////////
2005-01-10  Paolo Carlini  <pcarlini@suse.de>

	* include/bits/stl_algobase.h (lexicographical_compare):
	Fix concept check.

2005-01-10  Christopher Jefferson <chris@bubblescope.net>

	* include/bits/predefined_ops.h: New.
	* include/Makefile.am: Add.
	* include/Makefile.in: Regenerate.
	* include/bits/stl_algobase.h (mismatch, equal,
	lexicographical_compare): Make non-predicate version call predicated
	version.
	* testsuite/25_algorithms/lexicographical_compare/check_type.cc: New.
	* testsuite/25_algorithms/lexicographical_compare/1.cc: Likewise.
	* testsuite/25_algorithms/mismatch/check_type.cc: Likewise.
	* testsuite/25_algorithms/mismatch/1.cc: Likewise.
	* testsuite/25_algorithms/equal/check_type.cc: New.
	* testsuite/25_algorithms/equal/1.cc: New.
diff -urN libstdc++-v3-orig/include/Makefile.am libstdc++-v3/include/Makefile.am
--- libstdc++-v3-orig/include/Makefile.am	2005-01-09 19:27:10.000000000 +0100
+++ libstdc++-v3/include/Makefile.am	2005-01-10 10:30:28.000000000 +0100
@@ -1,6 +1,6 @@
 ## Makefile for the include subdirectory of the GNU C++ Standard library.
 ##
-## 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 libstdc++ version 3 distribution.
 ## Process this file with automake to produce Makefile.in.
@@ -119,6 +119,7 @@
 	${bits_srcdir}/mask_array.h \
 	${bits_srcdir}/ostream.tcc \
 	${bits_srcdir}/postypes.h \
+	${bits_srcdir}/predefined_ops.h \
 	${bits_srcdir}/stream_iterator.h \
 	${bits_srcdir}/streambuf_iterator.h \
 	${bits_srcdir}/slice_array.h \
diff -urN libstdc++-v3-orig/include/bits/predefined_ops.h libstdc++-v3/include/bits/predefined_ops.h
--- libstdc++-v3-orig/include/bits/predefined_ops.h	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/include/bits/predefined_ops.h	2005-01-10 10:27:32.000000000 +0100
@@ -0,0 +1,60 @@
+// Default predicates for internal use -*- C++ -*-
+
+// 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.
+
+// 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.
+
+/** @file predefined_ops.h
+ *  This is an internal header file, included by other library headers.
+ *  You should not attempt to use it directly.
+ */
+
+#ifndef _GLIBCXX_PREDEFINED_OPS_H
+#define _GLIBCXX_PREDEFINED_OPS_H	1
+
+namespace __gnu_cxx
+{
+namespace __ops
+{
+  struct less
+  {
+    template<typename _Lhs, typename _Rhs>
+      bool
+      operator()(const _Lhs& __lhs, const _Rhs& __rhs)
+      { return __lhs < __rhs; }
+  };
+
+  struct equal_to
+  {
+    template<typename _Lhs, typename _Rhs>
+      bool
+      operator()(const _Lhs& __lhs, const _Rhs& __rhs)
+      { return __lhs == __rhs; }
+  };
+} // namespace __ops
+} // namespace __gnu_cxx
+
+#endif
diff -urN libstdc++-v3-orig/include/bits/stl_algobase.h libstdc++-v3/include/bits/stl_algobase.h
--- libstdc++-v3-orig/include/bits/stl_algobase.h	2005-01-09 19:27:14.000000000 +0100
+++ libstdc++-v3/include/bits/stl_algobase.h	2005-01-10 10:52:42.000000000 +0100
@@ -72,6 +72,7 @@
 #include <bits/stl_iterator_base_types.h>
 #include <bits/stl_iterator_base_funcs.h>
 #include <bits/stl_iterator.h>
+#include <bits/predefined_ops.h>
 #include <bits/concept_check.h>
 #include <debug/debug.h>
 
@@ -664,39 +665,6 @@
    *  @param  first1  An input iterator.
    *  @param  last1   An input iterator.
    *  @param  first2  An input iterator.
-   *  @return   A pair of iterators pointing to the first mismatch.
-   *
-   *  This compares the elements of two ranges using @c == and returns a pair
-   *  of iterators.  The first iterator points into the first range, the
-   *  second iterator points into the second range, and the elements pointed
-   *  to by the iterators are not equal.
-  */
-  template<typename _InputIterator1, typename _InputIterator2>
-    pair<_InputIterator1, _InputIterator2>
-    mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
-	     _InputIterator2 __first2)
-    {
-      // concept requirements
-      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
-      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
-      __glibcxx_function_requires(_EqualOpConcept<
-	    typename iterator_traits<_InputIterator1>::value_type,
-	    typename iterator_traits<_InputIterator2>::value_type>)
-      __glibcxx_requires_valid_range(__first1, __last1);
-
-      while (__first1 != __last1 && *__first1 == *__first2)
-        {
-	  ++__first1;
-	  ++__first2;
-        }
-      return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
-    }
-
-  /**
-   *  @brief Finds the places in ranges which don't match.
-   *  @param  first1  An input iterator.
-   *  @param  last1   An input iterator.
-   *  @param  first2  An input iterator.
    *  @param  binary_pred  A binary predicate @link s20_3_1_base functor@endlink.
    *  @return   A pair of iterators pointing to the first mismatch.
    *
@@ -726,33 +694,28 @@
     }
 
   /**
-   *  @brief Tests a range for element-wise equality.
+   *  @brief Finds the places in ranges which don't match.
    *  @param  first1  An input iterator.
    *  @param  last1   An input iterator.
    *  @param  first2  An input iterator.
-   *  @return   A boolean true or false.
+   *  @return   A pair of iterators pointing to the first mismatch.
    *
-   *  This compares the elements of two ranges using @c == and returns true or
-   *  false depending on whether all of the corresponding elements of the
-   *  ranges are equal.
+   *  This compares the elements of two ranges using @c == and returns a pair
+   *  of iterators.  The first iterator points into the first range, the
+   *  second iterator points into the second range, and the elements pointed
+   *  to by the iterators are not equal.
   */
   template<typename _InputIterator1, typename _InputIterator2>
-    inline bool
-    equal(_InputIterator1 __first1, _InputIterator1 __last1,
-	  _InputIterator2 __first2)
+    pair<_InputIterator1, _InputIterator2>
+    mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
+	     _InputIterator2 __first2)
     {
       // concept requirements
-      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
-      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
       __glibcxx_function_requires(_EqualOpConcept<
 	    typename iterator_traits<_InputIterator1>::value_type,
 	    typename iterator_traits<_InputIterator2>::value_type>)
-      __glibcxx_requires_valid_range(__first1, __last1);
-      
-      for (; __first1 != __last1; ++__first1, ++__first2)
-	if (!(*__first1 == *__first2))
-	  return false;
-      return true;
+      return std::mismatch(__first1, __last1, __first2, 
+			   __gnu_cxx::__ops::equal_to());
     }
 
   /**
@@ -787,43 +750,27 @@
     }
 
   /**
-   *  @brief Performs "dictionary" comparison on ranges.
+   *  @brief Tests a range for element-wise equality.
    *  @param  first1  An input iterator.
    *  @param  last1   An input iterator.
    *  @param  first2  An input iterator.
-   *  @param  last2   An input iterator.
    *  @return   A boolean true or false.
    *
-   *  "Returns true if the sequence of elements defined by the range
-   *  [first1,last1) is lexicographically less than the sequence of elements
-   *  defined by the range [first2,last2).  Returns false otherwise."
-   *  (Quoted from [25.3.8]/1.)  If the iterators are all character pointers,
-   *  then this is an inline call to @c memcmp.
+   *  This compares the elements of two ranges using @c == and returns true or
+   *  false depending on whether all of the corresponding elements of the
+   *  ranges are equal.
   */
   template<typename _InputIterator1, typename _InputIterator2>
-    bool
-    lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1,
-			    _InputIterator2 __first2, _InputIterator2 __last2)
+    inline bool
+    equal(_InputIterator1 __first1, _InputIterator1 __last1,
+	  _InputIterator2 __first2)
     {
       // concept requirements
-      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
-      __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
-      __glibcxx_function_requires(_LessThanComparableConcept<
-	    typename iterator_traits<_InputIterator1>::value_type>)
-      __glibcxx_function_requires(_LessThanComparableConcept<
+      __glibcxx_function_requires(_EqualOpConcept<
+	    typename iterator_traits<_InputIterator1>::value_type,
 	    typename iterator_traits<_InputIterator2>::value_type>)
-      __glibcxx_requires_valid_range(__first1, __last1);
-      __glibcxx_requires_valid_range(__first2, __last2);
-
-      for (; __first1 != __last1 && __first2 != __last2;
-	   ++__first1, ++__first2)
-	{
-	  if (*__first1 < *__first2)
-	    return true;
-	  if (*__first2 < *__first1)
-	    return false;
-	}
-      return __first1 == __last1 && __first2 != __last2;
+      return std::equal(__first1, __last1, __first2, 
+			__gnu_cxx::__ops::equal_to());
     }
 
   /**
@@ -862,6 +809,37 @@
       return __first1 == __last1 && __first2 != __last2;
     }
 
+  /**
+   *  @brief Performs "dictionary" comparison on ranges.
+   *  @param  first1  An input iterator.
+   *  @param  last1   An input iterator.
+   *  @param  first2  An input iterator.
+   *  @param  last2   An input iterator.
+   *  @return   A boolean true or false.
+   *
+   *  "Returns true if the sequence of elements defined by the range
+   *  [first1,last1) is lexicographically less than the sequence of elements
+   *  defined by the range [first2,last2).  Returns false otherwise."
+   *  (Quoted from [25.3.8]/1.)  If the iterators are all character pointers,
+   *  then this is an inline call to @c memcmp.
+  */
+  template<typename _InputIterator1, typename _InputIterator2>
+    bool
+    lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1,
+			    _InputIterator2 __first2, _InputIterator2 __last2)
+    {
+      // concept requirements
+      __glibcxx_function_requires(_LessThanOpConcept<
+	    typename iterator_traits<_InputIterator1>::value_type,
+	    typename iterator_traits<_InputIterator2>::value_type>)
+      __glibcxx_function_requires(_LessThanOpConcept<
+	    typename iterator_traits<_InputIterator2>::value_type,
+	    typename iterator_traits<_InputIterator1>::value_type>)
+      return std::lexicographical_compare(__first1, __last1, __first2, 
+					  __last2, __gnu_cxx::__ops::less());
+    }
+
+
   inline bool
   lexicographical_compare(const unsigned char* __first1,
 			  const unsigned char* __last1,
diff -urN libstdc++-v3-orig/testsuite/25_algorithms/equal/1.cc libstdc++-v3/testsuite/25_algorithms/equal/1.cc
--- libstdc++-v3-orig/testsuite/25_algorithms/equal/1.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/25_algorithms/equal/1.cc	2005-01-10 11:01:32.000000000 +0100
@@ -0,0 +1,73 @@
+// 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.
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
+
+using __gnu_test::test_container;
+using __gnu_test::input_iterator_wrapper;
+
+typedef test_container<int, input_iterator_wrapper> Container;
+int array1[] = {0, 1};
+int array2[] = {1, 0};
+int array3[] = {1, 0};
+
+void test1()
+{
+  Container con1(array1, array1);
+  Container con2(array2, array2);
+  VERIFY( std::equal(con1.begin(), con1.end(), con2.begin()) );
+}
+
+void test2()
+{
+  Container con1(array1, array1 + 2);
+  Container con2(array2, array2 + 2);
+  VERIFY( !std::equal(con2.begin(), con2.end(), con1.begin()) );
+}
+
+void test3()
+{
+  Container con1(array1, array1 + 2);
+  Container con2(array2, array2 + 2);
+  VERIFY( !std::equal(con2.begin(), con2.end(), con1.begin()) );
+}
+
+void test4()
+{
+  Container con1(array1, array1 + 2);
+  Container con2(array2, array2 + 2);
+  VERIFY( !std::equal(con1.begin(), con1.end(), con2.begin()) );
+}
+
+void test5()
+{
+  Container con3(array3, array3 + 2);
+  Container con2(array2, array2 + 2);
+  VERIFY( std::equal(con3.begin(), con3.end(), con2.begin()) );
+}
+
+int main()
+{
+  test1();
+  test2();
+  test3();
+  test4();
+  test5();
+}
diff -urN libstdc++-v3-orig/testsuite/25_algorithms/equal/check_type.cc libstdc++-v3/testsuite/25_algorithms/equal/check_type.cc
--- libstdc++-v3-orig/testsuite/25_algorithms/equal/check_type.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/25_algorithms/equal/check_type.cc	2005-01-10 11:01:01.000000000 +0100
@@ -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.
+
+// { dg-do compile }
+
+#include <algorithm>
+
+struct Lhs1 { };
+
+struct Rhs1 { };
+
+bool operator==(const Lhs1&, const Rhs1&) {return true;}
+
+struct Lhs2 { };
+
+struct Rhs2 { };
+
+bool predicate(const Lhs2&, const Rhs2&) {return true;}
+
+void test1()
+{
+  Lhs1 lhs1[1];
+  Rhs1 rhs1[1];
+  std::equal(lhs1, lhs1 + 1, rhs1);
+
+  Lhs2 lhs2[1];
+  Rhs2 rhs2[1];
+  std::equal(lhs2, lhs2 + 1, rhs2, predicate);
+}
diff -urN libstdc++-v3-orig/testsuite/25_algorithms/lexicographical_compare/1.cc libstdc++-v3/testsuite/25_algorithms/lexicographical_compare/1.cc
--- libstdc++-v3-orig/testsuite/25_algorithms/lexicographical_compare/1.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/25_algorithms/lexicographical_compare/1.cc	2005-01-10 11:02:51.000000000 +0100
@@ -0,0 +1,78 @@
+// 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.
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
+
+using __gnu_test::test_container;
+using __gnu_test::input_iterator_wrapper;
+
+typedef test_container<int, input_iterator_wrapper> Container;
+int array1[] = {0, 1};
+int array2[] = {1, 0};
+int array3[] = {1, 0, 1};
+
+void test1()
+{
+  Container con1(array1, array1);
+  Container con2(array2, array2);
+  VERIFY( !std::lexicographical_compare(con1.begin(), con1.end(), 
+					con2.begin(), con2.end()) );
+}
+
+void test2()
+{
+  Container con1(array1, array1 + 2);
+  Container con2(array2, array2 + 2);
+  VERIFY( std::lexicographical_compare(con1.begin(), con1.end(), 
+				       con2.begin(), con2.end()) );
+}
+
+void test3()
+{
+  Container con1(array1, array1 + 2);
+  Container con2(array2, array2 + 2);
+  VERIFY( !std::lexicographical_compare(con2.begin(), con2.end(), 
+				        con1.begin(), con1.end()) );
+}
+
+void test4()
+{
+  Container con3(array3, array3 + 3);
+  Container con2(array2, array2 + 2);
+  VERIFY( std::lexicographical_compare(con2.begin(), con2.end(), 
+				       con3.begin(), con3.end()) );
+}
+
+void test5()
+{
+  Container con3(array3, array3 + 3);
+  Container con2(array2, array2 + 2);
+  VERIFY( !std::lexicographical_compare(con3.begin(), con3.end(),
+					con2.begin(), con2.end()) );
+}
+
+int main()
+{
+  test1();
+  test2();
+  test3();
+  test4();
+  test5();
+}
diff -urN libstdc++-v3-orig/testsuite/25_algorithms/lexicographical_compare/check_type.cc libstdc++-v3/testsuite/25_algorithms/lexicographical_compare/check_type.cc
--- libstdc++-v3-orig/testsuite/25_algorithms/lexicographical_compare/check_type.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/25_algorithms/lexicographical_compare/check_type.cc	2005-01-10 11:02:03.000000000 +0100
@@ -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.
+
+// { dg-do compile }
+
+#include <algorithm>
+
+struct Lhs1 { };
+
+struct Rhs1 { };
+
+bool operator<(const Lhs1&, const Rhs1&) {return true;}
+
+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);
+
+  X x1[1];
+  X x2[1];
+
+  std::lexicographical_compare(x1, x1 + 1, x2, x2 + 1, predicate);
+}
diff -urN libstdc++-v3-orig/testsuite/25_algorithms/mismatch/1.cc libstdc++-v3/testsuite/25_algorithms/mismatch/1.cc
--- libstdc++-v3-orig/testsuite/25_algorithms/mismatch/1.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/25_algorithms/mismatch/1.cc	2005-01-10 10:58:22.000000000 +0100
@@ -0,0 +1,87 @@
+// 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.
+
+#include <algorithm>
+#include <testsuite_hooks.h>
+#include <testsuite_iterators.h>
+
+using __gnu_test::test_container;
+using __gnu_test::input_iterator_wrapper;
+
+typedef test_container<int, input_iterator_wrapper> Container;
+int array1[] = {0, 1};
+int array2[] = {1, 0};
+int array3[] = {1, 0, 1};
+
+void test1a()
+{
+  Container con1(array1, array1);
+  Container con2(array2, array2);
+  VERIFY( std::mismatch(con1.begin(), con1.end(), con2.begin()).first.ptr
+	  == array1 );
+}
+
+void test1b()
+{
+  Container con1(array1, array1);
+  Container con2(array2, array2);
+  VERIFY( std::mismatch(con1.begin(), con1.end(), con2.begin()).second.ptr
+	  == array2 );
+}
+
+void test2a()
+{
+  Container con1(array1, array1 + 2);
+  Container con2(array2, array2 + 2);
+  VERIFY( std::mismatch(con1.begin(), con1.end(), con2.begin()).first.ptr
+	  == array1 );
+}
+
+void test2b()
+{
+  Container con1(array1, array1 + 2);
+  Container con2(array2, array2 + 2);
+  VERIFY( std::mismatch(con1.begin(), con1.end(), con2.begin()).second.ptr
+	  == array2 );
+}
+
+void test3a()
+{
+  Container con3(array3, array3 + 2);
+  Container con2(array2, array2 + 2);
+  VERIFY( std::mismatch(con3.begin(), con3.end(), con2.begin()).first.ptr
+	  == array3 + 2 );
+}
+
+void test3b()
+{
+  Container con3(array3, array3 + 2);
+  Container con2(array2, array2 + 2);
+  VERIFY( std::mismatch(con3.begin(), con3.end(), con2.begin()).second.ptr
+	  == array2 + 2 );
+}
+
+int main()
+{
+  test1a();
+  test1b();
+  test2a();
+  test2b();
+  test3a();
+  test3b();
+}
diff -urN libstdc++-v3-orig/testsuite/25_algorithms/mismatch/check_type.cc libstdc++-v3/testsuite/25_algorithms/mismatch/check_type.cc
--- libstdc++-v3-orig/testsuite/25_algorithms/mismatch/check_type.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/25_algorithms/mismatch/check_type.cc	2005-01-10 10:58:51.000000000 +0100
@@ -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.
+
+// { dg-do compile }
+
+#include <algorithm>
+
+struct Lhs1 { };
+
+struct Rhs1 { };
+
+bool operator==(const Lhs1&, const Rhs1&) {return true;}
+
+struct Lhs2 { };
+
+struct Rhs2 { };
+
+bool predicate(const Lhs2&, const Rhs2&) {return true;}
+
+void test1()
+{
+  Lhs1 lhs1[1];
+  Rhs1 rhs1[1];
+
+  std::mismatch(lhs1, lhs1 + 1, rhs1);
+
+  Lhs2 lhs2[1];
+  Rhs2 rhs2[1];
+
+  std::mismatch(lhs2, lhs2 + 1, rhs2, predicate);
+}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]