www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - getter/setter in one function (almost)

unfortunately, dmd doesn't accept the signature as a valid property.



import std.stdio;
import std.typecons;

struct T {
     int _i;

      property int i(Nullable!int derp = Nullable!int.init) {
         return _i = derp.isNull ? _i : derp.get;
     }
}
void main () {
     T t;
     t.i = 1;
     writeln(t.i);
}
Jul 15 2013