How to dispatch a class function for an object accessed by handle?
Adam D. Ruppe
destructionator at gmail.com
Fri Mar 6 13:47:45 UTC 2020
On Friday, 6 March 2020 at 11:51:54 UTC, wjoe wrote:
> I don't understand this error message. Which type can't be
> resolved?
I.... don't know. It works if you rename the inner one but it
doesn't like eponymous templates like this. I suspect either the
spec subtly doesn't allow it or a compiler bug. I think the type
it is referring to is the `this` type.
You can work around with an alias:
// test rig
import std.stdio;
struct A {
template opDispatch(string name) {
auto opDispatch(T, Args...)(Args args) {
writeln(name, ".", T.stringof, "(", args, ")");
}
}
}
// workaround
void main() {
A a;
alias helper = a.opDispatch!("foo");
a.helper!(int)(5, "omg");
}
So the helper does one level, then the next level is done on the
next line to avoid the stupid "multiple ! not allowed". You need
to specify the `a` again to avoid `need this for...` due to how
aliases are kinda weird.
Huge hassle to use but if just doing it temporarily to debug it
can be livable.
> Is there a way to look at output of what the compiler generates
> for f.whatever!SomeResource(...); ?
-vcg-ast or something like to dmd but i never use it since
there's TONS of spam in a file called `yourfile.d.cg`
More information about the Digitalmars-d-learn
mailing list