Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memoize should handle lambdas #10380

Open
dlangBugzillaToGithub opened this issue Aug 2, 2019 · 1 comment
Open

Memoize should handle lambdas #10380

dlangBugzillaToGithub opened this issue Aug 2, 2019 · 1 comment
Labels
Arch:x86 Issues specific to x86 OS:Windows Issues Specific to Windows Severity:Enhancement

Comments

@dlangBugzillaToGithub
Copy link

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);
    }
}
@dlangBugzillaToGithub
Copy link
Author

dlang-bot commented on 2020-05-29T19:25:09Z

@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

@LightBender LightBender removed the P4 label Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arch:x86 Issues specific to x86 OS:Windows Issues Specific to Windows Severity:Enhancement
Projects
None yet
Development

No branches or pull requests

2 participants