Using memberspaces for a property-like syntax and more
TommiT
tommitissari at hotmail.com
Sat Feb 2 15:02:43 PST 2013
On Saturday, 2 February 2013 at 22:18:52 UTC, Jonathan M Davis
wrote:
> On Saturday, February 02, 2013 10:14:29 TommiT wrote:
>> I propose we just forget about the whole concept of a property
>
> I think that this proves that the property discussion has
> gotten way out of hand.
I don't see that quoted sentence of mine as a proof that the
discussion has gotten out of hand. It only shows that I
personally think that memberspaces are semantically such a close
match to the concept of properties, that I don't see any reason
to think of them as different things.
BTW, given that we fix the @property attribute, would the line:
s.prop += 3;
...call:
1) s.prop( s.prop + 3 );
...or:
2) s.prop().opOpAssign!"+"(3);
...in the code snippet below:
struct T
{
private int _value;
ref T opAssign(int rhs)
{
_value = rhs;
return this;
}
ref T opOpAssign(string op)(int rhs)
if(op == "+" || op == "-")
{
mixin("_value" ~ op ~ "= rhs;");
return this;
}
T opBinary(string op)(int rhs) const
if(op == "+" || op == "-")
{
T t = this;
mixin("t._value" ~ op ~ "= rhs;");
return t;
}
}
struct S
{
private T _t;
@property ref T prop()
{
return _t;
}
@property void prop(int v)
{
_t = v;
}
}
void main()
{
S s;
s.prop += 3; // ?
}
More information about the Digitalmars-d
mailing list