delegate opCall?
H. S. Teoh
hsteoh at quickfur.ath.cx
Thu Oct 11 17:40:33 PDT 2012
>From what I understand from TDPL, given a struct or object obj, writing
obj(x,y,z) will be translated to obj.opCall(x,y,z), correct? So why is
it that this doesn't work:
struct S {
RetVal delegate(Args args) opCall;
}
void main() {
auto s = S((Args args) => doSomething(args));
Args my_args;
RetVal r = s(my_args); // this is line 7
}
I get this error: test.d(7): Error: struct S does not overload ()
An easy workaround is to rename the delegate "impl", then implement
opCall as a wrapper:
RetVal opCall(Args args) { return impl.args; }
But this seems unnecessarily verbose to me.
T
--
What's a "hot crossed bun"? An angry rabbit.
More information about the Digitalmars-d
mailing list