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]

First patch to simplify <algorithm>


Here is a first attempt at a patch to simplify stl_algo.h (and others) and delegate algorithms which have a default and predicated version to just use the predicated version.

Any comments / suggestions very welcome before I set out to write a quite large set of somewhat similar patches.

Chris
2004-12-05  Christopher Jefferson <chris@bubblescope.net>

	* include/bits/default_preds.h: New.
	* include/bits/stl_algo.h(adjacent_find): Make non-predicate
	adjacent_find call predicated adjacent_find.
Index: stl_algo.h
===================================================================
RCS file: /cvsroot/gcc/gcc/libstdc++-v3/include/bits/stl_algo.h,v
retrieving revision 1.50
diff -u -r1.50 stl_algo.h
--- stl_algo.h	29 Oct 2004 21:44:55 -0000	1.50
+++ stl_algo.h	5 Dec 2004 14:08:21 -0000
@@ -64,6 +64,7 @@
 #include <bits/stl_heap.h>
 #include <bits/stl_tempbuf.h>     // for _Temporary_buffer
 #include <debug/debug.h>
+#include <bits/default_preds.h>
 
 // See concept_check.h for the __glibcxx_*_requires macros.
 
@@ -338,35 +339,6 @@
     }
 
   /**
-   *  @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.
    *  @param  first         A forward iterator.
    *  @param  last          A forward iterator.
@@ -400,6 +372,27 @@
     }
 
   /**
+   *  @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 adjacent_find(__first, __last,
+             __default_eq_pred<typename iterator_traits<_ForwardIterator>::
+			   value_type>());
+    }
+
+
+  /**
    *  @brief Count the number of copies of a value in a sequence.
    *  @param  first  An input iterator.
    *  @param  last   An input iterator.

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