Boost logo

Boost :

From: Mike Tegtmeyer (tegtmeye_at_[hidden])
Date: 2007-11-02 16:50:06



On Fri, 2 Nov 2007, Mike Tegtmeyer wrote:

> I am often asked why shared_ptr always uses the custom deleter even when
> the pointer argument is zero. I know it is safe to delete a NULL pointer
> so this works with delete but it would seem that if the user is giving a
> custom deleter, then they are probably doing something else. ie
> //will crash if fread returns 0
> shared_ptr<FILE> foo(fread("foo.txt","r"),fclose);
> This is an easy screw-up for most new folks and the docs don't really
> explicitly point out this (I think) non-obvious behavior.
> One can obviously wrap the deleter with a check among numerous other
> things but I'm curious what the rationale was since this won't work "out
> of the box" with C APIs. Can someone point me to the dialog discussing
> the design decision for this behavior so I can pass it along?
> Thanks,
> Mike
> _______________________________________________
> Unsubscribe & other changes:

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