C++ Logo

std-proposals

Advanced search

Re: P0323 std::expected - void value type?

From: Barry Revzin <barry.revzin_at_[hidden]>
Date: Sun, 4 Oct 2020 19:46:20 -0500
On Sun, Oct 4, 2020 at 7:26 PM Jason McKesson via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> And it doesn't make sense for `optional` to allow any kind of "no
> value" type. You can't have a NothingOrNothing type ;)
>

Sure it does. optional<void> still has two states: engaged nothing and
disengaged. It may seem like a weird spelling of bool, but it's a perfectly
meaningful type and fills a hole in the type system.

For instance, we could consider adding a member function ok() to
expected<T, E> that returns an optional<T> (Rust's Result has such a
function, for instance). Perhaps you have some generic code that might want
to drop the error for whatever reason. The inability to define such a
function for void is *yet another *really annoying scenario where void has
to be treated specially. The same holds for any generic operation on an
optional, really.

Barry

Received on 2020-10-04 19:46:35