Boost logo

Boost :

From: Daniel Frey (daniel.frey_at_[hidden])
Date: 2003-05-15 09:57:12


Markus Werle wrote:
> In one of Herb Sutters articles I saw that
> after deleting a pointer (a pimpl) he assigns 0 afterwards
> which seems to me like a good idea.
> (see e.g. http://www.gotw.ca/gotw/028.htm or http://tinyurl.com/bq8o)
>
> Maybe there is a good reason (efficiency?)
> why checked_delete omits this extra step.
> Please explain

Setting the pointer to 0 is mostly useful for debugging, I guess, but
there might be other reasons. but the reason to use
boost::checked_delete is to add a test for an incomplete type - and
nothing more. It's an orthogonal concept and these concepts shouldn't be
mixed in one helper. Otherwise, you'd replace

delete t;
t = 0;

by

boost::checked_delete(t); // "new" version

instead of

boost::checked_delete(t); // "old" version
t = 0;

Maybe you want to write another helper if you need it often enough:

template< typename T > void delete_and_reset( T*& t )
{
    boost::checked_delete( t );
    t = 0;
}

Of course the delete_and_reset-concept implies the
checked_delete-concept, but not vice versa!

Regards, Daniel

-- 
Daniel Frey
aixigo AG - financial training, research and technology
Schloß-Rahe-Straße 15, 52072 Aachen, Germany
fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99
eMail: daniel.frey_at_[hidden], web: http://www.aixigo.de

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