I’m unable to figure out how to use the memoize function inside a class.
import std.functional;
class A {
int slowFunc(int a, int b) {
return 0;
}
alias memoize!slowFunc fastFunc;
}
void main() {
auto a = new A;
a.fastFunc(1,2);
}
This gives an error when trying to compile: Error: need ‘this’ to access member slowFunc
How would I go about making this work?
It doesn’t actually support this yet. We could file an enhancement request. Here’s my experimental implementation:
The timing comments are for my machine of course. 🙂