C++ Logo


Advanced search

Subject: Re: [std-proposals] P0323 std::expected - void value type?
From: Barry Revzin (barry.revzin_at_[hidden])
Date: 2020-10-05 10:55:46

On Mon, Oct 5, 2020 at 10:42 AM Emile Cormier via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> Thanks, Arthur. Thinking of expected as a "wrapper" around a return type
> makes more sense to me now than thinking of it as a "container of one or
> error".
> If C/C++ had been designed with void being an empty monostate value type,
> I guess we wouldn't have all this trouble of treating void as a special
> case in generic programming. Libraries wouldn't have needed to invent their
> own "nothing" types like nullopt_t or monostate_t.

std::monostate (no _t), yes. But we'd need nullopt anyway in order to
properly identify the empty state of the optional, which is why you cannot
have an optional<nullopt_t>. Similar to how Haskell/Rust have a proper unit
type - spelled () - but nevertheless have Nothing/None to identify the
empty state.


STD-PROPOSALS list run by std-proposals-owner@lists.isocpp.org

Standard Proposals Archives on Google Groups