@property - take it behind the woodshed and shoot it?

H. S. Teoh hsteoh at quickfur.ath.cx
Sat Jan 26 17:09:11 PST 2013


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.


More information about the Digitalmars-d mailing list