Boost logo

Boost :

From: Daniel Frey (d.frey_at_[hidden])
Date: 2002-10-19 12:00:25


On Sat, 19 Oct 2002 17:10:32 +0200, Peter Dimov wrote:

> From: "Daniel Frey" <d.frey_at_[hidden]>
>> Hi,
>>
>> I have a (maybe dumb) question. The current version of shared_ptr
>> contains
> code
>> like:
>>
>> typename detail::shared_ptr_traits<T>::reference operator* () const //
> never throws
>> {
>> BOOST_ASSERT(px != 0);
>> return *px;
>> }
>>
>> 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? For some applications, this may be of
great use, e.g. a server that answers HTTP requests. Whatever happens
inside a request, it should never kill the server itself, just the
current operation. Or is there any reason why '// never throws' needs to
be guaranteed and undefined behaviour for buggy uses of shared_ptr?

Regards, Daniel


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