Boost logo

Boost :

Subject: Re: [boost] [outcome] Exception safety guarantees
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2017-05-27 23:44:56


2017-05-28 1:27 GMT+02:00 Peter Dimov via Boost <boost_at_[hidden]>:

> Andrzej Krzemienski wrote:
>
>> ```
>> expected<T, E> o = fun();
>> // (*)
>> if (o.has_value()) ...
>> ```
>>
>> Upon the call to has_value() how is it possible that I am experiencing
>> the valueless_by_exception state?
>>
>
> It's not possible to experience that state here. It's possible to
> experience it in other scenarios. If o is non-local, for example, the
> assignment throws, and a catch block either catches the exception and
> further code examines o, or if the catch block or a destructor calls a
> function that examines o.

My first reaction to this is: such a code is again fishy, and it is better
to avoid writing such code that offer stronger guarantees. "Examines`o`" --
for what purpose? (after the throw, nowing that it ia in a valid but
unspecified state).

But maybe it is my inability to imagine a practical use case for it. It
would help me, if you could show an example that illustrates a practical
value of such examination of an object in a valid-but-unspecified state.
(Other than to determine if it is in a valid-but-unspecified state.)

Regards,
&rzej;


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