struct S
    {
        int x;

        ref S byRef() return
        {
            return this;
        }
    }

    void main()
    {
        import std.conv : to;
        import std.stdio : writeln;

        S s;

        s.x = 1;
        auto s2 = s.byRef();
        s2.x = 2;
        writeln(&s, " vs ", &s2);
        assert(s2.x == 2, s2.x.to!string());
        assert(s.x == 2, s.x.to!string());
    }


Output from v2.113
7FFF27E25958 vs 7FFF27E2595C
[email protected](23): 1
----------------
??:? _d_assert_msg [0x5ef4a93a89d0]
./onlineapp.d:23 _Dmain [0x5ef4a93841c7]
  • Should this work... apz28 via Digitalmars-d-learn

Reply via email to