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 move_iterator and other C++0x bits


Hi,

tested x86_64-linux, committed to mainline.

Paolo.

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

	* testsuite/23_containers/map/moveable.cc: Remove dg-require-rvalref.
	* testsuite/23_containers/multimap/moveable.cc: Likewise.
	* testsuite/23_containers/set/moveable.cc: Likewise. 
	* testsuite/23_containers/multiset/moveable.cc: Likewise.
	* testsuite/23_containers/deque/moveable.cc: Likewise. 
	* testsuite/23_containers/list/moveable.cc: Likewise. 
	* testsuite/23_containers/vector/moveable.cc: Likewise. 
	* include/std/utility: Use _GLIBCXX_BEGIN_NAMESPACE.

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

	* include/bits/stl_iterator.h (class move_iterator,
	make_move_iterator): Add.
Index: include/std/utility
===================================================================
--- include/std/utility	(revision 129032)
+++ include/std/utility	(working copy)
@@ -87,8 +87,8 @@
 
 #include <type_traits>
 
-namespace std
-{
+_GLIBCXX_BEGIN_NAMESPACE(std)
+
   // 20.2.2, forward/move
   template<typename _Tp>
     struct identity
@@ -105,7 +105,8 @@
     inline typename std::remove_reference<_Tp>::type&&
     move(_Tp&& __t)
     { return __t; }
-}
+
+_GLIBCXX_END_NAMESPACE
 
 #endif
 
Index: include/bits/stl_iterator.h
===================================================================
--- include/bits/stl_iterator.h	(revision 129032)
+++ include/bits/stl_iterator.h	(working copy)
@@ -826,4 +826,173 @@
 
 _GLIBCXX_END_NAMESPACE
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+
+_GLIBCXX_BEGIN_NAMESPACE(std)
+
+  // 24.4.3  Move iterators
+  /**
+   *  @if maint
+   *  Class template move_iterator is an iterator adapter with the same
+   *  behavior as the underlying iterator except that its dereference
+   *  operator implicitly converts the value returned by the underlying
+   *  iterator's dereference operator to an rvalue reference.  Some
+   *  generic algorithms can be called with move iterators to replace
+   *  copying with moving.
+   *  @endif
+   */
+  template<typename _Iterator>
+    class move_iterator
+    {
+    protected:
+      _Iterator _M_current;
+
+    public:
+      typedef _Iterator                                        iterator_type;
+      typedef typename iterator_traits<_Iterator>::difference_type
+                                                               difference_type;
+      typedef typename iterator_traits<_Iterator>::pointer     pointer;
+      typedef typename iterator_traits<_Iterator>::value_type  value_type;
+      typedef typename iterator_traits<_Iterator>::iterator_category
+                                                               iterator_category;
+      typedef value_type&&                                     reference;
+
+    public:
+      move_iterator()
+      : _M_current() { }
+
+      explicit
+      move_iterator(iterator_type __i)
+      : _M_current(__i) { }
+
+      template<typename _Iter>
+	move_iterator(const move_iterator<_Iter>& __i)
+	: _M_current(__i.base()) { }
+
+      iterator_type
+      base() const
+      { return _M_current; }
+
+      reference
+      operator*() const
+      { return *_M_current; }
+
+      pointer
+      operator->() const
+      { return _M_current; }
+
+      move_iterator&
+      operator++()
+      {
+	++_M_current;
+	return *this;
+      }
+
+      move_iterator
+      operator++(int)
+      {
+	move_iterator __tmp = *this;
+	++_M_current;
+	return __tmp;
+      }
+
+      move_iterator&
+      operator--()
+      {
+	--_M_current;
+	return *this;
+      }
+
+      move_iterator
+      operator--(int)
+      {
+	move_iterator __tmp = *this;
+	--_M_current;
+	return __tmp;
+      }
+
+      move_iterator
+      operator+(difference_type __n) const
+      { return move_iterator(_M_current + __n); }
+
+      move_iterator&
+      operator+=(difference_type __n)
+      {
+	_M_current += __n;
+	return *this;
+      }
+
+      move_iterator
+      operator-(difference_type __n) const
+      { return move_iterator(_M_current - __n); }
+    
+      move_iterator&
+      operator-=(difference_type __n)
+      { 
+	_M_current -= __n;
+	return *this;
+      }
+
+      reference
+      operator[](difference_type __n) const
+      { return _M_current[__n]; }
+    };
+
+  template<typename _IteratorL, typename _IteratorR>
+    inline bool
+    operator==(const move_iterator<_IteratorL>& __x,
+	       const move_iterator<_IteratorR>& __y)
+    { return __x.base() == __y.base(); }
+
+  template<typename _IteratorL, typename _IteratorR>
+    inline bool
+    operator!=(const move_iterator<_IteratorL>& __x,
+	       const move_iterator<_IteratorR>& __y)
+    { return !(__x == __y); }
+
+  template<typename _IteratorL, typename _IteratorR>
+    inline bool
+    operator<(const move_iterator<_IteratorL>& __x,
+	      const move_iterator<_IteratorR>& __y)
+    { return __x.base() < __y.base(); }
+
+  template<typename _IteratorL, typename _IteratorR>
+    inline bool
+    operator<=(const move_iterator<_IteratorL>& __x,
+	       const move_iterator<_IteratorR>& __y)
+    { return !(__y < __x); }
+
+  template<typename _IteratorL, typename _IteratorR>
+    inline bool
+    operator>(const move_iterator<_IteratorL>& __x,
+	      const move_iterator<_IteratorR>& __y)
+    { return __y < __x; }
+
+  template<typename _IteratorL, typename _IteratorR>
+    inline bool
+    operator>=(const move_iterator<_IteratorL>& __x,
+	       const move_iterator<_IteratorR>& __y)
+    { return !(__x < __y); }
+
+  template<typename _IteratorL, typename _IteratorR>
+    inline typename move_iterator<_IteratorL>::difference_type
+    operator-(const move_iterator<_IteratorL>& __x,
+	      const move_iterator<_IteratorR>& __y)
+    { return __x.base() - __y.base(); }
+
+  template<typename _Iterator>
+    inline move_iterator<_Iterator>
+    operator+(typename move_iterator<_Iterator>::difference_type __n,
+	      const move_iterator<_Iterator>& __x)
+    { return __x + __n; }
+
+  template<typename _Iterator>
+    inline move_iterator<_Iterator>
+    make_move_iterator(const _Iterator& __i)
+    { return move_iterator<_Iterator>(__i); }
+
+_GLIBCXX_END_NAMESPACE
+
+#endif // __GXX_EXPERIMENTAL_CXX0X__
+
 #endif
Index: testsuite/23_containers/multimap/moveable.cc
===================================================================
--- testsuite/23_containers/multimap/moveable.cc	(revision 129032)
+++ testsuite/23_containers/multimap/moveable.cc	(working copy)
@@ -1,4 +1,3 @@
-// { dg-require-rvalref "" }
 // { dg-options "-std=gnu++0x" }
 
 // Copyright (C) 2005, 2007 Free Software Foundation, Inc.
@@ -33,6 +32,7 @@
 // this test may begin to fail.
 
 #include <map>
+#include <utility>
 #include <testsuite_hooks.h>
 
 int main()
Index: testsuite/23_containers/set/moveable.cc
===================================================================
--- testsuite/23_containers/set/moveable.cc	(revision 129032)
+++ testsuite/23_containers/set/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/23_containers/vector/moveable.cc
===================================================================
--- testsuite/23_containers/vector/moveable.cc	(revision 129032)
+++ testsuite/23_containers/vector/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/23_containers/deque/moveable.cc
===================================================================
--- testsuite/23_containers/deque/moveable.cc	(revision 129032)
+++ testsuite/23_containers/deque/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/23_containers/multiset/moveable.cc
===================================================================
--- testsuite/23_containers/multiset/moveable.cc	(revision 129032)
+++ testsuite/23_containers/multiset/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/23_containers/list/moveable.cc
===================================================================
--- testsuite/23_containers/list/moveable.cc	(revision 129032)
+++ testsuite/23_containers/list/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/23_containers/map/moveable.cc
===================================================================
--- testsuite/23_containers/map/moveable.cc	(revision 129032)
+++ testsuite/23_containers/map/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]