This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

[v3] Add / use _GLIBCXX_MOVE in algorithm


Hi,

tested x86_64-linux, committed to mainline.

Paolo.

/////////////////
2007-10-07  Paolo Carlini  <pcarlini@suse.de>

	* include/bits/stl_algobase.h (_GLIBCXX_MOVE): Add.
	(swap, __iter_swap): Use it.
	* testsuite/25_algorithms/rotate/moveable.cc: Remove dg-require-rvalref.
	* testsuite/25_algorithms/remove/moveable.cc: Likewise.
	* testsuite/25_algorithms/partition/moveable.cc: Likewise. 
	* testsuite/25_algorithms/swap_ranges/moveable.cc: Likewise.
	* testsuite/25_algorithms/reverse/moveable.cc: Likewise. 
	* testsuite/25_algorithms/unique/moveable.cc: Likewise. 
	* testsuite/25_algorithms/remove_if/moveable.cc: Likewise. 

	* include/bits/stl_algobase.h (lexicographical_compare):
	Clean up.

2007-10-07  Chris Jefferson  <chris@bubblescope.net>
	    Paolo Carlini  <pcarlini@suse.de>

	* include/bits/stl_algo.h (remove, remove_if, unique,
	__rotate(_RandomAccessIterator, _RandomAccessIterator,
	_RandomAccessIterator, random_access_iterator_tag)): Use _GLIBCXX_MOVE.
	(__rotate(_ForwardIterator, _ForwardIterator, _ForwardIterator,
	forward_iterator_tag), __rotate(_BidirectionalIterator,
	_BidirectionalIterator, _BidirectionalIterator,
	bidirectional_iterator_tag), __partition(_ForwardIterator,
	_ForwardIterator, _Predicate, forward_iterator_tag)): Use iter_swap.
Index: include/bits/stl_algobase.h
===================================================================
--- include/bits/stl_algobase.h	(revision 129057)
+++ include/bits/stl_algobase.h	(working copy)
@@ -74,6 +74,13 @@
 #include <bits/concept_check.h>
 #include <debug/debug.h>
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+# include <utility>
+# define _GLIBCXX_MOVE(_Tp) std::move(_Tp)
+#else
+# define _GLIBCXX_MOVE(_Tp) _Tp
+#endif
+
 _GLIBCXX_BEGIN_NAMESPACE(std)
 
   /**
@@ -92,9 +99,9 @@
       // concept requirements
       __glibcxx_function_requires(_SGIAssignableConcept<_Tp>)
 
-      _Tp __tmp = __a;
-      __a = __b;
-      __b = __tmp;
+      _Tp __tmp = _GLIBCXX_MOVE(__a);
+      __a = _GLIBCXX_MOVE(__b);
+      __b = _GLIBCXX_MOVE(__tmp);
     }
 
   // See http://gcc.gnu.org/ml/libstdc++/2004-08/msg00167.html: in a
@@ -109,9 +116,9 @@
         {
           typedef typename iterator_traits<_ForwardIterator1>::value_type
             _ValueType1;
-          _ValueType1 __tmp = *__a;
-          *__a = *__b;
-          *__b = __tmp; 
+          _ValueType1 __tmp = _GLIBCXX_MOVE(*__a);
+          *__a = _GLIBCXX_MOVE(*__b);
+          *__b = _GLIBCXX_MOVE(__tmp);
 	}
     };
 
@@ -879,6 +886,7 @@
     {
       typedef typename iterator_traits<_II1>::iterator_category _Category1;
       typedef typename iterator_traits<_II2>::iterator_category _Category2;
+      typedef __lc_rai<_Category1, _Category2> 	__rai_type;
 
       // concept requirements
       typedef typename iterator_traits<_II1>::value_type _ValueType1;
@@ -890,12 +898,8 @@
       __glibcxx_requires_valid_range(__first1, __last1);
       __glibcxx_requires_valid_range(__first2, __last2);
 
-      __last1 = __lc_rai<_Category1, _Category2>::__newlast1(__first1,
-							     __last1,
-							     __first2,
-							     __last2);
-      for (; __first1 != __last1
-	     && __lc_rai<_Category1, _Category2>::__cnd2(__first2, __last2);
+      __last1 = __rai_type::__newlast1(__first1, __last1, __first2, __last2);
+      for (; __first1 != __last1 && __rai_type::__cnd2(__first2, __last2);
 	   ++__first1, ++__first2)
 	{
 	  if (*__first1 < *__first2)
Index: include/bits/stl_algo.h
===================================================================
--- include/bits/stl_algo.h	(revision 129057)
+++ include/bits/stl_algo.h	(working copy)
@@ -788,9 +788,17 @@
       __glibcxx_requires_valid_range(__first, __last);
 
       __first = _GLIBCXX_STD_P::find(__first, __last, __value);
-      _ForwardIterator __i = __first;
-      return __first == __last ? __first
-		        : std::remove_copy(++__i, __last, __first, __value);
+      if(__first == __last)
+        return __first;
+      _ForwardIterator __result = __first;
+      ++__first;
+      for(; __first != __last; ++__first)
+        if(!(*__first == __value))
+          {
+            *__result = _GLIBCXX_MOVE(*__first);
+            ++__result;
+          }
+      return __result;
     }
 
   /**
@@ -822,10 +830,17 @@
       __glibcxx_requires_valid_range(__first, __last);
 
       __first = _GLIBCXX_STD_P::find_if(__first, __last, __pred);
-      _ForwardIterator __i = __first;
-      return __first == __last ? __first
-			       : std::remove_copy_if(++__i, __last,
-						     __first, __pred);
+      if(__first == __last)
+        return __first;
+      _ForwardIterator __result = __first;
+      ++__first;
+      for(; __first != __last; ++__first)
+        if(!__pred(*__first))
+          {
+            *__result = _GLIBCXX_MOVE(*__first);
+            ++__result;
+          }
+      return __result;
     }
 
   /**
@@ -862,7 +877,7 @@
       ++__first;
       while (++__first != __last)
 	if (!(*__dest == *__first))
-	  *++__dest = *__first;
+	  *++__dest = _GLIBCXX_MOVE(*__first);
       return ++__dest;
     }
 
@@ -903,7 +918,7 @@
       ++__first;
       while (++__first != __last)
 	if (!bool(__binary_pred(*__dest, *__first)))
-	  *++__dest = *__first;
+	  *++__dest = _GLIBCXX_MOVE(*__first);
       return ++__dest;
     }
 
@@ -1207,7 +1222,7 @@
       _ForwardIterator __first2 = __middle;
       do
 	{
-	  swap(*__first, *__first2);
+	  std::iter_swap(__first, __first2);
 	  ++__first;
 	  ++__first2;
 	  if (__first == __middle)
@@ -1219,7 +1234,7 @@
 
       while (__first2 != __last)
 	{
-	  swap(*__first, *__first2);
+	  std::iter_swap(__first, __first2);
 	  ++__first;
 	  ++__first2;
 	  if (__first == __middle)
@@ -1253,7 +1268,7 @@
 
       while (__first != __middle && __middle != __last)
 	{
-	  swap(*__first, *--__last);
+	  std::iter_swap(__first, --__last);
 	  ++__first;
 	}
 
@@ -1301,7 +1316,7 @@
 
       for (_Distance __i = 0; __i < __d; __i++)
 	{
-	  _ValueType __tmp = *__first;
+	  _ValueType __tmp = _GLIBCXX_MOVE(*__first);
 	  _RandomAccessIterator __p = __first;
 
 	  if (__k < __l)
@@ -1310,11 +1325,11 @@
 		{
 		  if (__p > __first + __l)
 		    {
-		      *__p = *(__p - __l);
+		      *__p = _GLIBCXX_MOVE(*(__p - __l));
 		      __p -= __l;
 		    }
 
-		  *__p = *(__p + __k);
+		  *__p = _GLIBCXX_MOVE(*(__p + __k));
 		  __p += __k;
 		}
 	    }
@@ -1324,15 +1339,15 @@
 		{
 		  if (__p < __last - __k)
 		    {
-		      *__p = *(__p + __k);
+		      *__p = _GLIBCXX_MOVE(*(__p + __k));
 		      __p += __k;
 		    }
-		  *__p = * (__p - __l);
+		  *__p = _GLIBCXX_MOVE(*(__p - __l));
 		  __p -= __l;
 		}
 	    }
 
-	  *__p = __tmp;
+	  *__p = _GLIBCXX_MOVE(__tmp);
 	  ++__first;
 	}
     }
@@ -1412,8 +1427,7 @@
   template<typename _ForwardIterator, typename _Predicate>
     _ForwardIterator
     __partition(_ForwardIterator __first, _ForwardIterator __last,
-		_Predicate __pred,
-		forward_iterator_tag)
+		_Predicate __pred, forward_iterator_tag)
     {
       if (__first == __last)
 	return __first;
@@ -1427,7 +1441,7 @@
       while (++__next != __last)
 	if (__pred(*__next))
 	  {
-	    swap(*__first, *__next);
+	    std::iter_swap(__first, __next);
 	    ++__first;
 	  }
 
@@ -1442,8 +1456,7 @@
   template<typename _BidirectionalIterator, typename _Predicate>
     _BidirectionalIterator
     __partition(_BidirectionalIterator __first, _BidirectionalIterator __last,
-		_Predicate __pred,
-		bidirectional_iterator_tag)
+		_Predicate __pred, bidirectional_iterator_tag)
     {
       while (true)
 	{
Index: testsuite/25_algorithms/rotate/moveable.cc
===================================================================
--- testsuite/25_algorithms/rotate/moveable.cc	(revision 129057)
+++ testsuite/25_algorithms/rotate/moveable.cc	(working copy)
@@ -1,4 +1,3 @@
-// { dg-require-rvalref "" }
 // { dg-options "-std=gnu++0x" }
 
 // Copyright (C) 2005, 2007 Free Software Foundation, Inc.
Index: testsuite/25_algorithms/remove/moveable.cc
===================================================================
--- testsuite/25_algorithms/remove/moveable.cc	(revision 129057)
+++ testsuite/25_algorithms/remove/moveable.cc	(working copy)
@@ -1,4 +1,3 @@
-// { dg-require-rvalref "" }
 // { dg-options "-std=gnu++0x" }
 
 // Copyright (C) 2005, 2007 Free Software Foundation, Inc.
Index: testsuite/25_algorithms/partition/moveable.cc
===================================================================
--- testsuite/25_algorithms/partition/moveable.cc	(revision 129057)
+++ testsuite/25_algorithms/partition/moveable.cc	(working copy)
@@ -1,4 +1,3 @@
-// { dg-require-rvalref "" }
 // { dg-options "-std=gnu++0x" }
 
 // Copyright (C) 2005, 2007 Free Software Foundation, Inc.
Index: testsuite/25_algorithms/swap_ranges/moveable.cc
===================================================================
--- testsuite/25_algorithms/swap_ranges/moveable.cc	(revision 129057)
+++ testsuite/25_algorithms/swap_ranges/moveable.cc	(working copy)
@@ -1,5 +1,4 @@
 // { dg-do compile }
-// { dg-require-rvalref "" }
 // { dg-options "-std=gnu++0x" }
 
 // Copyright (C) 2005, 2007 Free Software Foundation, Inc.
Index: testsuite/25_algorithms/reverse/moveable.cc
===================================================================
--- testsuite/25_algorithms/reverse/moveable.cc	(revision 129057)
+++ testsuite/25_algorithms/reverse/moveable.cc	(working copy)
@@ -1,5 +1,4 @@
 // { dg-do compile }
-// { dg-require-rvalref "" }
 // { dg-options "-std=gnu++0x" }
 
 // Copyright (C) 2005, 2007 Free Software Foundation, Inc.
Index: testsuite/25_algorithms/unique/moveable.cc
===================================================================
--- testsuite/25_algorithms/unique/moveable.cc	(revision 129057)
+++ testsuite/25_algorithms/unique/moveable.cc	(working copy)
@@ -1,4 +1,3 @@
-// { dg-require-rvalref "" }
 // { dg-options "-std=gnu++0x" }
 
 // Copyright (C) 2005, 2007 Free Software Foundation, Inc.
Index: testsuite/25_algorithms/remove_if/moveable.cc
===================================================================
--- testsuite/25_algorithms/remove_if/moveable.cc	(revision 129057)
+++ testsuite/25_algorithms/remove_if/moveable.cc	(working copy)
@@ -1,4 +1,3 @@
-// { dg-require-rvalref "" }
 // { dg-options "-std=gnu++0x" }
 
 // Copyright (C) 2005, 2007 Free Software Foundation, Inc.

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