Boost logo

Boost :

From: Rainer Deyke (root_at_[hidden])
Date: 2002-02-12 15:08:37


----- Original Message -----
From: "Darin Adler" <darin_at_[hidden]>
To: "Boost" <boost_at_[hidden]>
Sent: Tuesday, February 12, 2002 12:04 PM
Subject: Re: [boost] more comments on new weak_ptr

> My only worry is that there are a number of ways to accidentally use
> weak_ptr in an unsafe manner. I'd almost prefer that weak_ptr itself
not
> offer a way to check for 0 (the bool conversion and operator !),
because
> providing those operations makes it more likely that programmers
will write
> code that first checks for 0, then creates a shared_ptr, rather than
> correctly doing it the other way around.

When performing tasks such as eliminanating all expired weak pointers
from a cache, you don't want to construct a shared pointer. You just
want to check for null pointers, and false negatives are no big deal.

> If it was entirely up to me, I'd probably have the shared_ptr
constructor
> allow implicit type conversion, eliminate a.get(), and never use the
> exception.

If it was up to me, 'weak_ptr::get' would return a plain pointer
(useful and safe in a variety of cases), and a non-throwing
'shared_ptr' constructor would be used to convert to 'shared_ptr'.

--
Rainer Deyke | root_at_[hidden] | http://rainerdeyke.com

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