I think the properties could be much more useful as a library solution. I'm thinking a template, which generates a structure with all necessary operators overloaded. It would be much more flexible. The only downside would be absence of syntax sugar. It would work faster too in cases of opOpAssign, because opOpAssign is generally faster then a combination of opAssign and opBinary.
On Mon, May 7, 2012 at 6:19 AM, Jonathan M Davis <[email protected]> wrote: > On Monday, May 07, 2012 04:05:20 Mehrdad wrote: >> Why doesn't this compile? >> >> @property int foo() { return 1; } >> @property void foo(int v) { } >> >> void main() >> { >> foo |= 2; >> } > > Because unfortunately, properties aren't currently set up to be quite as > advanced as that. Properties read like variables and write like variables, but > they don't read and write at the same time like variables do. > > foo = foo | 2; > > would work, because each property usage is translated into a single call to a > function, but > > foo |= 2; > > doesn't, because it would require it be translated into > > foo = foo | 2; > > and then translated into calls to the property functions. I'd definitiely > argue > that it should work that way, but D's properties are simplistic enough that > they don't currently. There may or may not be an enhancement request for it, > but if not, then there probably should be. > > Another example which is brought up from time to time is > > ++foo; > > It doesn't work either, and for the same reasons. > > - Jonathan M Davis -- Bye, Gor Gyolchanyan.
