digitalmars.D.learn - lvalue forwarding struct?
- Chad J (22/22) Aug 21 2007 What I am looking for is a templated struct that simply wraps a
- Bill Baxter (7/36) Aug 21 2007 I think you should take a look at the code posted by Reiner the other
- Chad J (2/42) Aug 21 2007 Looks interesting. Thanks.
- Henning Hasemann (5/6) Aug 21 2007 http://www.digitalmars.com/d/archives/digitalmars/D/Problem_with_Point_p...
- Chad J (2/7) Aug 21 2007 As Chris said, rather slick. Thanks.
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.
Aug 21 2007
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
Aug 21 2007
Bill Baxter wrote:Chad J wrote:Looks interesting. Thanks.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
Aug 21 2007
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
Aug 21 2007