On Monday, 10 May 2021 at 21:10:13 UTC, Paul Backus wrote:
On Monday, 10 May 2021 at 21:01:53 UTC, Jack wrote:
[...]

You can do it with a string mixin:

```d
// Note: q{ ... } creates a "token string", a special kind of string literal
// that's used for code strings.
// See https://dlang.org/spec/lex.html#token_strings
enum string handleXY = q{
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");
                }
};
```

Usage:

```d
case X, Y:
    mixin(handleXY);
```

sounds good, thanks!

Reply via email to