Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-11-02 15:33:57


Oleg Fedtchenko wrote:
>> Peter Dimov wrote:
>>
>> No.
>>
>
>>> in reply to Oleg Fedtchenko's:
>>>
>>> Is it possible to implement the next example using global
>>> functions as specified above?
>>>
>>> class D
>>> {
>>> private:
>>> WORD m_wData;
>>> public:
>>> D(){ m_wData = 0;}
>>>
>>> virtual shared_ptr<WORD> GetData( shared_ptr<D> this_ )
>
> Is it worth using the proposed *member_ptr* smart pointer
> (e.g. for the tasks discussed in the previous messages or
> like those described at http://boostoleg.narod.ru/examples.htm) ?

I'm not sure. In a situation like the above I'd probably go with
enable_shared_from_this. member_ptr also seems to require a base class, so
it's a tie, except that the returned pointer is a shared_ptr: more
"standard" and supports weak pointers.

http://boost.org/libs/smart_ptr/enable_shared_from_this.html
http://boost.org/libs/smart_ptr/sp_techniques.html#from_this

If D is intrusively counted, I can also return a shared_ptr that does
intrusive_ptr_release on it, similar to:

http://boost.org/libs/smart_ptr/sp_techniques.html#intrusive

but storing a different pointer in the deleter, like:

shared_ptr<WORD> pw( &this->m_wData, bind( intrusive_deleter<D>(), this ) );

It seems that your member_ptr can be emulated with

shared_ptr<WORD> pw( &this->m_wData,
  bind( &member_ptr_owner_base::release, this )
);

but I may be wrong; I looked at it only briefly.


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