Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
August 21, 2007 lvalue forwarding struct? | ||||
---|---|---|---|---|
| ||||
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. */ } 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. |
August 21, 2007 Re: lvalue forwarding struct? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chad J | 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 |
August 21, 2007 Re: lvalue forwarding struct? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bill Baxter | 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.
|
August 21, 2007 Re: lvalue forwarding struct? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chad J | > So does anyone have such a thing that they want to share? http://www.digitalmars.com/d/archives/digitalmars/D/Problem_with_Point_property_49990.html#N50017 -- GPG Public Key: http://keyserver.ganneff.de:11371/pks/lookup?op=get&search=0xDDD6D36D41911851 Fingerprint: 344F 4072 F038 BB9E B35D E6AB DDD6 D36D 4191 1851 |
August 22, 2007 Re: lvalue forwarding struct? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Henning Hasemann | Henning Hasemann wrote:
>> So does anyone have such a thing that they want to share?
>
> http://www.digitalmars.com/d/archives/digitalmars/D/Problem_with_Point_property_49990.html#N50017
>
>
As Chris said, rather slick. Thanks.
|
Copyright © 1999-2021 by the D Language Foundation