On Mon, 07 May 2012 15:35:35 -0400, Jacob Carlborg <[email protected]> wrote:
On 2012-05-07 14:43, Steven Schveighoffer wrote:
It's like this in C#.
I can't decide whether I like it better in D or C#. Clearly the compiler
lowering of foo |= 2 to foo = foo | 2 would be benficial in terms of
less code to write.
But I also like having control over how properties can implement
operators. For example, the above is two function calls, but it may be
easier/more efficient written as one. The issue is, how do you do that?
The current definition syntax doesn't lend itself well to extension...
-Steve
If an operator is overloaded use that single function, otherwise do a
rewirte.
How do you overload the operator for a property? For example:
struct S
{
int x;
}
struct T
{
private int _x;
@property S s() { return S(_x);}
@property void s(S news) { _x = newS.x; }
}
How do I define T.s |= 5 ???
I realize we could define opBinary("|") on S, and depend on the rewrite,
but I'd rather do it in one operation.
-Steve