Boost logo

Boost Users :

Subject: Re: [Boost-users] [smart_ptr] weak_ptr pointer semantics
From: Szymon Gatner (szymon.gatner_at_[hidden])
Date: 2011-11-10 19:46:39


> Because it is not safe to have a pointer to something and not reference
> count it.

Not sure what you mean here, I still have weak_ptr<> which has a counter
and there is a shared_ptr<> (or not) somewhere out there. So counter exists
as long as I still have any shared_ or weak_ pointer.

 See the explanation at
> http://www.boost.org/doc/libs/1_47_0/libs/smart_ptr/weak_ptr.htm for a more
> detailed argument of the same.

Thanks, no idea how I missed that. Makes perfect sense in threaded world
but not convinced for single-threaded.

 If you don't want safety in your pointers,
> then use raw pointers. If you want safety, then you have to accept the
> consequences...

So using get() on shared/scoped/auto/unique_ptr somehow keeps me safe
having raw pointer that bypasses all protection they provide but weak_ptr
is too much? Not buying it ;)

Cheers,
Simon


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