std.sumtype?
Oleg B
code.viator at gmail.com
Thu Mar 18 18:42:32 UTC 2021
On Thursday, 18 March 2021 at 18:09:38 UTC, Paul Backus wrote:
> union U1 { int n; float f; }
> union U2 { float f; int n; }
>
> static assert(is(U1 == U2)); // fails
>
> D is a nominally-typed language, not a structurally-typed one.
> That means types that are structurally identical (like the
> unions and SumTypes in the above examples) are still considered
> separate types if their names are spelled differently.
>
> IMO the behavior of SumType in this regard is perfectly
> consistent with the rest of the language. If you want to use
> structural typing instead of nominal typing in your own code,
> you can define template predicates to check for SumTypes with a
> particular structure, the same way Phobos defines predicates
> like `isInputRange` to check for types with a particular
> structure.
okey, I agree
but read-only tag (kind, type index) is key feature in chouse
between sumtype and other for me, and I hope it will be added
before next compiler release...
More information about the Digitalmars-d
mailing list