DIP23 draft: Fixing properties redux

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun Feb 3 11:52:02 PST 2013


On 2/3/13 11:28 AM, Steven Schveighoffer wrote:
> This sounds good. It might be a bit confusing, but nice in the fact that
> &(a.b) always means address of whatever b returns, whether it is a field
> or property.

Yah, this is a good rule of thumb for generic code.

Note that there's a subtlety in the expression "&expr.name". This is not 
precedence, just use of punctuation to express a unit. Attempting to 
decompose it by inserting parens yields different things altogether: 
&(expr.name) and (&expr).name are not mere redirections of precedence.

>> @property int foo(); // error
>> @property int goo(int); // fine, assume a getter for int
>
> I think this is a possible solution, and I can live with that, I'm
> fairly certain that some people use global properties currently, so they
> will not be too happy.

Yah, let's see how this restriction pans out.

>> No. Templated member variables are not allowed either.
>
> Wait, what? I don't like this idea. Why should this not be allowed:
>
> @property void x(T)(T t) {_x = to!(typeof(_x))(t);}

Yah, I misspoke. Properties can be templated subject to the other 
restrictions.

Andrei


More information about the Digitalmars-d mailing list