In Andrei's book, as well as in the Phobos source, there are property getters that return refs, as in...

 @property ref T front() {
     return _payload[0];
 }

... and code that uses this with simple assignments, such as:

 r.front = foo;

For some reason, I can't get this to work in my code :-/ DMD seems to insist that I add a setter as well (i.e., @property T front(T val) { return _payload[0] = val; }).

On the other hand, I *do* get

 r.front() = foo;

to work. That works well even without @property, of course; and r.front fails even without @property.

Then, again, if I write both the getter (front()) and the setter (front(T)), that works even without @property (which, then, seems rather redundant?).

So ... I guess I have two questions:

1. What's the point of @property (when it seems I get the same functionality without it)? 2. How can I make r.front = foo work, when I only have r.front(), returning a ref (which seems like it is used in actual code)?

--
Magnus Lie Hetland
http://hetland.org

Reply via email to