You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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);}
}
The text was updated successfully, but these errors were encountered:
simen.kjaras reported this on 2019-08-02T22:50:17Z
Transfered from https://issues.dlang.org/show_bug.cgi?id=20099
Description
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); } }The text was updated successfully, but these errors were encountered: