On Thursday, 7 May 2020 at 14:53:10 UTC, Steven Schveighoffer
wrote:
On 5/7/20 5:22 AM, learner wrote:
[...]
Because VariantN (the base of Algebraic) can literally hold
anything, it cannot be pure, @safe, nothrow, @nogc.
As others have recommended, I suggest using TaggedAlgebraic. I
recently have been using it to create an algebraic type to hold
a MYSQL value, so I can migrate the mysql-native library to be
@safe (mysql-native currently uses Variant for everything).
I added a special UDA to TaggedAlgebraic, so you can guarantee
only @safe calls are allowed (for instance, if it can hold a
pointer and an int, then opBinary!"+" can be marked as @safe if
the operation fails when it's a pointer).
TaggedAlgebraic could probably do the same for pure, but not
sure about nothrow and @nogc, since it uses exceptions when
things aren't valid.
-Steve
Modules of D standard library aren't in a good shape, if everyone
suggests alternatives for a basic building block as variant.
The types VariantN can hold are known at compile time, why can't
it be specialized?