std.sumtype?

Paul Backus snarwin at gmail.com
Thu Mar 18 16:11:06 UTC 2021


On Thursday, 18 March 2021 at 15:58:55 UTC, Oleg B wrote:
> auto tag = val.match!(
>   (Type1 t1) => 0, // or MyOwnValTag.type1
>   (Type2 t2) => 1, // or MyOwnValTag.type2
>   ... etc
> );
>
> next write tag, in next match write value
>
> how to generate this match without mixins? how to get (in 
> general way) type from sumtype val by own tag or number for 
> deserialization?

Something like this:

alias QualifiedTypes = CopyTypeQualifiers!(typeof(val), 
val.Types);
auto tag = val.match!(v => staticIndexOf!(typeof(v), 
QualifiedTypes));


More information about the Digitalmars-d mailing list