What's wrong with std.variant.Variant?
Mathias LANG
geod24 at gmail.com
Sun Jun 14 06:59:38 UTC 2020
On Saturday, 13 June 2020 at 19:10:04 UTC, Andrei Alexandrescu
wrote:
> I was curious about collecting a list of grievances about
> Variant. It's the oldest piece of generic code in std, and it
> predates a lot of good language additions.
>
> So what's wrong with Variant? One thing I collected from a
> coworker is that it doesn't work with Windows DLLs, because in
> turn typeof() comparison does not work across Windows DLLs.
>
> What are other problems with it?
I tried to use it a while ago and figured rolling out my own
would be better (https://github.com/Geod24/minivariant). I've
seen other (and probably better) implementations out there, but I
mostly use this one because I'm familiar with the tradeoff.
I think most people want a tagged union over a generic variant
type, however things are built the other way around: the tagged
union is built on the generic variant type. Building a typed
union over a type that relies on type erasure means Algebraic has
to reimplement all the conversions rules that would normally be
done by the compiler, e.g. assigning `immutable(uint)` to a
`ulong` should just work, but it does not.
More information about the Digitalmars-d
mailing list