C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Fwd: Extension to runtime polymorphism proposed

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Fri, 10 Apr 2026 10:01:50 -0400
On Fri, Apr 10, 2026 at 8:30 AM Muneem via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> std variant is still a union, like it has the baggage of a union. The "type safety" that is probably achieved by a few underlying tags is just to help you keep track of what the union means.

"Is probably achieved"? Do you... do you not know how a variant
*works* internally?

> It is not type safe in its mechanics but used to wrap something meant to be flexible. You are right variants are closed sets, sorry, but it is still based of a very flexible closed set (a union). Like why implement strict dynamic typing in the mechanical terms of closed set duck typing!?

Because if you want "closed set duck typing", the only difference
between that and what `variant` offers is that you have to manually
write a bunch of visitor helpers to achieve closed set duck typing
with `variant`. The internal data representation of the current
`variant` and a type which offers "closed set duck typing" is *the
same*.

The only difference is ergonomical. That's not meaningless of course,
but in terms of data representation (ie: the bits stored in the object
and what they mean), they both use the exact same data set: a union
and a value saying which type is currently valid for access.

Received on 2026-04-10 14:02:04