It does not support yet. We could request a raise. Here is my experimental implementation:
import std.stdio; import std.traits; import std.typecons; import std.datetime; template isClassStruct(alias fun) { enum bool isClassStruct = (is(fun == class) || is(fun == struct)); } mixin template memoize(alias fun, uint maxSize = uint.max) if (isClassStruct!(__traits(parent, fun))) { ReturnType!fun opCall(ParameterTypeTuple!fun args) { static ReturnType!fun[Tuple!(typeof(args))] memo; auto t = tuple(args); auto p = t in memo; if (p) return *p; static if (maxSize != uint.max) { if (memo.length >= maxSize) memo = null; } mixin("auto r = this." ~ __traits(identifier, fun) ~ "(args);"); memo[t] = r; return r; } } class A { int slowFunc(int a, int b) { int result; foreach (_; 0 .. 1024) { result += a; result += b; } return result; } mixin memoize!slowFunc fastFunc; } enum CallCount = 2048; void main() { A a = new A; auto sw1 = StopWatch(AutoStart.yes); foreach (x; 0 .. CallCount) { a.slowFunc(100, 100);
Time comments for my car, of course. :)
source share