Boost logo

Boost :

From: Alexander Terekhov (terekhov_at_[hidden])
Date: 2003-10-09 09:31:12


Peter Dimov wrote:
>
> Alexander Terekhov wrote:
> > Peter Dimov wrote:
> [...]
> >>> ... and never actually do a reset, to begin with.
> >>
> >> This is known and expected. reset() is assumed to give the basic
> >> guarantee.
> >
> > That makes no sense to me.
>
> Heh. I don't care. Most of what you post makes no sense, you still expect us
> to parse it. Look it up.

I did.

"void reset(); // never throws
 Effects: Equivalent to shared_ptr().swap(*this)."

"shared_ptr(); // never throws"

"void swap(shared_ptr & b); // never throws"

>
> >> If the reset() attempt fails, the fallback is that the pointer will
> >> be destroyed later, when all weak pointers die.
> >
> > And what if throws later as well?
               ^
               |
it ------------+

>
> What if _what_ throws?

Damn. *p_.reset();*

You wrote: "If this is not the case, p_.reset() should be wrapped in
a try {} catch(...) {} block that ignores exceptions. In the (usually
unlikely) event when an exception is thrown and ignored, p_ will be
released when the lifetime of the deleter ends." Nevermind that you
also wrote "~weak_ptr(); Effects: Destroys this weak_ptr but has no
effect on the object its stored pointer points to.".

> The destructor? Destructors never throw. :-)

Never say never. In the current C++ destructors can throw by default.
In my book, they shall have implicit throw()-nothing ES by default.

>
> >> The problem of course
> >> only arises when reset() can throw, and is a good illustration why
> >> it should be nothrow, which shared_ptr::reset() is.
> >
> > Same logic also applies to "p_.reset();"
>
> That makes no sense to me. :-)

Damn.

"void reset(); // never throws
 Effects: Equivalent to shared_ptr().swap(*this)."

and

"Destructors never throw." Oder? ;-)

regards,
alexander.


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