Puzzled

Max Samukha maxsamukha at gmail.com
Wed Dec 13 06:39:00 UTC 2023


On Wednesday, 13 December 2023 at 03:37:25 UTC, Don Allen wrote:

> Same complaints from the compiler:
> ````

This works (the explicit template is due to a 'need this' bug):

```
import std.stdio;

struct Foo {
     int bar;
     int baz;
}

template bletch(alias field)
{
     static void bletch(T)(ref T self, int x) {
         auto pField = &__traits(child, self, field);
         *pField = x;
         writefln("%d", *pField);
     }
}

int main(string[] args)
{
     Foo s;
     bletch!(s.bar)(s, 1);
     bletch!(s.baz)(s, 2);
     return 0;
}
```


More information about the Digitalmars-d mailing list