Match properties as member variables

comco void.unsigned at gmail.com
Sun Dec 15 14:48:38 PST 2013


On Friday, 13 December 2013 at 12:01:28 UTC, comco wrote:
> From client perspective, properties look like member variables.
> With (auto) ref, a generic function can catch a member variable 
> and read it and update it:
>
> void swap(T)(ref T a, ref T b) {...}
>
> The client can use swap with member variables.
> But he can't use this swap with class properties - they're 
> special.
>
> Since the properties "look like" member variables, I think it 
> is a valid use-case for us to want to be able to write generic 
> code that can handle properties passed as arguments in the same 
> way as member variables passed as arguments.
>
> Can you write version of swap, which works also with properties 
> and/or combination of properties and references?

No comments; I've found the same question asked about C#.
http://stackoverflow.com/questions/2182455/why-c-sharp-does-not-provide-internal-helper-for-passing-property-as-reference

So, I hope this will make more people understand what is it all 
about.


More information about the Digitalmars-d-learn mailing list