Boost logo

Boost Users :

Subject: Re: [Boost-users] boost shared_ptr with own dtor
From: Lars Viklund (zao_at_[hidden])
Date: 2012-12-08 14:18:57


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[]'.

Also note that while it's "initialized correctly", operator bool-ish
will still evaluate to false for a held nullptr.

Implementor beware, as always.

-- 
Lars Viklund | zao_at_[hidden]

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