|
Boost Users : |
Subject: Re: [Boost-users] boost shared_ptr with own dtor
From: Andrew Holden (andrewholden1_at_[hidden])
Date: 2012-12-08 16:33:39
On Dec 8, 2012, at 2:18 PM, Lars Viklund <zao_at_[hidden]> wrote:
> On Sat, Dec 08, 2012 at 01:34:18PM -0500, Andrew Holden wrote:
>> That will work unless cptr_open() returns NULL. If I recall, if cptr_open() returns NULL, then the shared_ptr will report it is initialized correctly even though it contains a NULL pointer, and will call cptr_close (NULL) when it goes out of scope.
>
> This is of course not necessarily an error if your deleter is documented
> to Do The Right Thing on nulls, like 'free', as well as simple wrappers
> around 'delete' and 'delete[]'.
True, and if cptr_close was written by the O.P., then adding a check for NULL would be trivial and would not have a measurable impact on runtime.
> Also note that while it's "initialized correctly", operator bool-ish
> will still evaluate to false for a held nullptr.
Good point. For whatever reason (I can't remember why) I got into the habit of calling shared_ptr::empty() instead of using the pointer as a bool. You just gave me a reason to revisit that decision.
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