What's wrong with std.variant.Variant?

Johannes Pfau nospam at example.com
Sat Jun 13 19:42:27 UTC 2020


Am Sat, 13 Jun 2020 15:10:04 -0400 schrieb Andrei Alexandrescu:


> 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.

I think you mean typeid? This is not Variant's fault though, we really 
need full DLL support in general...
 
> What are other problems with it?

I never had any real problems with std.variant, but I have some smaller 
nits:

* Does the Algebraic implementation use typeid/TypeInfo? I think that's 
not documented and I'd prefer a numeric/enum tag
* Memory Management is not documented


Algebraic has to compete with https://code.dlang.org/packages/
taggedalgebraic which has some more features. I never really liked the 
Agelbraic APIs (phobos and TaggedAlgebraic: casting to get values / 
explicit get calls etc.). I prefer something with a union-like interface 
like TaggedUnion:

union Base
{
    int a;
    string b;
}

alias Type = TaggedUnion!Base;

Type t = Type(0);
t.a = 42;
t.b = "foo";
writeln(t.b);
if (t.kind == Type.Kind.Foo)
if (t.isFoo)...



-- 
Johannes


More information about the Digitalmars-d mailing list