forked from boostorg/smart_ptr
shared_ptr now autodetects counted_bases; minor test updates; intrusive_ptr no longer calls addref/release for NULL pointers.
[SVN r13602]
This commit is contained in:
@@ -169,12 +169,12 @@ private:
|
||||
|
||||
inline void intrusive_ptr_add_ref(counted_base * p)
|
||||
{
|
||||
if(p != 0) p->add_ref();
|
||||
p->add_ref();
|
||||
}
|
||||
|
||||
inline void intrusive_ptr_release(counted_base * p)
|
||||
{
|
||||
if(p != 0) p->release();
|
||||
p->release();
|
||||
}
|
||||
|
||||
namespace detail
|
||||
@@ -215,6 +215,8 @@ private:
|
||||
|
||||
friend class weak_count;
|
||||
|
||||
template<class P, class D> shared_count(P, D, counted_base const *);
|
||||
|
||||
public:
|
||||
|
||||
shared_count(): pi_(new counted_base(1, 1))
|
||||
@@ -226,7 +228,7 @@ public:
|
||||
pi_->add_ref();
|
||||
}
|
||||
|
||||
template<class P, class D> shared_count(P p, D d): pi_(0)
|
||||
template<class P, class D> shared_count(P p, D d, void const * = 0): pi_(0)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -239,6 +241,11 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
template<class P, class D> shared_count(P, D, counted_base * pi): pi_(pi)
|
||||
{
|
||||
pi_->add_ref();
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_AUTO_PTR
|
||||
|
||||
// auto_ptr<Y> is special cased to provide the strong guarantee
|
||||
|
||||
@@ -33,7 +33,8 @@ namespace boost
|
||||
//
|
||||
// void intrusive_ptr_add_ref(T * p);
|
||||
// void intrusive_ptr_release(T * p);
|
||||
// (note: p may be 0!)
|
||||
//
|
||||
// (p != 0)
|
||||
//
|
||||
// The object is responsible for destroying itself.
|
||||
//
|
||||
@@ -52,26 +53,26 @@ public:
|
||||
|
||||
intrusive_ptr(T * p): p_(p)
|
||||
{
|
||||
intrusive_ptr_add_ref(p_);
|
||||
if(p_ != 0) intrusive_ptr_add_ref(p_);
|
||||
}
|
||||
|
||||
~intrusive_ptr()
|
||||
{
|
||||
intrusive_ptr_release(p_);
|
||||
if(p_ != 0) intrusive_ptr_release(p_);
|
||||
}
|
||||
|
||||
#ifdef BOOST_MSVC6_MEMBER_TEMPLATES
|
||||
|
||||
template<class U> intrusive_ptr(intrusive_ptr<U> const & rhs): p_(rhs.get())
|
||||
{
|
||||
intrusive_ptr_add_ref(p_);
|
||||
if(p_ != 0) intrusive_ptr_add_ref(p_);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
intrusive_ptr(intrusive_ptr const & rhs): p_(rhs.p_)
|
||||
{
|
||||
intrusive_ptr_add_ref(p_);
|
||||
if(p_ != 0) intrusive_ptr_add_ref(p_);
|
||||
}
|
||||
|
||||
#ifdef BOOST_MSVC6_MEMBER_TEMPLATES
|
||||
|
||||
@@ -87,7 +87,7 @@ public:
|
||||
}
|
||||
|
||||
template<typename Y>
|
||||
explicit shared_ptr(Y * p): px(p), pn(p, checked_deleter<Y>()) // Y must be complete
|
||||
explicit shared_ptr(Y * p): px(p), pn(p, checked_deleter<Y>(), p) // Y must be complete
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user