std.sumtype?
Steven Schveighoffer
schveiguy at gmail.com
Thu Mar 18 16:43:21 UTC 2021
On 3/18/21 12:11 PM, Paul Backus wrote:
> 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));
Wait, you can't access the tag for the tagged union?
FYI, taggedalgebraic, it's simply val.kind.
I'd suggest giving read-only access to the tag. The types are already
accessible.
-Steve
More information about the Digitalmars-d
mailing list