std.sumtype?

Steven Schveighoffer schveiguy at gmail.com
Thu Mar 18 17:39:04 UTC 2021


On 3/18/21 1:24 PM, Oleg B wrote:
> May be depending on order of types must be fixed too
> 
> ```
> alias S1 = Sumtype!(int, float);
> alias S2 = Sumtype!(float, int);
> 
> static assert (is(S1 == S2)); // false by now
> ```
> because no different between S1 and S2 in practice use

That requires sorting the types somehow, which isn't really easy or 
cheap at compile-time.

It's the same for std.variant.Algebraic (although it's a runtime error 
instead of a compile-time one).

It's kind of a tradeoff that you have to live with -- nice type 
checking, but you have to keep the same order for sanity.

-Steve


More information about the Digitalmars-d mailing list