On Friday, 1 February 2013 at 14:49:48 UTC, TommiT wrote:
As far as I know, the obove kind of thing isn't possible with
the current state of affairs; with @property attribute, you
cannot provide the extra level of encapsulation that checks
that the sum of 'speed' and 'sneak' isn't above 5.
...and if the specification is changed so that:
struct S
{
T _prop;
@property T prop() const
{
return _prop;
}
@property void prop(T t)
{
assert(t <= 5);
_prop = t;
}
}
...
S s;
s.prop += 3;
...gets lowered to s.prop = (s.prop + 3); Then that sucks because
now T is forced to provide the binary + operator.