Property discussion wrap-up
Zach the Mystic
reachBUTMINUSTHISzach at gOOGLYmail.com
Tue Jan 29 12:14:26 PST 2013
On Tuesday, 29 January 2013 at 17:47:44 UTC, Rob T wrote:
> The struct property concept is perhaps more profound than the
> function-only approach because it can be used for much more
> than what was originally intended, For example, any normal
> variable can be redefined into a property, allowing you to add
> additional state to it, and additional intelligence.
> Effectively, you are able to create "smart" variables and use
> them in a generalized way.
There is even more then one way to do it, and your new struct
need not carry any data of its own:
struct Steve
{
int _n;
bool nHasBeenSet;
n struct
{
int opGet() { return _n; }
int opAssign( int newN ) {
_n = newN;
nHasBeenSet = true;
return _n;
}
}
}
The extra data is outside the struct's property definition. I
assume this would be the normal way to do it. Structs have
incredible semantics, and they're already in the language. In my
opinion, their use as a namespace is under-appreciated.
> The property as a function approach, is not very profound, and
> the need for them is not very compelling, especially
> considering how much effort is being spend on this topic. The
> struct approach however is much more interesting and has much
> more potential use.
>
> --rt
Thank you for saying that, Rob T.
More information about the Digitalmars-d
mailing list