@property - take it behind the woodshed and shoot it?
Jacob Carlborg
doob at me.com
Thu Jan 24 05:56:02 PST 2013
On 2013-01-24 14:41, deadalnix wrote:
> 3. @getter is an attribute. A function marked @getter is automatically
> executed : () is added automatically :
> @getter void funName() {}
> funName; // function get executed.
> funName(); // Error, void is not callable.
>
> 4. @getter can be used as UFCS.
> @getter void funName(T t) {}
> T t; t.funName; // function gets executed.
> funName(t); // Error, funName require 1 argument, 0 given.
>
> 5. @setter is an attribute. A setter method can *only* be used in rhs of
> an expression. The assigned value is used as argument.
> @setter void funName(T t) {}
> T t; funName = t; // function gets executed.
> funName(t); // Error, funName must be used in an assign expression.
>
> 6. @setter can as well be used as UFCS :
> @getter void funName(T t, U u) {}
> T t; U u; t.funName = u; // function gets executed.
> t.funName(u); // Error, funName must be used in an assign expression.
What about @property(getter) and @property(setter) instead? Otherwise we
need two new built-in attributes.
> 8. method behave as functions :
> class A { void foo() {} }
> A a;
> static assert(is(typeof(a.foo) : void delegate())); // Pass.
> &a.foo; // deprecated NOOP for compatibility.
> a.foo(); // call a.foo
The address operator wouldn't be needed to get a delegate for a method
anymore?
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list