Subject: Re: [boost] [variant2] Formal review
From: Gavin Lambert (boost_at_[hidden])
Date: 2019-04-16 22:58:50


On 17/04/2019 05:07, Emil Dotchevski wrote:
>> I guess you are referring to function std::visit(), which checks for
>> valueless_by_exception state and if one is detected throws an exception.
>
> https://github.com/llvm-mirror/libcxx/blob/master/include/variant
>
> I counted 20+ checks, but actually even if the runtime cost was zero, the
> empty state is one more thing the user has to think about, one more thing
> that could go wrong -- but only in the context of error handling where
> writing unit tests, debugging and QA are all extra difficult.

That's just an example of poor design/optimisation, though. The
valueless state should be treated as just another index position exactly
like any other (ironically, pretty much exactly how Peter's
"non-valueless" variant does). Then checking for the valueless state is
precisely identical to checking for any other state, so it does come for
free.