On 2009-07-24 17:40:37 -0400, Walter Bright <[email protected]> said:

It's just that D is complex enough - there needs to be some very good reasons for adding more syntax that has apparently zero semantic information that would be different from the usual function syntax.

You know. I agree with you on that point. Earlier, in a thread no one replied to [1], demonstrated that we already have almost everyting we need to create properties using mixins. Here's an example:

        struct Z
        {
                int valueSquare;

                template Property()
                {
                        int value;

                        void opAssign(int v) { value = v; valueSquare = value * 
value; }
                        void opAddAssign(int v) { value = v; valueSquare = 
value * value; }
                        int get() { return value; }

                        alias get this;
                }

                mixin Property property;
        }

The only really missing part is that "alias get this" doesn't work ("Error: expression has no value" when fetching a value from z.property) so you have to explicitly call the "get" function.

[1]: http://www.digitalmars.com/d/archives/digitalmars/D/properties_using_template_mixins_and_alias_this_87952.html

--


Michel Fortin
[email protected]
http://michelf.com/

Reply via email to