On Wednesday, 18 February 2026 at 19:43:38 UTC, JN wrote:
    template WrapCall(string call)
    {
        enum WrapCall = "before(); " ~ call ~ "; after();";
    }

    void main()
    {
        mixin WrapCall!"add(1, 2)";
    }

The mixin statement inserts the body of the template into main's scope, so this just declares a string enum:

```d
void main()
{
    enum WrapCall = "before(); " ~ "add(1, 2)" ~ "; after();";
}
```
Note that eponymous templates don't do anything special for mixin statements.

This doesn't work, if I change it to mixin(WrapCall!"add(1, 2")), it works, why?

Because that string mixin takes an enum string template instantiation and parses it as if it were code inside main, so you get:

```d
void main()
{
    before(); add(1, 2); after();
}
```

Reply via email to