forked from boostorg/smart_ptr
Fix get_pointer for the array case, add operator= for unique_ptr, update auto_ptr signatures to use rvalue reference when available.
[SVN r81730]
This commit is contained in:
@ -418,17 +418,30 @@ public:
|
|||||||
#ifndef BOOST_NO_AUTO_PTR
|
#ifndef BOOST_NO_AUTO_PTR
|
||||||
|
|
||||||
template<class Y>
|
template<class Y>
|
||||||
explicit shared_ptr(std::auto_ptr<Y> & r): px(r.get()), pn()
|
explicit shared_ptr( std::auto_ptr<Y> & r ): px(r.get()), pn()
|
||||||
{
|
{
|
||||||
boost::detail::sp_assert_convertible< Y, T >();
|
boost::detail::sp_assert_convertible< Y, T >();
|
||||||
|
|
||||||
Y * tmp = r.get();
|
Y * tmp = r.get();
|
||||||
pn = boost::detail::shared_count(r);
|
pn = boost::detail::shared_count( r );
|
||||||
|
|
||||||
boost::detail::sp_deleter_construct( this, tmp );
|
boost::detail::sp_deleter_construct( this, tmp );
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
|
#if defined( BOOST_HAS_RVALUE_REFS )
|
||||||
|
|
||||||
|
template<class Y>
|
||||||
|
shared_ptr( std::auto_ptr<Y> && r ): px(r.get()), pn()
|
||||||
|
{
|
||||||
|
boost::detail::sp_assert_convertible< Y, T >();
|
||||||
|
|
||||||
|
Y * tmp = r.get();
|
||||||
|
pn = boost::detail::shared_count( r );
|
||||||
|
|
||||||
|
boost::detail::sp_deleter_construct( this, tmp );
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
|
||||||
|
|
||||||
template<class Ap>
|
template<class Ap>
|
||||||
explicit shared_ptr( Ap r, typename boost::detail::sp_enable_if_auto_ptr<Ap, int>::type = 0 ): px( r.get() ), pn()
|
explicit shared_ptr( Ap r, typename boost::detail::sp_enable_if_auto_ptr<Ap, int>::type = 0 ): px( r.get() ), pn()
|
||||||
@ -486,11 +499,20 @@ public:
|
|||||||
template<class Y>
|
template<class Y>
|
||||||
shared_ptr & operator=( std::auto_ptr<Y> & r )
|
shared_ptr & operator=( std::auto_ptr<Y> & r )
|
||||||
{
|
{
|
||||||
this_type(r).swap(*this);
|
this_type( r ).swap( *this );
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
|
#if defined( BOOST_HAS_RVALUE_REFS )
|
||||||
|
|
||||||
|
template<class Y>
|
||||||
|
shared_ptr & operator=( std::auto_ptr<Y> && r )
|
||||||
|
{
|
||||||
|
this_type( static_cast< std::auto_ptr<Y> && >( r ) ).swap( *this );
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif !defined( BOOST_NO_SFINAE ) && !defined( BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
|
||||||
|
|
||||||
template<class Ap>
|
template<class Ap>
|
||||||
typename boost::detail::sp_enable_if_auto_ptr< Ap, shared_ptr & >::type operator=( Ap r )
|
typename boost::detail::sp_enable_if_auto_ptr< Ap, shared_ptr & >::type operator=( Ap r )
|
||||||
@ -503,6 +525,17 @@ public:
|
|||||||
|
|
||||||
#endif // BOOST_NO_AUTO_PTR
|
#endif // BOOST_NO_AUTO_PTR
|
||||||
|
|
||||||
|
#if !defined( BOOST_NO_CXX11_SMART_PTR )
|
||||||
|
|
||||||
|
template<class Y, class D>
|
||||||
|
shared_ptr & operator=( std::unique_ptr<Y, D> && r )
|
||||||
|
{
|
||||||
|
this_type( static_cast< std::unique_ptr<Y, D> && >( r ) ).swap(*this);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
// Move support
|
// Move support
|
||||||
|
|
||||||
#if defined( BOOST_HAS_RVALUE_REFS )
|
#if defined( BOOST_HAS_RVALUE_REFS )
|
||||||
@ -730,7 +763,7 @@ template<class T, class U> shared_ptr<T> reinterpret_pointer_cast( shared_ptr<U>
|
|||||||
|
|
||||||
// get_pointer() enables boost::mem_fn to recognize shared_ptr
|
// get_pointer() enables boost::mem_fn to recognize shared_ptr
|
||||||
|
|
||||||
template<class T> inline T * get_pointer(shared_ptr<T> const & p) BOOST_NOEXCEPT
|
template<class T> inline typename shared_ptr<T>::element_type * get_pointer(shared_ptr<T> const & p) BOOST_NOEXCEPT
|
||||||
{
|
{
|
||||||
return p.get();
|
return p.get();
|
||||||
}
|
}
|
||||||
|
@ -91,6 +91,12 @@ int main()
|
|||||||
p2.reset();
|
p2.reset();
|
||||||
p3.reset();
|
p3.reset();
|
||||||
BOOST_TEST( X::instances == 0 );
|
BOOST_TEST( X::instances == 0 );
|
||||||
|
|
||||||
|
p2 = std::unique_ptr<X>( new X );
|
||||||
|
BOOST_TEST( X::instances == 1 );
|
||||||
|
|
||||||
|
p2.reset();
|
||||||
|
BOOST_TEST( X::instances == 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -105,6 +111,12 @@ int main()
|
|||||||
|
|
||||||
p2.reset();
|
p2.reset();
|
||||||
BOOST_TEST( Y::instances == 0 );
|
BOOST_TEST( Y::instances == 0 );
|
||||||
|
|
||||||
|
p2 = std::unique_ptr<Y, YD>( new Y, YD() );
|
||||||
|
BOOST_TEST( Y::instances == 1 );
|
||||||
|
|
||||||
|
p2.reset();
|
||||||
|
BOOST_TEST( Y::instances == 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -121,6 +133,12 @@ int main()
|
|||||||
|
|
||||||
p2.reset();
|
p2.reset();
|
||||||
BOOST_TEST( Y::instances == 0 );
|
BOOST_TEST( Y::instances == 0 );
|
||||||
|
|
||||||
|
p2 = std::unique_ptr<Y, YD&>( new Y, yd );
|
||||||
|
BOOST_TEST( Y::instances == 1 );
|
||||||
|
|
||||||
|
p2.reset();
|
||||||
|
BOOST_TEST( Y::instances == 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -137,6 +155,12 @@ int main()
|
|||||||
|
|
||||||
p2.reset();
|
p2.reset();
|
||||||
BOOST_TEST( Y::instances == 0 );
|
BOOST_TEST( Y::instances == 0 );
|
||||||
|
|
||||||
|
p2 = std::unique_ptr<Y, YD const&>( new Y, yd );
|
||||||
|
BOOST_TEST( Y::instances == 1 );
|
||||||
|
|
||||||
|
p2.reset();
|
||||||
|
BOOST_TEST( Y::instances == 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
return boost::report_errors();
|
return boost::report_errors();
|
||||||
|
Reference in New Issue
Block a user