Another Properties Proposal
Chad J
gamerChad at _spamIsBad_gmail.com
Wed Aug 22 21:56:07 PDT 2007
Chad J wrote:
>
> // baz is just some function. This is on the user's side of the prop.
> T baz(T)(Bar arg)
> {
> auto ptr = &arg.foo; // foo is a property, a data field works too
> T val = *ptr; // calls foo.setFoo(typeof(foo).init);
> return val;
> }
I just realized that such a thing doesn't work at all, because nothing
would expand to the "typeof(foo).init" that is passed to the setter.
So the idea of returning a delegate from an address-of-property probably
isn't useful at all in this context.
The notion of having the thing returned from address-of-property be
something that templates could work with as if it were a data field, at
least syntactically, still might have some potential though. Even
better if it doesn't rely on implicit properties.
In an adjacent post, Chris Nicholson-Sauls suggested that properties
could be "treated internally by D as just a struct which calls the
self-named function". Perhaps if such a struct was revealed as some
kind of special internal library built in struct then it could be
returned as a property's address by default.
More information about the Digitalmars-d
mailing list