|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r52775 - in sandbox/boost0x: boost/ptr_container boost/ptr_container/detail boost/utility/detail libs/ptr_container/test
From: sebastian.redl_at_[hidden]
Date: 2009-05-05 17:34:31
Author: cornedbee
Date: 2009-05-05 17:34:30 EDT (Tue, 05 May 2009)
New Revision: 52775
URL: http://svn.boost.org/trac/boost/changeset/52775
Log:
Partial move support for ptr_container.
Text files modified:
sandbox/boost0x/boost/ptr_container/detail/reversible_ptr_container.hpp | 51 +++++++++++++++++++++++++++------------
sandbox/boost0x/boost/ptr_container/ptr_sequence_adapter.hpp | 15 ++++++++++-
sandbox/boost0x/boost/utility/detail/result_of_iterate.hpp | 2
sandbox/boost0x/libs/ptr_container/test/Jamfile.v2 | 2
sandbox/boost0x/libs/ptr_container/test/ptr_map.cpp | 9 +++++++
sandbox/boost0x/libs/ptr_container/test/sequence_test_data.hpp | 12 ++++++++
6 files changed, 70 insertions(+), 21 deletions(-)
Modified: sandbox/boost0x/boost/ptr_container/detail/reversible_ptr_container.hpp
==============================================================================
--- sandbox/boost0x/boost/ptr_container/detail/reversible_ptr_container.hpp (original)
+++ sandbox/boost0x/boost/ptr_container/detail/reversible_ptr_container.hpp 2009-05-05 17:34:30 EDT (Tue, 05 May 2009)
@@ -37,6 +37,8 @@
#include <boost/type_traits/is_integral.hpp>
#include <typeinfo>
#include <memory>
+#include <utility>
+#include <stdio.h>
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
#pragma warning(push)
@@ -318,6 +320,10 @@
reversible_ptr_container()
{ }
+ reversible_ptr_container( reversible_ptr_container&& o )
+ : c_( std::move( o.c_ ) )
+ { }
+
template< class SizeType >
reversible_ptr_container( SizeType n, unordered_associative_container_tag )
: c_( n )
@@ -362,13 +368,20 @@
return *this;
}
- reversible_ptr_container& operator=( reversible_ptr_container r ) // strong
+ reversible_ptr_container& operator=( const reversible_ptr_container& o ) // strong
{
+ reversible_ptr_container r(o);
swap( r );
return *this;
}
-
- // overhead: null-initilization of container pointer (very cheap compared to cloning)
+
+ reversible_ptr_container& operator=( reversible_ptr_container&& r ) // nothrow
+ {
+ c_ = std::move( r.c_ );
+ return *this;
+ }
+
+ // overhead: null-initialization of container pointer (very cheap compared to cloning)
// overhead: 1 heap allocation (very cheap compared to cloning)
template< class InputIterator >
reversible_ptr_container( InputIterator first,
@@ -701,17 +714,23 @@
return std::auto_ptr<this_type>( new this_type( this->begin(), this->end() ) ); \
}
-#define BOOST_PTR_CONTAINER_DEFINE_COPY_CONSTRUCTORS( PC, base_type ) \
- \
- template< class U > \
- PC( const PC<U>& r ) : base_type( r ) { } \
- \
- PC& operator=( PC r ) \
- { \
- this->swap( r ); \
- return *this; \
- } \
-
+#define BOOST_PTR_CONTAINER_DEFINE_COPY_CONSTRUCTORS( PC, base_type ) \
+ \
+ template< class U > \
+ PC( const PC<U>& r ) : base_type( r ) { } \
+ \
+ PC& operator=( const PC& o ) \
+ { \
+ PC r(o); \
+ this->swap( r ); \
+ return *this; \
+ } \
+ PC( PC&& r ) : base_type( static_cast<base_type&&>( r ) ) { } \
+ PC& operator=( PC&& r ) { \
+ base_type::operator=( std::move( r ) ); \
+ return *this; \
+ }
+
#define BOOST_PTR_CONTAINER_DEFINE_CONSTRUCTORS( PC, base_type ) \
typedef BOOST_DEDUCED_TYPENAME base_type::iterator iterator; \
@@ -724,8 +743,8 @@
PC( InputIterator first, InputIterator last ) : base_type( first, last ) {} \
template< class InputIterator > \
PC( InputIterator first, InputIterator last, \
- const allocator_type& a ) : base_type( first, last, a ) {}
-
+ const allocator_type& a ) : base_type( first, last, a ) {}
+
#define BOOST_PTR_CONTAINER_DEFINE_NON_INHERITED_MEMBERS( PC, base_type, this_type ) \
BOOST_PTR_CONTAINER_DEFINE_CONSTRUCTORS( PC, base_type ) \
BOOST_PTR_CONTAINER_DEFINE_RELEASE_AND_CLONE( PC, base_type, this_type )
Modified: sandbox/boost0x/boost/ptr_container/ptr_sequence_adapter.hpp
==============================================================================
--- sandbox/boost0x/boost/ptr_container/ptr_sequence_adapter.hpp (original)
+++ sandbox/boost0x/boost/ptr_container/ptr_sequence_adapter.hpp 2009-05-05 17:34:30 EDT (Tue, 05 May 2009)
@@ -161,6 +161,10 @@
: base_type( a )
{ }
+ ptr_sequence_adapter( ptr_sequence_adapter&& o)
+ : base_type( static_cast<base_type&&>(o) )
+ { }
+
template< class SizeType >
ptr_sequence_adapter( SizeType n,
ptr_container_detail::fixed_length_sequence_tag tag )
@@ -224,12 +228,19 @@
: base_type( clone )
{ }
- ptr_sequence_adapter& operator=( const ptr_sequence_adapter r )
+ ptr_sequence_adapter& operator=( const ptr_sequence_adapter& o )
{
+ ptr_sequence_adapter r(o);
this->swap( r );
return *this;
}
-
+
+ ptr_sequence_adapter& operator=( ptr_sequence_adapter&& r )
+ {
+ base_type::operator=( std::move(r) );
+ return *this;
+ }
+
template< class PtrContainer >
ptr_sequence_adapter& operator=( std::auto_ptr<PtrContainer> clone )
{
Modified: sandbox/boost0x/boost/utility/detail/result_of_iterate.hpp
==============================================================================
--- sandbox/boost0x/boost/utility/detail/result_of_iterate.hpp (original)
+++ sandbox/boost0x/boost/utility/detail/result_of_iterate.hpp 2009-05-05 17:34:30 EDT (Tue, 05 May 2009)
@@ -10,7 +10,7 @@
# error Boost result_of - do not include this file!
#endif
-#if defined(BOOST_HAS_DECLTYPE)
+#if defined(BOOST_HAS_DECLTYPE) && 0
// As of N2588, C++0x result_of only supports function call
// expressions of the form f(x). This precludes support for member
Modified: sandbox/boost0x/libs/ptr_container/test/Jamfile.v2
==============================================================================
--- sandbox/boost0x/libs/ptr_container/test/Jamfile.v2 (original)
+++ sandbox/boost0x/libs/ptr_container/test/Jamfile.v2 2009-05-05 17:34:30 EDT (Tue, 05 May 2009)
@@ -39,5 +39,5 @@
[ sc-test ptr_unordered_map ]
[ sc-test ptr_circular_buffer ]
# [ sc-test null_filter_iterator ]
-
+ [ sc-test small ]
;
Modified: sandbox/boost0x/libs/ptr_container/test/ptr_map.cpp
==============================================================================
--- sandbox/boost0x/libs/ptr_container/test/ptr_map.cpp (original)
+++ sandbox/boost0x/libs/ptr_container/test/ptr_map.cpp 2009-05-05 17:34:30 EDT (Tue, 05 May 2009)
@@ -111,6 +111,15 @@
BOOST_MESSAGE( "finished iterator test" );
+ C m1; m1.insert( a_key, new T );
+ C m2( std::move(m1) );
+ BOOST_CHECK_EQUAL( m1.size(), 0u );
+ BOOST_CHECK_EQUAL( m2.size(), 1u );
+ m1 = std::move(m2);
+ BOOST_CHECK_EQUAL( m1.size(), 1u );
+ BOOST_CHECK_EQUAL( m2.size(), 0u );
+ BOOST_MESSAGE( "finished moving test" );
+
BOOST_DEDUCED_TYPENAME C::size_type s = c.size();
BOOST_DEDUCED_TYPENAME C::size_type s2 = c.max_size();
hide_warning(s2);
Modified: sandbox/boost0x/libs/ptr_container/test/sequence_test_data.hpp
==============================================================================
--- sandbox/boost0x/libs/ptr_container/test/sequence_test_data.hpp (original)
+++ sandbox/boost0x/libs/ptr_container/test/sequence_test_data.hpp 2009-05-05 17:34:30 EDT (Tue, 05 May 2009)
@@ -56,7 +56,17 @@
a_copy = a_copy;
BOOST_CHECK( a_copy.empty() );
BOOST_CHECK( !c.empty() );
- BOOST_MESSAGE( "finished copying test" );
+ BOOST_MESSAGE( "finished copying test" );
+
+ C m1;
+ m1.push_back(new T);
+ C m2( std::move(m1) );
+ BOOST_CHECK_EQUAL( m1.size(), 0u );
+ BOOST_CHECK_EQUAL( m2.size(), 1u );
+ m1 = std::move(m2);
+ BOOST_CHECK_EQUAL( m1.size(), 1u );
+ BOOST_CHECK_EQUAL( m2.size(), 0u );
+ BOOST_MESSAGE( "finished moving test" );
BOOST_DEDUCED_TYPENAME C::allocator_type alloc = c.get_allocator();
hide_warning(alloc);
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