Thread overview | |||||
---|---|---|---|---|---|
|
May 15, 2005 property: feature enhancement | ||||
---|---|---|---|---|
| ||||
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 15, 2005 Re: property: feature enhancement | ||||
---|---|---|---|---|
| ||||
Posted in reply to ehance | > 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 19, 2005 Re: property: feature enhancement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Uwe Salomon | Uwe Salomon wrote:
>> 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.
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 Sauls
|
Copyright © 1999-2021 by the D Language Foundation