[Issue 20302] New: std.functional.memoize doesn't accept a functions with const/immutable parameters

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Oct 15 13:07:11 UTC 2019


https://issues.dlang.org/show_bug.cgi?id=20302

          Issue ID: 20302
           Summary: std.functional.memoize doesn't accept a functions with
                    const/immutable parameters
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: petar.p.kirov at gmail.com

void main()
{
    import std.functional : memoize;
    alias mfun = memoize!fun;
    mfun("asd", 3);
}

const(string) fun(const immutable(char)* ptr, const size_t len)
{
    return ptr[0..len] ~ "123";
}

Fails to compile with:
/dlang/dmd/linux/bin64/../../src/phobos/std/functional.d(1137): Error: cannot
modify const expression memo[t]
onlineapp.d(39): Error: template instance `std.functional.memoize!(fun)` error
instantiating

--


More information about the Digitalmars-d-bugs mailing list