Boost logo

Boost :

From: Frank Mori Hess (frank.hess_at_[hidden])
Date: 2008-04-10 10:59:05


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Thursday 10 April 2008 09:57 am, Daniel Frey wrote:
> On Thu, 2008-04-10 at 09:27 -0400, Frank Mori Hess wrote:
> > Also, on further thought, I don't think enable_shared_from_this_base
> > needs to be a template class at all.
>
> If you have an easier implementation without further overhead, I'd be
> happy to see it.

This patch against trunk illustrates what I have in mind: shared_ptr_observer
doesn't need to be a template class. I derived enable_shared_from_this from
shared_ptr_observer so I could verify it still passes all the smart_ptr
tests.

- --
Frank
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFH/is95vihyNWuA4URApWKAJ9j/aAg3bR2bi9xttLngQtlsJCydACgq3EY
7RQkDMmoMEDoGlsx4P0PY/c=
=93cK
-----END PGP SIGNATURE-----

--Boundary-00=_9si/HGUZthrbURZ
Content-Type: text/x-diff; charset="iso-8859-1";
        name="shared_ptr_observer.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
        filename="shared_ptr_observer.patch"

Index: boost/enable_shared_from_this.hpp
===================================================================
--- boost/enable_shared_from_this.hpp (revision 44150)
+++ boost/enable_shared_from_this.hpp (working copy)
@@ -21,7 +21,7 @@
 namespace boost
 {
 
-template<class T> class enable_shared_from_this
+template<class T> class enable_shared_from_this: public shared_ptr_observer
 {
 // dynamic cast to template type doesn't work in constructor, so we have
 // to use lazy initialization
Index: boost/shared_ptr.hpp
===================================================================
--- boost/shared_ptr.hpp (revision 44150)
+++ boost/shared_ptr.hpp (working copy)
@@ -52,6 +52,8 @@
 template<class T> class weak_ptr;
 template<class T> class enable_shared_from_this;
 
+class shared_ptr_observer {};
+
 namespace detail
 {
 
@@ -93,11 +95,11 @@
 
 struct ignore_enable_shared_from_this_tag {};
 
-template<class T, class Y> void sp_enable_shared_from_this( boost::shared_ptr<Y> * ptr, boost::enable_shared_from_this<T> const * pe )
+template<class T, class Y> void sp_enable_shared_from_this( boost::shared_ptr<Y> * ptr, T *pt, boost::shared_ptr_observer const *)
 {
- if(pe != 0)
+ if(pt)
     {
- pe->_internal_accept_owner(*ptr);
+ pt->_internal_accept_owner(*ptr);
     }
 }
 
@@ -110,7 +112,7 @@
     template<class T> sp_any_pointer( T* ) {}
 };
 
-inline void sp_enable_shared_from_this( sp_any_pointer, sp_any_pointer )
+inline void sp_enable_shared_from_this( sp_any_pointer, sp_any_pointer, sp_any_pointer )
 {
 }
 
@@ -131,6 +133,11 @@
 
 #endif // _MANAGED
 
+template<class T, class Y> void sp_enable_shared_from_this( boost::shared_ptr<Y> * ptr, T *pt)
+{
+ sp_enable_shared_from_this( ptr, pt, pt );
+}
+
 #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

--Boundary-00=_9si/HGUZthrbURZ--


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk