Property discussion wrap-up
Jonathan M Davis
jmdavisProg at gmx.com
Fri Feb 1 07:13:55 PST 2013
On Friday, February 01, 2013 16:03:41 TommiT wrote:
> 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.
And why is that a problem? If you expect s.pop += 3 to work, how could you not
expect + to work on the type of prop? You're generally doing something wrong
if your type defines += and not + anyway, so I really don't see the problem
here.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list