Fix Issue 12568 - std.functional.memoize does not work with constant

arrays.
This commit is contained in:
Monarch Dodra 2014-04-23 21:38:11 +02:00 committed by Andrej Mitrovic
parent aede15f059
commit 70dff45550

View file

@ -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)