Boost logo

Boost Users :

Subject: Re: [Boost-users] [smart_ptr] weak_ptr pointer semantics
From: Richard Damon (Richard_at_[hidden])
Date: 2011-11-10 19:58:38


On 11/10/11 7:20 PM, Szymon Gatner wrote:
> Hi,
>
> Why weak_ptr does not have (smart) pointer semantics? No * or -> or even get().
>
> I often need a pointer type that is a listener to shared_ptr<> (does not affect
> refcount) but is still usable as a regular pointer type. If providing
> * and -> operators
> is for some reason undesirable then just a get() member would be nice as it
> would allow to implement own wrapper with pointer semantics. get() would return
> raw pointer from shared counter (so is fast) and not shared_ptr<> as
> lock() does.
>
I think the issue is that without converting the weak_ptr to a
shared_ptr, you don't have any way to make sure that the object pointed
to by the weak_ptr hasn't gone away (especially in a multi-threaded
application).

-- 
Richard Damon

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net