Currently, std.functional.memoize uses std.traits.ReturnType and std.traits.Parameters to get the return type and parameters of the memoized function. This fails for stuff like memoize!(a => a.field). Suggested new implementation: template memoize(alias fun) { auto memoize(Args...)(Args args) if (is(typeof(fun(args)))) { import std.typecons : Tuple; static if (__traits(isTemplate, fun)) { import std.traits : isDelegate; static assert(!isDelegate!(fun!Args), fun.stringof~" is a delegate, and thus has context memoize can't access."); } static typeof(fun(args))[Tuple!Args] memo; auto t = Tuple!Args(args); if (auto p = t in memo) return *p; return memo[t] = fun(args); } }
@Biotronic created dlang/phobos pull request #7507 "Fix issue 20099 - Memoize should handle lambdas" fixing this issue: - Fix issue 20099 https://github.com/dlang/phobos/pull/7507
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10380 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB