digitalmars.D - property: feature enhancement
- ehance d.com (14/15) May 14 2005 From D doc:
- Uwe Salomon (4/9) May 15 2005 The op= operators are guaranteed to evaluate the lvalue only once. If yo...
- Chris Sauls (6/13) May 19 2005 As far as I can see, (T prop(T)) is still only being called once. Is
From D doc: int test() { Foo f; f.data = 3; // same as f.data(3); return f.data + 3; // same as return f.data() + 3; } So how about: f.data += 3; // same as f.data( f.data()+3 ) f.data -= 3; // same as f.data( f.data()-3 ) f.data *= 3; // same as f.data( f.data()*3 ) f.data /= 3; // same as f.data( f.data()/3 )<<= ..=
May 14 2005
So how about: f.data += 3; // same as f.data( f.data()+3 ) f.data -= 3; // same as f.data( f.data()-3 ) f.data *= 3; // same as f.data( f.data()*3 ) f.data /= 3; // same as f.data( f.data()/3 )The op= operators are guaranteed to evaluate the lvalue only once. If you rewrite it the way you propose, this would not be true anymore. Ciao uwe
May 15 2005
Uwe Salomon wrote:As far as I can see, (T prop(T)) is still only being called once. Is there some case wherein the Settor (T prop(T)) needs to emulate a Gettor (T prop()), thereby causing an internal change before the operation? If not, then I don't see how its no longer true. -- Chris Saulsf.data += 3; // same as f.data( f.data()+3 ) f.data -= 3; // same as f.data( f.data()-3 ) f.data *= 3; // same as f.data( f.data()*3 ) f.data /= 3; // same as f.data( f.data()/3 )The op= operators are guaranteed to evaluate the lvalue only once. If you rewrite it the way you propose, this would not be true anymore.
May 19 2005