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 constructor / assignment to pair


Hi,

tested x86_64-linux. Committed to mainline.

Paolo.

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

	* include/std/utility (identity, move, forward): Move to...
	* include/bits/stl_move.h: ... here.
	* include/Makefile.am: Add.
	* include/bits/stl_algobase.h: Include the latter.
	* include/Makefile.in: Regenerate.
	* testsuite/20_util/pair/moveable.cc: Remove dg-require-rvalref.

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

	* include/bits/stl_pair.h (pair<>:pair(pair&&),
	pair<>::operator=(pair&&)): Add.
Index: include/Makefile.in
===================================================================
--- include/Makefile.in	(revision 129122)
+++ include/Makefile.in	(working copy)
@@ -369,6 +369,7 @@
 	${bits_srcdir}/stl_list.h \
 	${bits_srcdir}/stl_map.h \
 	${bits_srcdir}/stl_auto_ptr.h \
+	${bits_srcdir}/stl_move.h \
 	${bits_srcdir}/stl_multimap.h \
 	${bits_srcdir}/stl_multiset.h \
 	${bits_srcdir}/stl_numeric.h \
Index: include/std/utility
===================================================================
--- include/std/utility	(revision 129122)
+++ include/std/utility	(working copy)
@@ -84,30 +84,7 @@
 #    undef _GLIBCXX_BEGIN_NAMESPACE_TR1
 #    undef _GLIBCXX_INCLUDE_AS_CXX0X
 #  endif
-
-#include <type_traits>
-
-_GLIBCXX_BEGIN_NAMESPACE(std)
-
-  // 20.2.2, forward/move
-  template<typename _Tp>
-    struct identity
-    {
-      typedef _Tp type;
-    };
-
-  template<typename _Tp>
-    inline _Tp&&
-    forward(typename std::identity<_Tp>::type&& __t)
-    { return __t; }
-
-  template<typename _Tp>
-    inline typename std::remove_reference<_Tp>::type&&
-    move(_Tp&& __t)
-    { return __t; }
-
-_GLIBCXX_END_NAMESPACE
-
+#  include <bits/stl_move.h>
 #endif
 
 #endif /* _GLIBCXX_UTILITY */
Index: include/bits/stl_algobase.h
===================================================================
--- include/bits/stl_algobase.h	(revision 129122)
+++ include/bits/stl_algobase.h	(working copy)
@@ -75,7 +75,7 @@
 #include <debug/debug.h>
 
 #ifdef __GXX_EXPERIMENTAL_CXX0X__
-# include <utility>
+# include <bits/stl_move.h>
 # define _GLIBCXX_MOVE(_Tp) std::move(_Tp)
 #else
 # define _GLIBCXX_MOVE(_Tp) _Tp
Index: include/bits/stl_pair.h
===================================================================
--- include/bits/stl_pair.h	(revision 129122)
+++ include/bits/stl_pair.h	(working copy)
@@ -62,6 +62,10 @@
 #ifndef _STL_PAIR_H
 #define _STL_PAIR_H 1
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#include <bits/stl_move.h>
+#endif
+
 _GLIBCXX_BEGIN_NAMESPACE(std)
 
   /// pair holds two objects of arbitrary type.
@@ -89,6 +93,20 @@
       template<class _U1, class _U2>
         pair(const pair<_U1, _U2>& __p)
 	: first(__p.first), second(__p.second) { }
+
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+      pair(pair&& __p)
+      : first(std::move(__p.first)),
+	second(std::move(__p.second)) { }
+
+      pair&
+      operator=(pair&& __p)
+      { 
+	first = std::move(__p.first);
+	second = std::move(__p.second);
+	return *this;
+      }
+#endif
     };
 
   /// Two pairs of the same type are equal iff their members are equal.
Index: include/Makefile.am
===================================================================
--- include/Makefile.am	(revision 129122)
+++ include/Makefile.am	(working copy)
@@ -120,6 +120,7 @@
 	${bits_srcdir}/stl_list.h \
 	${bits_srcdir}/stl_map.h \
 	${bits_srcdir}/stl_auto_ptr.h \
+	${bits_srcdir}/stl_move.h \
 	${bits_srcdir}/stl_multimap.h \
 	${bits_srcdir}/stl_multiset.h \
 	${bits_srcdir}/stl_numeric.h \
Index: testsuite/20_util/pair/moveable.cc
===================================================================
--- testsuite/20_util/pair/moveable.cc	(revision 129122)
+++ testsuite/20_util/pair/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]