Re: Dealing with property function and operator overloads

2011-10-04 Thread Andrej Mitrovic
Also I can use a forward function for toString, I didn't realize this until now: string toString() { return to!string(payload); }

Re: Dealing with property function and operator overloads

2011-10-04 Thread Andrej Mitrovic
On 10/4/11, Jacob Carlborg wrote: > No "alias this" in the wrapper? I shouldn't have named it Wrapper, you could better think of it as a Widget with a position field, if that position is changed (and not just read from) then some kind of repaint mechanism would be invoked. However I shouldn't in

Re: Dealing with property function and operator overloads

2011-10-03 Thread Jacob Carlborg
On 2011-10-03 20:57, Andrej Mitrovic wrote: Looks like I can use some D tricks for this: import std.stdio; struct Point { int x, y; void opOpAssign(string op)(int rhs) { mixin ("x = x " ~ op ~ " rhs;"); mixin ("y = y " ~ op ~ " rhs;"); } } struct Wrapped(

Re: Dealing with property function and operator overloads

2011-10-03 Thread bearophile
Steven Schveighoffer: > I suspect operator overloads are going to be a large hole in the interface > design of many objects, but at least they won't be exploitable once > compiled. Just after the introduction of the new operator overload syntax I have suggested to introduce strict tests to s

Re: Dealing with property function and operator overloads

2011-10-03 Thread Andrej Mitrovic
On 10/3/11, Steven Schveighoffer wrote: > Even so, it's better for people who are not familiar with the language to > see correct code vs. code open to exploitation. I can see your point. I'll make some simple constraints when I post code samples like this from now on.

Re: Dealing with property function and operator overloads

2011-10-03 Thread Steven Schveighoffer
On Mon, 03 Oct 2011 16:07:19 -0400, Andrej Mitrovic wrote: On 10/3/11, Steven Schveighoffer wrote: Probably slightly off topic, but be very careful with operator overloads without using constraints. For example, I can do some weird things to your struct: Point p; p.opOpAssign!"*x; y+="(5

Re: Dealing with property function and operator overloads

2011-10-03 Thread Andrej Mitrovic
On 10/3/11, Steven Schveighoffer wrote: > Probably slightly off topic, but be very careful with operator overloads > without using constraints. > > For example, I can do some weird things to your struct: > > Point p; > > p.opOpAssign!"*x; y+="(5); > > I suspect operator overloads are going to be a

Re: Dealing with property function and operator overloads

2011-10-03 Thread Steven Schveighoffer
On Mon, 03 Oct 2011 14:57:33 -0400, Andrej Mitrovic wrote: Looks like I can use some D tricks for this: import std.stdio; struct Point { int x, y; void opOpAssign(string op)(int rhs) { mixin ("x = x " ~ op ~ " rhs;"); mixin ("y = y " ~ op ~ " rhs;"); } } P

Re: Dealing with property function and operator overloads

2011-10-03 Thread Andrej Mitrovic
Forgot to add an opAssign in Wrapped as well: void opAssign(T)(T rhs) { payload = rhs; dg(); } That takes care of assigning and ops that change the object's state.

Re: Dealing with property function and operator overloads

2011-10-03 Thread Andrej Mitrovic
Looks like I can use some D tricks for this: import std.stdio; struct Point { int x, y; void opOpAssign(string op)(int rhs) { mixin ("x = x " ~ op ~ " rhs;"); mixin ("y = y " ~ op ~ " rhs;"); } } struct Wrapped(T) { T payload; alias payload this; void

Dealing with property function and operator overloads

2011-10-03 Thread Andrej Mitrovic
Sample code: struct Point { int x, y; void opOpAssign(string op)(int rhs) { mixin("x = x " ~ op ~ " rhs;"); mixin("y = y " ~ op ~ " rhs;"); } } struct Wrapper { void notifyChanged() { } @property void point(Point newpoint) { _p = newpoint; notifyChanged();