Boost logo

Boost :

Subject: Re: [boost] [outcome] comments on Regular ops
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2018-01-23 06:30:26


On 23/01/2018 12:50, Peter Dimov wrote:
> Andrzej Krzemienski wrote:
>
>> This could be handled by providing a dedicated heterogeneous
>> comparison between `result<T, EC>` and `EC`.
>
> I prefer `if( !r && r.error() == condition )`. Similarly, `r? *r: x`
> instead of `r.value_or(x)`.

This is actually a good example of why operator bool might be a bad idea.

It's not too controversial for result<>, but in outcome<> "!r" will be
true if there isn't a value, but "r.error()" might throw or UB in that
case if it has an exception without an error code.

So the long-form of that test would be:

     if ( r.has_error() && r.error() == condition )


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