From 7e9664396a8c86aa04e5cc550b5801b95ea6c930 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 17 Jul 2011 20:35:44 +0000 Subject: [PATCH] Add copy constructor/assignment - in C++0x, move disables implicit copy. [SVN r73202] --- include/boost/smart_ptr/shared_array.hpp | 20 +++++++++++++++++++- include/boost/smart_ptr/shared_ptr.hpp | 12 +++++++++++- include/boost/smart_ptr/weak_ptr.hpp | 18 +++++++++++++++++- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/include/boost/smart_ptr/shared_array.hpp b/include/boost/smart_ptr/shared_array.hpp index 1f50403..0acdff7 100644 --- a/include/boost/smart_ptr/shared_array.hpp +++ b/include/boost/smart_ptr/shared_array.hpp @@ -69,7 +69,25 @@ public: { } -// generated copy constructor, assignment, destructor are fine +// generated copy constructor, destructor are fine... + +#if defined( BOOST_HAS_RVALUE_REFS ) + +// ... except in C++0x, move disables the implicit copy + + shared_array( shared_array const & r ): px( r.px ), pn( r.pn ) // never throws + { + } + +#endif + + // assignment + + shared_array & operator=( shared_array const & r ) // never throws + { + this_type( r ).swap( *this ); + return *this; + } void reset(T * p = 0) { diff --git a/include/boost/smart_ptr/shared_ptr.hpp b/include/boost/smart_ptr/shared_ptr.hpp index 16a1f92..d3973da 100644 --- a/include/boost/smart_ptr/shared_ptr.hpp +++ b/include/boost/smart_ptr/shared_ptr.hpp @@ -197,7 +197,17 @@ public: boost::detail::sp_enable_shared_from_this( this, p, p ); } -// generated copy constructor, destructor are fine +// generated copy constructor, destructor are fine... + +#if defined( BOOST_HAS_RVALUE_REFS ) + +// ... except in C++0x, move disables the implicit copy + + shared_ptr( shared_ptr const & r ): px( r.px ), pn( r.pn ) // never throws + { + } + +#endif template explicit shared_ptr(weak_ptr const & r): pn(r.pn) // may throw diff --git a/include/boost/smart_ptr/weak_ptr.hpp b/include/boost/smart_ptr/weak_ptr.hpp index db56103..e00d96e 100644 --- a/include/boost/smart_ptr/weak_ptr.hpp +++ b/include/boost/smart_ptr/weak_ptr.hpp @@ -40,8 +40,24 @@ public: { } -// generated copy constructor, assignment, destructor are fine +// generated copy constructor, assignment, destructor are fine... +#if defined( BOOST_HAS_RVALUE_REFS ) + +// ... except in C++0x, move disables the implicit copy + + weak_ptr( weak_ptr const & r ): px( r.px ), pn( r.pn ) // never throws + { + } + + weak_ptr & operator=( weak_ptr const & r ) // never throws + { + px = r.px; + pn = r.pn; + return *this; + } + +#endif // // The "obvious" converting constructor implementation: