Date: Tue, 28 Oct 2025 15:07:56 +0100
Il 28/10/25 12:46, Nikl Kelbon via Std-Proposals ha scritto:
> No one really has correct code with std::varant right now, because no
> one handles valueless_by_exception, but its possible to get rid of it.
>
> 0. backup memory of old value
> 1. construct new value ON TOP of memory of old value
> On exception just memswap backup and new value (new value not constructed)
This was extensively discussed. You may also want to read about the
design of Boost.Variant2.
https://www.boost.org/doc/libs/latest/libs/variant2/doc/html/variant2.html#design_rationale
TL;DR: backup *where*? In the variant object itself? Then you don't need
a backup, but all of your variants now are twice as big. On the heap?
This brings allocator-awareness into std::variant and memory allocation
may fail.
On a quality implementation requiring that all the types in a variant
are nothrow move assignable should be sufficient to guarantee that the
variant is never in a valueless state.
My 2 c,
--
Giuseppe D'Angelo
> No one really has correct code with std::varant right now, because no
> one handles valueless_by_exception, but its possible to get rid of it.
>
> 0. backup memory of old value
> 1. construct new value ON TOP of memory of old value
> On exception just memswap backup and new value (new value not constructed)
This was extensively discussed. You may also want to read about the
design of Boost.Variant2.
https://www.boost.org/doc/libs/latest/libs/variant2/doc/html/variant2.html#design_rationale
TL;DR: backup *where*? In the variant object itself? Then you don't need
a backup, but all of your variants now are twice as big. On the heap?
This brings allocator-awareness into std::variant and memory allocation
may fail.
On a quality implementation requiring that all the types in a variant
are nothrow move assignable should be sufficient to guarantee that the
variant is never in a valueless state.
My 2 c,
--
Giuseppe D'Angelo
Received on 2025-10-28 14:07:59
