On Sun, Jan 27, 2013 at 01:15:29AM +0100, Rob T wrote:
> We can almost implement properties as a regular struct
[...]

You do it like this:

        import std.stdio;

        struct IntProp {
                int __impl;

                @property /* <-- ah, the irony! */ int value() {
                        return __impl + 123;
                }
                alias value this;       // watch this magic

                void opAssign(int val) {
                        __impl = val - 123;
                }
        }

        struct S {
                IntProp prop;
        }

        void main() {
                S s;
                writeln(s.prop);
                s.prop = 321;
                writeln(s.prop);
        }


T

-- 
Gone Chopin. Bach in a minuet.

Reply via email to