On Monday, 29 July 2013 at 21:25:21 UTC, Temtaime wrote:
No, i cannot.

struct S {
        uint longnamed;
}

void main() {
        S somestruct;

        alias v = somestruct.longnamed;
        writeln(v);
}

Error: need 'this' for 'longnamed' of type 'uint'

Is it a bug ?

Oh, that is annoying...
Then, make your own reference type:

import std.stdio;

struct S {
        uint longnamed;
}

struct Ref(T) {
public:
        T* ptr;
        
        @disable
        this();
        
        /*@disable
        this(this);*/
        
        @disable
        this(typeof(null));
        
        @disable
        void opAssign(ref Ref!T);
        
        this(T* ptr) {
                this.ptr = ptr;
        }
        
        @property
        ref inout(T) get() inout {
                return *this.ptr;
        }
        
        alias get this;
}

void main() {
        S somestruct;

        Ref!uint v = &somestruct.longnamed;
        writeln(v);
}

Reply via email to