On 2/4/13, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> wrote:The problem is you cannot replace a field with a @property function
> I'm unclear that's a problem.
without breaking user-code when you take into account operator
overloading. Consider:
struct S
{
S opBinary(string op : "&", S)(S s)
{
return this;
}
}
struct M
{
S s;
}
void main()
{
M m;
auto s = m.s & m.s; // ok
}
Suppose you want to turn 's' into a read-only property, so you write:
struct S
{
S opBinary(string op : "&", S)(S s)
{
return this;
}
}
struct M
{
@property S s() { return _s; }
private S _s;
}
void main()
{
M m;
auto s = m.s & m.s; // fail
}
Now the user-code fails.