Bug 20302 – std.functional.memoize doesn't accept a functions with const/immutable parameters

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-10-15T13:07:11Z
Last change time
2019-10-19T06:04:40Z
Keywords
pull
Assigned to
ZombineDev
Creator
ZombineDev

Comments

Comment #0 by petar.p.kirov — 2019-10-15T13:07:11Z
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
Comment #1 by dlang-bot — 2019-10-16T11:41:15Z
@ZombineDev created dlang/phobos pull request #7231 "Fix issues 20301 and 20302" fixing this issue: - Fix issue 20302 - Support head const in memoize Make std.functional.memoize accept functions whose return type or parameters are head const. https://github.com/dlang/phobos/pull/7231
Comment #2 by dlang-bot — 2019-10-19T06:04:40Z
dlang/phobos pull request #7231 "Fix issues 20301 and 20302" was merged into stable: - 52bf1876f7efaed360ab5daa394fa81464b7c6e2 by ZombineDev: Fix issue 20302 - Support head const in memoize Make std.functional.memoize accept functions whose return type or parameters are head const. https://github.com/dlang/phobos/pull/7231