|
Boost : |
Subject: Re: [boost] [outcome] outcome without empty state?
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2017-05-24 23:45:52
On 25/05/2017 07:54, Niall Douglas wrote:
>> 3. A default-constructed result<T> is initialized as if
>> `result<T>{error_code_extended{}}`.
>
> I feel lots of gut feelings against that default. It seems a bit of a hack.
>
> Also, I remember Expected used to do this as a default, but it was
> undone. I would assume someone from WG21 gave a very good reason why.
>
> I will say that I cannot think of a good technical reason not to default
> construct to a null error_code. But just because you can doesn't mean
> you should.
Visions of "An error occurred: The operation succeeded" dialog boxes
scroll through my brain.
I like Peter Dimov's suggestion of defaulting to a non-null error code,
especially where T is not void. This requires explicitly acknowledging
success. (I'm not sure about the case where T is void. I'm initially
inclined to want the same for consistency, but I suspect that would be
too painful to actually use in practice.)
Perhaps a suitable default would be std::errc::state_not_recoverable?
That seems appropriate while being fairly rare as a regular error code.
(Or of course since we're talking about std::error_code, a custom error
category that isn't convertible to errc could be used for this instead.)
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk