Simplify some C-style code

sfp sfp at hush.ai
Wed Dec 25 18:25:57 UTC 2024


On Wednesday, 25 December 2024 at 17:46:01 UTC, monkyyy wrote:
> On Wednesday, 25 December 2024 at 17:20:01 UTC, user1234 wrote:
>> What you can do however is to use 
>> https://dlang.org/phobos/std_sumtype.html. instead of a the 
>> manually defined tagged union.
>
> If he's struggling to define a enum with a mixin I assume he's 
> very new and to get this code to work with sumtype would 
> require a template map, which would make you a highly competent 
> template wizard

Thanks for fleshing out an example for me. That's a big help. 
Understanding that `mixin` only works for certain AST nodes is 
useful... but kind of weird that it doesn't work inside `enum`. 
Seems like an obvious application...

I'm an experienced programmer but new to D. I've done a decent 
amount of template metaprogramming in C++, but not really a 
wizard there either. Just enough to be dangerous (mostly to 
myself).

What is a template map? I'd be interested in seeing this pattern 
and whether it's worth it to try to salvage std.sumtype.

I also saw a thread about a language level (possibly?) sumtype. 
Is this feature going to resolve the `This` parameter grossness?


More information about the Digitalmars-d-learn mailing list