mirror of
https://github.com/boostorg/smart_ptr.git
synced 2025-11-21 17:59:53 +01:00
Added weak_from_raw(), for use in conjunction with
enable_shared_from_raw base class. [SVN r57423]
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
namespace boost
|
||||
{
|
||||
template<typename T> boost::shared_ptr<T> shared_from_raw(T *);
|
||||
template<typename T> boost::weak_ptr<T> weak_from_raw(T *);
|
||||
|
||||
namespace detail
|
||||
{
|
||||
@@ -72,6 +73,7 @@ public:
|
||||
private:
|
||||
template<class Y> friend class shared_ptr;
|
||||
template<typename T> friend boost::shared_ptr<T> shared_from_raw(T *);
|
||||
template<typename T> friend boost::weak_ptr<T> weak_from_raw(T *);
|
||||
template< class X, class Y > friend inline void detail::sp_enable_shared_from_this( boost::shared_ptr<X> * ppx, Y const * py, boost::enable_shared_from_raw const * pe );
|
||||
#endif
|
||||
|
||||
@@ -114,9 +116,19 @@ private:
|
||||
template<typename T>
|
||||
boost::shared_ptr<T> shared_from_raw(T *p)
|
||||
{
|
||||
BOOST_ASSERT(p != 0);
|
||||
return boost::shared_ptr<T>(p->enable_shared_from_raw::shared_from_this(), p);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
boost::weak_ptr<T> weak_from_raw(T *p)
|
||||
{
|
||||
BOOST_ASSERT(p != 0);
|
||||
boost::weak_ptr<T> result;
|
||||
result._internal_aliasing_assign(p->enable_shared_from_raw::weak_this_, p);
|
||||
return result;
|
||||
}
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template< class X, class Y > inline void sp_enable_shared_from_this( boost::shared_ptr<X> * ppx, Y const * py, boost::enable_shared_from_raw const * pe )
|
||||
|
||||
@@ -183,10 +183,11 @@ public:
|
||||
pn.swap(other.pn);
|
||||
}
|
||||
|
||||
void _internal_assign(T * px2, boost::detail::shared_count const & pn2)
|
||||
template<typename Y>
|
||||
void _internal_aliasing_assign(weak_ptr<Y> const & r, T * px2)
|
||||
{
|
||||
px = px2;
|
||||
pn = pn2;
|
||||
pn = r.pn;
|
||||
}
|
||||
|
||||
template<class Y> bool _internal_less(weak_ptr<Y> const & rhs) const
|
||||
@@ -225,6 +226,6 @@ template<class T> void swap(weak_ptr<T> & a, weak_ptr<T> & b)
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif // #ifndef BOOST_SMART_PTR_WEAK_PTR_HPP_INCLUDED
|
||||
|
||||
Reference in New Issue
Block a user