C++ Logo

std-proposals

Advanced search

Re: std::variant - going from Alternative& to the enclosing variant&

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Fri, 11 Sep 2020 03:03:27 +0300
On Fri, 11 Sep 2020 at 02:49, Marcin Jaczewski via Std-Proposals
<std-proposals_at_[hidden]> wrote:
> One thing, why do you not implement `variant_from_alternative`
> yourself? If standard can do it, then you can do it too.

Incorrect. The layout of variant's data is not accessible that way to
client code.

> If you can't do it then is it possible for a standard library to do it
> correctly?

Yes. There's nothing to it, the stdlib vendors know their variant's
internals, and can convert
a reference to a variant member to a variant without any trouble.

Received on 2020-09-10 19:07:09