|
Boost : |
From: Daniel Frey (daniel.frey_at_[hidden])
Date: 2002-10-21 11:07:07
Peter Dimov wrote:
>
> From: "Daniel Frey" <d.frey_at_[hidden]>
> [...]
> > >> What does "never throws" means
> > >
> > > It means that operator* doesn't throw when its requirements ("The stored
> > > pointer must not be 0") are met, otherwise the behavior is undefined.
> >
> > Hm... I think that this point of view is perfectly reasonable if the
> > condition that throws would be the result of a bug inside shared_ptr or
> > the compiler, thus in actual code it cannot really happen. But the above
> > BOOST_ASSERT guards against wrong use of the class. Wouldn't it be better
> > to document a defined behaviour?
>
> Depends on the point of view, but the general answer is "no". Imagine that
> you are writing a shared_ptr implementation that must conform to the
> documented interface. As things currently stand, you are free to make
> operator* do whatever you think is appropriate for your situation. Had the
> behavior been defined, you wouldn't have had a choice.
To put it another way: It's undefined behaviour but you (as a user) can
add
if( !p ) throw my_defined_exception()
wherever you want - but it's up to you to guard against dereferencing
0-pointers. The BOOST_ASSERT is just a helper to detect "undefined
behaviour" but it is not guaranteed to be there (depending on DEBUG, the
compiler's support for exceptions, etc.).
I think I can live with that, althrough some policy-classes might
provide some better support for more robustness - maybe I'll play with
the idea in my own pointer-classes first and only bring this up again if
I think I have a solution - not just a question :) Thanks for the
explanation.
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