Boost logo

Boost :

Subject: Re: [boost] Variant2 review
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2019-04-08 16:32:00


pon., 8 kwi 2019 o 02:56 Gavin Lambert via Boost <boost_at_[hidden]>
napisał(a):

> On 8/04/2019 05:03, Peter Dimov wrote:
> > Phil Endecott wrote:
> >> - I would love to have some way to get a warning or error if the
> >> double storage mode had been triggered, or to disable that mode (with
> >> an error).
> >
> > I was thinking of addressing this by adding either
> >
> > static constexpr bool variant<T...>::is_single_buffered();
> >
> > or
> >
> > static constexpr bool variant<T...>::is_double_buffered();
> >
> > (not sure which spelling is better), so that you can static_assert that
> > your variants are never double-buffered.
>
> Something like this would definitely be nice.
>
> Especially when something as simple as accidentally omitting "noexcept"
> can cause a significant behavioural and storage size change, it's great
> to be able to tell the compiler that this was unintended.
>
> (Of course, as I've said before I would have preferred that this choice
> was made by providing two different front-end "variant" types -- that
> way the assert is already inside the library and the user can't forget
> to make it.)
>

Such thing could be achieved if the behavior of variant's assignment and
emplacement was controlled by a type trait. The default implementation for
unfriendly types would be compile-time error; but users would be able to
specialize it for their instantiations of variant in order to assign
different semantics: double buffering, or setting the
valueless_by_exception state.

Regards,
&rzej;


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