can I reuse statements?

Jack jckj33 at gmail.com
Mon May 10 21:01:53 UTC 2021


mixin template seems to allow only declarations so if I put a if 
or case-statement in the body it doesn't work. I'd like to make 
something like this work:

```d
             switch(code) {
                 case X, Y: // that specific case repeats alot in 
the code in different procedures
                   mixin handleXY;

                 default:
          }
```

then

```d
mixin template foo()
{
                 auto c = arr[i]; // arr and i are available at 
switch(code)'s scope
                 auto m = Message(...);

                 switch(code)
                 {
                     case BAA_A:  c.doSomething(m); break;
                     case BAA_B: c.doSomething(m); break;
                     default: assert(0, "error");
                 }
}
```


More information about the Digitalmars-d-learn mailing list