diff --git a/include/boost/intrusive_ptr.hpp b/include/boost/intrusive_ptr.hpp index cd1ac11..c4ec407 100644 --- a/include/boost/intrusive_ptr.hpp +++ b/include/boost/intrusive_ptr.hpp @@ -105,6 +105,11 @@ public: return *this; } + void reset( T * rhs ) + { + this_type( rhs ).swap( *this ); + } + T * get() const { return p_; @@ -112,11 +117,13 @@ public: T & operator*() const { + BOOST_ASSERT( p_ != 0 ); return *p_; } T * operator->() const { + BOOST_ASSERT( p_ != 0 ); return p_; } diff --git a/include/boost/shared_array.hpp b/include/boost/shared_array.hpp index eb69c8e..3b82f35 100644 --- a/include/boost/shared_array.hpp +++ b/include/boost/shared_array.hpp @@ -103,7 +103,23 @@ public: return px != 0; } -#elif defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003)) +#elif defined( _MANAGED ) + + static void unspecified_bool( this_type*** ) + { + } + + typedef void (*unspecified_bool_type)( this_type*** ); + + operator unspecified_bool_type() const // never throws + { + return px == 0? 0: unspecified_bool; + } + +#elif \ + ( defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, < 0x3200) ) || \ + ( defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ < 304) ) + typedef T * (this_type::*unspecified_bool_type)() const; operator unspecified_bool_type() const // never throws diff --git a/include/boost/shared_ptr.hpp b/include/boost/shared_ptr.hpp index 9edc86f..5e1abd8 100644 --- a/include/boost/shared_ptr.hpp +++ b/include/boost/shared_ptr.hpp @@ -5,7 +5,7 @@ // shared_ptr.hpp // // (C) Copyright Greg Colvin and Beman Dawes 1998, 1999. -// Copyright (c) 2001-2006 Peter Dimov +// Copyright (c) 2001-2007 Peter Dimov // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at @@ -88,6 +88,21 @@ template void sp_enable_shared_from_this( shared_count const & if(pe != 0) pe->_internal_weak_this._internal_assign(const_cast(px), pn); } +#ifdef _MANAGED + +// Avoid C4793, ... causes native code generation + +struct sp_any_pointer +{ + template sp_any_pointer( T* ) {} +}; + +inline void sp_enable_shared_from_this( shared_count const & /*pn*/, sp_any_pointer, sp_any_pointer ) +{ +} + +#else // _MANAGED + #ifdef sgi // Turn off: the last argument of the varargs function "sp_enable_shared_from_this" is unnamed # pragma set woff 3506 @@ -101,6 +116,8 @@ inline void sp_enable_shared_from_this( shared_count const & /*pn*/, ... ) # pragma reset woff 3506 #endif +#endif // _MANAGED + #if !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION ) && !defined( BOOST_NO_AUTO_PTR ) // rvalue auto_ptr support based on a technique by Dave Abrahams @@ -195,6 +212,12 @@ public: { } + // aliasing + template< class Y > + shared_ptr( shared_ptr const & r, T * p ): px( p ), pn( r.pn ) // never throws + { + } + template shared_ptr(shared_ptr const & r, boost::detail::static_cast_tag): px(static_cast(r.px)), pn(r.pn) { @@ -236,7 +259,7 @@ public: #if !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION ) template - explicit shared_ptr( Ap r, typename boost::detail::sp_enable_if_auto_ptr::type = 0 ): px( r.get() ), pn() + shared_ptr( Ap r, typename boost::detail::sp_enable_if_auto_ptr::type = 0 ): px( r.get() ), pn() { typename Ap::element_type * tmp = r.get(); pn = boost::detail::shared_count( r ); @@ -283,6 +306,38 @@ public: #endif // BOOST_NO_AUTO_PTR +// Move support + +#if defined( BOOST_HAS_RVALUE_REFS ) + + shared_ptr( shared_ptr && r ): px( r.px ), pn() // never throws + { + pn.swap( r.pn ); + r.px = 0; + } + + template + shared_ptr( shared_ptr && r ): px( r.px ), pn() // never throws + { + pn.swap( r.pn ); + r.px = 0; + } + + shared_ptr & operator=( shared_ptr && r ) // never throws + { + this_type( static_cast< shared_ptr && >( r ) ).swap( *this ); + return *this; + } + + template + shared_ptr & operator=( shared_ptr && r ) // never throws + { + this_type( static_cast< shared_ptr && >( r ) ).swap( *this ); + return *this; + } + +#endif + void reset() // never throws in 1.30+ { this_type().swap(*this); @@ -304,6 +359,11 @@ public: this_type( p, d, a ).swap( *this ); } + template void reset( shared_ptr const & r, T * p ) + { + this_type( r, p ).swap( *this ); + } + reference operator* () const // never throws { BOOST_ASSERT(px != 0); @@ -323,7 +383,7 @@ public: // implicit conversion to "bool" -#if defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x580) +#if ( defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, < 0x570) ) || defined(__CINT__) operator bool () const { @@ -345,7 +405,8 @@ public: #elif \ ( defined(__MWERKS__) && BOOST_WORKAROUND(__MWERKS__, < 0x3200) ) || \ - ( defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ < 304) ) + ( defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ < 304) ) || \ + ( defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x590) ) typedef T * (this_type::*unspecified_bool_type)() const; @@ -393,9 +454,9 @@ public: return pn < rhs.pn; } - void * _internal_get_deleter(std::type_info const & ti) const + void * _internal_get_deleter( detail::sp_typeinfo const & ti ) const { - return pn.get_deleter(ti); + return pn.get_deleter( ti ); } // Tasteless as this may seem, making all members public allows member templates @@ -523,7 +584,7 @@ template std::basic_ostream & operator<< (std:: #endif // __GNUC__ < 3 -// get_deleter (experimental) +// get_deleter #if ( defined(__GNUC__) && BOOST_WORKAROUND(__GNUC__, < 3) ) || \ ( defined(__EDG_VERSION__) && BOOST_WORKAROUND(__EDG_VERSION__, <= 238) ) || \ @@ -534,7 +595,7 @@ template std::basic_ostream & operator<< (std:: template D * get_deleter(shared_ptr const & p) { - void const * q = p._internal_get_deleter(typeid(D)); + void const * q = p._internal_get_deleter(BOOST_SP_TYPEID(D)); return const_cast(static_cast(q)); } @@ -542,7 +603,7 @@ template D * get_deleter(shared_ptr const & p) template D * get_deleter(shared_ptr const & p) { - return static_cast(p._internal_get_deleter(typeid(D))); + return static_cast(p._internal_get_deleter(BOOST_SP_TYPEID(D))); } #endif diff --git a/include/boost/weak_ptr.hpp b/include/boost/weak_ptr.hpp index 8f4230f..ae606f2 100644 --- a/include/boost/weak_ptr.hpp +++ b/include/boost/weak_ptr.hpp @@ -179,12 +179,6 @@ template void swap(weak_ptr & a, weak_ptr & b) a.swap(b); } -// deprecated, provided for backward compatibility -template shared_ptr make_shared(weak_ptr const & r) -{ - return r.lock(); -} - } // namespace boost #ifdef BOOST_MSVC