
Hi, These might've been ask and answered already - can 't find it though. 1. Why doesn't intrusive_ptr have reset( T* )? 2. Why there is no something like this provided by the header: template<typename Derived> class intrusive_base { protected: intrusive_base() : m_counter( 0 ) {} private: friend void intrusive_ptr_add_ref( Derived* p ) { ++p->m_counter; } friend void intrusive_ptr_release( Derived* p ) { --p->m_counter; if( !p->m_counter ) delete p; } unsigned m_counter; }; to be used like this: class Foo : intrusive_base<Foo> { ... }; This should streamline intrusive_ptr class usage, isn't it? Or there is an alternative way already? Gennadiy

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Friday 27 June 2008 19:00 pm, Gennadiy Rozental wrote:
2. Why there is no something like this provided by the header:
template<typename Derived> class intrusive_base { protected: intrusive_base() : m_counter( 0 ) {}
private: friend void intrusive_ptr_add_ref( Derived* p ) { ++p->m_counter; } friend void intrusive_ptr_release( Derived* p ) { --p->m_counter; if( !p->m_counter ) delete p; }
unsigned m_counter; };
to be used like this:
class Foo : intrusive_base<Foo> { ... };
One minor quibble: I think you left out a "public": class Foo: public intrusive_base<Foo> otherwise, I get compile errors unless I declare the add_ref/release functions as friends to Foo also. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFIaOa15vihyNWuA4URAvi9AKCZq/XrWxSV9pfC5GovTvwAPPtJBQCfTwef vFFCEB61f0Sl6TLXjh8K1Os= =AQdl -----END PGP SIGNATURE-----
participants (2)
-
Frank Mori Hess
-
Gennadiy Rozental