Boost logo

Boost :

Subject: Re: [boost] variant - off topic
From: Robert Ramey (ramey_at_[hidden])
Date: 2019-04-08 14:58:46


On 4/8/19 12:29 AM, Gavin Lambert via Boost wrote:
> On 8/04/2019 18:29, Robert Ramey wrote:
>> LOL - Looks good to me!  So now we have std::variant that is
>> guaranteed to have a valid state with no double buffer BS and no extra
>> overhead.
>
> It's restricted to only trivial types, however, which sharply limits its
> usability.  (Mostly just to primitives and PODs, though that's an
> oversimplification.)
>
> Or did you mean to check is_nothrow_constructible rather than
> is_trivially_constructible?

I looked at both nothrow and trivial and couldn't figure out the
difference between them with spending more time than I wanted to at the
time. After, I was just throwing out an idea for discussion.

Note that this approach is not really a rival to making a new variant.
It's to explicit limited the usage a variant to those situations where
there are none of the problems and tradeoffs that implementations of
variants have to address.

Basicall, I'm giving up on trying to understand all this stuff. I just
need something that "just works" in an efficient simple way or "just
fails(tm)" if that's not possible. It it just fails, I'll fall back to
the "fancy variant" (and spend a lot of time investigating the tradeoffs
and error/exception handling requirements) or alter my types so the
safe_variant just works.

> (Also, for robustness you should check assignment as well as construction.)

Hmmm - interesting point. My goal was to make it impossible for
safe_variant to end up in the the dreaded stateless state. I was
gathering from the discussions that assignment to variant entailed
construction of a new instance of one of the constituent types was key
place where the stateless problem can occur. So you're absolutely right
in that the checks have to be implemented for all operations which might
be used.

Robert Ramey

>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost


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