Using ()s in @property functions
Steven Schveighoffer
schveiguy at yahoo.com
Tue Jun 29 08:38:39 PDT 2010
On Tue, 29 Jun 2010 10:15:10 -0400, Leandro Lucarella <luca at llucax.com.ar>
wrote:
> Steven Schveighoffer, el 29 de junio a las 08:13 me escribiste:
>> >>There is one thing that bugs me about this solution though. What if
>> the
>> >>user does this:
>> >>(1) Grab the pointer. *ptr = prop;
>> >(1) Grab the pointer. T* ptr = ∝
>> >
>> >>(2) assigns to it. *ptr = val;
>> >>(3) expects the result to be updated in prop. assert(val == prop);
>> >
>>
>> Why would this assert fail? If a property returns a ref
>
> What if it doesn't? If returns a temporary calculated value?
It returns a ref. That can't be a calculated value. If it's a calculated
value then T* ptr = &prop will fail to compile.
>
>> then you
>> set through that ref. What you did is no different, you just
>> delayed the assignment for a bit.
>>
>> You can reduce your test case to:
>>
>> (1) assign to the property. prop = val;
>
> Is not the same at all! prop = val will call the setter function, *ptr
> = val will not!
Maybe you are thinking of something different, here is the code we're
discussing:
struct Foo {
uint num;
@property ref uint front() {
return num;
}
}
-Steve
More information about the Digitalmars-d
mailing list