Simplify some C-style code

sfp sfp at hush.ai
Wed Dec 25 17:30:30 UTC 2024


On Wednesday, 25 December 2024 at 17:20:01 UTC, user1234 wrote:
> On Wednesday, 25 December 2024 at 16:41:05 UTC, sfp wrote:
>> On Wednesday, 25 December 2024 at 07:57:04 UTC, monkyyy wrote:
>>> static foreach, traits and mixin
>>
>> I was looking into this but I think I need some help getting 
>> off the ground...
>>
>> This doesn't compile:
>> ```
>> enum Test { mixin("A, B, C") }
>> ```
>
> Mixins can only introduce certain type of nodes: Type, 
> Declaration, Expression, and Statement. Honestly I dont see how 
> would they help here... What you can do however is to use 
> https://dlang.org/phobos/std_sumtype.html. instead of a the 
> manually defined tagged union.

Unfortunately, std.sumtype doesn't seem to work for my case. I 
want to be able to define several mutually recursive types. It 
seems the only way to define a recursive type using std.sumtype 
is the `This` parameter. For instance, this doesn't work:
```
alias Blah = SumType!(A);
struct A { Blah *b; }
```
Throws an error about recursive template expansion or something.


More information about the Digitalmars-d-learn mailing list