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
> ...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
> 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
> 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
> 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()->...)

> 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
> 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
and review work if anyone takes up the job in earnest.

Raoul Gough.

Do You Yahoo!?
Get your free address at

Boost list run by bdawes at, gregod at, cpdaniel at, john at