Restrict Class Properties?

Jarrett Billingsley kb3ctd2 at yahoo.com
Thu Feb 22 14:50:15 PST 2007


"Manfred Nowak" <svv1999 at hotmail.com> wrote in message 
news:erkjin$2t1o$1 at digitalmars.com...
> Jarrett Billingsley wrote
>
> What are "templated properties"? Are you really declaring, that a
> "real" property is a "tempülated" property?

No, I mean with the current "properties" it's not possible to use template 
functions as properties, i.e.

class A
{
    void x(T)(T value)
    {
        writefln("I'm a property and I got: ", value);
    }
}

void main()
{
    A a = new A();
    a.x = 5; // error, a.x is not an lvalue
}

This is because a.x is actually a template with one function declared in it. 
When you try to assign to it, it makes no sense, since a.x is a template. 
That check happens _before_ the rewrite to a function call happens.

If, however, you had a separate property syntax:

class A
{
    property x
    {
        void opSet(T)(T value) // just guessing at the name
        {
            writefln("I'm a property and I got: ", value);
        }
    }
}

void main()
{
    A a = new A();
    a.x = 5; // works
}

D would find that a.x is a property.  Assignment to a property is 
unambiguously a call to its opSet function, and so the call would be 
rewritten as

a.x.opSet(5);

which can then cause the template to be instantiated properly.

I suppose this could also be done with the current "properties" :)  (and 
hopefully it will, because I know that there is no way in hell that any 
property syntax is ever going to make it into D)

>
> That is already possible, except you do not want to buy such.

Uhh... "buy"?  I don't know what you're trying to say, and I don't know how 
this is at all possible (unless you mean that "trick" that you posted 
involving using an extra dummy index). 





More information about the Digitalmars-d mailing list