pon., 8 kwi 2019 o 02:56 Gavin Lambert via Boost
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
::is_single_buffered(); or
static constexpr bool variant
::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;