I just figured out how to store a reference:

@safe:
auto x(ref int a) {
        struct A {
                ref int xa() { return a; }
        }
        return A();
}
void main() {
        import std.stdio;
        int b = 10;
        auto a = x(b);
        a.xa = 20;
        writeln(b); //Prints 20
}

I have no idea if this is a right thing to do. Can someone tell me if this is idiomatic D, and whether there're any catches to this method or not?

Thanks.

Reply via email to