Anyway to achieve the following

Carl Sturtivant sturtivant at gmail.com
Sat Aug 14 20:50:47 UTC 2021


```
struct S {
   int x = 1234;
}

void main() {
   import std.stdio;
    S s;
    //construction of a using &(s.x)
    auto a = Ref!(int)(&s.x);
    writeln(a); //displays 1234
    s.x += 1;
    writeln(a); //displays 1235
    a += 1;
    writeln(s.x); //displays 1236
}

struct Ref(T) {
   T* ptr;
   this(T* p) { ptr = p; }
   string toString() { import std.conv; return to!string(*ptr); }
   ref T var() { return *ptr; }
   alias var this;
}
```


More information about the Digitalmars-d-learn mailing list