|
Boost : |
From: John Maddock (John_Maddock_at_[hidden])
Date: 2001-06-17 05:28:44
>The deletion of the newly allocated object can be guaranteed easily by
using a variation of the swap-idiom for exception safety:
template<class T>
void auto_ptr<T>::reset(T* new_p)
{ // short circuit self-assignment
if (this_p == new_p)
return;
// swap (performed here only partially)
T* old_p = this_p;
this_p = new_p;
// perform operations that might throw
delete old_p;
}
<
I don't think that that is any safer than the current version - all you've
done is change the thing that leaks - now if the destructor throws it's
old_ptr that leaks rather then new_ptr, how is this any better? Come to
that what does it mean for a destructor to throw anyway?
- John Maddock
http://ourworld.compuserve.com/homepages/john_maddock/
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk