lvalue forwarding struct?

Chad J gamerChad at _spamIsBad_gmail.com
Tue Aug 21 11:24:34 PDT 2007


Bill Baxter wrote:
> Chad J wrote:
>> What I am looking for is a templated struct that simply wraps a 
>> variable, and ensures lvalueness is preserved for that variable.
>> Ex:
>>
>> foo(bar) *= 9;
>>
>> In this case foo is to be a function that acts on bar, and then makes 
>> sure that bar has the *= 9; applied to it.
>>
>> It might look like this:
>>
>> int foo(inout int input)
>> {
>>   input++;
>>   return lvalue(input);
>> /* lvalue(...) is an opCall constructor for the lvalue templated 
>> forwarding struct.  */
>> }
> 
> It certainly isn't going to work if you return 'int'.
> 
>> Thus we could write
>>
>> int bar = 3;
>> foo(bar) *= 9;
>> printf( "%d", bar ); // prints 36
>>
>> One possible use case would be as a hack to get around certain 
>> shortcomings of properties for the time being.
>>
>> So does anyone have such a thing that they want to share?
>> Otherwise this is something I might do.
> 
> I think you should take a look at the code posted by Reiner the other 
> day in digitalmars.D under the subject "Proxy objects and 
> controlling/monitoring access".  The thread starts with the message 
> Xref: digitalmars.com digitalmars.D:57028
> 
> --bb

Looks interesting.  Thanks.


More information about the Digitalmars-d-learn mailing list