Boost logo

Boost-Commit :

From: daniel_james_at_[hidden]
Date: 2008-07-13 15:26:57


Author: danieljames
Date: 2008-07-13 15:26:56 EDT (Sun, 13 Jul 2008)
New Revision: 47399
URL: http://svn.boost.org/trac/boost/changeset/47399

Log:
Support for auto_ptr.

Text files modified:
   sandbox/move/boost/move.hpp | 68 +++++++++++++++++++--------------------
   sandbox/move/libs/move/test/main.cpp | 13 +++++++
   2 files changed, 46 insertions(+), 35 deletions(-)

Modified: sandbox/move/boost/move.hpp
==============================================================================
--- sandbox/move/boost/move.hpp (original)
+++ sandbox/move/boost/move.hpp 2008-07-13 15:26:56 EDT (Sun, 13 Jul 2008)
@@ -33,6 +33,15 @@
 
 /*************************************************************************************************/
 
+// Illegal forward declare.
+
+namespace std
+{
+ template <class T> class auto_ptr;
+}
+
+/*************************************************************************************************/
+
 namespace boost {
 
 /*************************************************************************************************/
@@ -166,10 +175,6 @@
 
 /*************************************************************************************************/
 
-#if !defined(BOOST_NO_SFINAE)
-
-/*************************************************************************************************/
-
 struct copy_tag {};
 struct swap_tag {};
 struct boost_move_tag {};
@@ -181,9 +186,10 @@
         typename boost::mpl::if_<boost::detail::has_swap_overload<T>,
             swap_tag, copy_tag>::type > {};
 
-/*************************************************************************************************/
-
-#endif
+template <class T>
+struct move_type<std::auto_ptr<T> > {
+ typedef custom_move_tag type;
+};
 
 /*************************************************************************************************/
 
@@ -319,6 +325,17 @@
 
 /*!
 \ingroup move_related
+\brief This version of move is for auto_ptrs.
+*/
+template <class T>
+std::auto_ptr<T>& move(std::auto_ptr<T>& x) {
+ return x;
+}
+
+/*************************************************************************************************/
+
+/*!
+\ingroup move_related
 \brief Iterator pair version of move. Similar to std::copy but with move semantics,
 for movable types, otherwise with copy semantics.
 */
@@ -413,6 +430,13 @@
 
 /*************************************************************************************************/
 
+template <class T>
+inline void move_construct(std::auto_ptr<T>* p, std::auto_ptr<T>& x) {
+ ::new(static_cast<void*>(p)) std::auto_ptr<T>(x);
+}
+
+/*************************************************************************************************/
+
 #if !defined(BOOST_NO_SFINAE)
 
 /*************************************************************************************************/
@@ -504,40 +528,14 @@
     return std::uninitialized_copy(f, l, r);
 }
 
-#endif
+#endif // BOOST_NO_SFINAE
 
 /*************************************************************************************************/
+
 } // namespace boost
 
 /*************************************************************************************************/
 
-// auto_ptr support
-
-// Illegal forward declare.
-
-namespace std
-{
- template <class T> class auto_ptr;
-}
-
-namespace boost
-{
- template <class T>
- struct move_type<std::auto_ptr<T>, void> {
- typedef custom_move_tag type;
- };
-
- template <class T>
- std::auto_ptr<T>& move(std::auto_ptr<T>& x) {
- return x;
- }
-
- template <class T>
- inline void move_construct(std::auto_ptr<T>* p, std::auto_ptr<T>& x) {
- ::new(static_cast<void*>(p)) std::auto_ptr<T>(x);
- }
-}
-
 #endif
 
 /*************************************************************************************************/

Modified: sandbox/move/libs/move/test/main.cpp
==============================================================================
--- sandbox/move/libs/move/test/main.cpp (original)
+++ sandbox/move/libs/move/test/main.cpp 2008-07-13 15:26:56 EDT (Sun, 13 Jul 2008)
@@ -17,6 +17,8 @@
 #include <boost/move.hpp>
 #include "./vector.hpp"
 
+#include <memory>
+
 /*************************************************************************************************/
 
 #define BOOST_CHECK_EQUAL(x, y) BOOST_CHECK(x == y)
@@ -45,6 +47,7 @@
     typedef test_vector<vector_t> vector_vector_t;
     typedef std::vector<int> std_vector_t;
     typedef test_vector<std_vector_t> vector_std_vector_t;
+ typedef test_vector<std::auto_ptr<int> > vector_auto_ptr_t;
     
     // Test is_movable<> template function
 
@@ -118,6 +121,16 @@
         boost::uninitialized_move(&y[0], &y[3], &x[0]);
         BOOST_CHECK_EQUAL(addr, x[0].begin());
     }
+
+ { // Move auto_ptr
+ vector_auto_ptr_t x;
+ for(int i = 0; i < 100; ++i)
+ x.push_back(std::auto_ptr<int>(new int(i)));
+ BOOST_CHECK_EQUAL(100, x.size());
+ BOOST_CHECK_EQUAL(0, *x[0]);
+ BOOST_CHECK_EQUAL(10, *x[10]);
+ BOOST_CHECK_EQUAL(99, *x[99]);
+ }
 }
 
 int test_main(int, char**) {


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk