mirror of
https://github.com/dlang/phobos.git
synced 2025-04-29 14:40:30 +03:00
Fix Issue 12568 - std.functional.memoize does not work with constant
arrays.
This commit is contained in:
parent
aede15f059
commit
70dff45550
1 changed files with 15 additions and 5 deletions
|
@ -666,11 +666,12 @@ alias fastTransmogrify = memoize!(transmogrify, 128);
|
|||
*/
|
||||
template memoize(alias fun, uint maxSize = uint.max)
|
||||
{
|
||||
ReturnType!fun memoize(ParameterTypeTuple!fun args)
|
||||
private alias Args = ParameterTypeTuple!fun;
|
||||
ReturnType!fun memoize(Args args)
|
||||
{
|
||||
import std.typecons : Tuple, tuple;
|
||||
static ReturnType!fun[Tuple!(typeof(args))] memo;
|
||||
auto t = tuple(args);
|
||||
static ReturnType!fun[Tuple!Args] memo;
|
||||
auto t = Tuple!Args(args);
|
||||
auto p = t in memo;
|
||||
if (p) return *p;
|
||||
static if (maxSize != uint.max)
|
||||
|
@ -714,6 +715,15 @@ unittest
|
|||
return n < 2 ? 1 : n * mfact(n - 1);
|
||||
}
|
||||
assert(fact(10) == 3628800);
|
||||
|
||||
// Issue 12568
|
||||
static uint len2(const string s) { // Error
|
||||
alias mLen2 = memoize!len2;
|
||||
if (s.length == 0)
|
||||
return 0;
|
||||
else
|
||||
return 1 + mLen2(s[1 .. $]);
|
||||
}
|
||||
}
|
||||
|
||||
private struct DelegateFaker(F)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue