Boost logo

Boost :

From: Raoul Gough (RaoulGough_at_[hidden])
Date: 2002-04-10 08:17:10


> From: "Peter Dimov" <pdimov_at_[hidden]>
> Date: Sun, 7 Apr 2002 15:04:18 +0300
[snip]
> ...weak_ptr has been redesigned since the 1.27.0 release; I
> suspect that you won't like some of the changes (lack of operator* and
> operator->, for instance.)

Yes, that would make adapting my code to boost::weak_ptr more difficult.

>
> The problem with a "standard" weak_ptr is that it's too easy to make
costly
> mistakes, even in single-threaded code:
>
> void f(T & t);
>
> f(*wp);
>
> If f(), directly or indirectly, reset()s the owning shared_ptr, it's left
> with a dangling reference. Of course ordinary pointers have the same
problem
> too; but when people use a "smart" pointer they expect to be immune from
> this kind of error, and the probablity that they will make a mistake
> increases. (As Greg Colvin put it, boost smart pointers are "as safe as
> possible but no safer.")

I see the point. Still, it makes simple usage a bit tedious: instead of
writing wp->foo() I would then have to write make_shared (wp)->foo() with
no likely safety benefit in this case. I guess there's no way around this if
you want the extra safety in the general case.

>
> I'm not convinced that even leaving get() in is a good idea. We should
> probably rename it to unsafe_get() since no matter how red, bold, and
large
> we make the warning in the documentation, people will ignore it. And it's
> not possible to change the name of operator* to signal that it's unsafe,
> too.

I would agree - include all raw pointer accessors or none (rather than
preventing wp->... but allowing wp.get()->...)

[snip]
> The main problem with policy-based pointer proposals so far is that nobody
> actually sat down and did the work. The only serious proposal is Andrei's
> Loki::SmartPtr, which doesn't support (out of the box) neither the array
> versions nor the current shared_ptr, and nobody has expressed willingness
to
> write the necessary paperwork (formal spec, tests, docs, that sort of
> thing.)
>
> Saying "why don't we make a policy-based smart pointer" on the list is not
> enough (this is not aimed at you personally, merely a general comment.)

I'm not in a position to propose a solution, but I could volunteer some
testing
and review work if anyone takes up the job in earnest.

Regards,
Raoul Gough.

_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


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