Memoizing a templated function
ixid
nuaccount at gmail.com
Mon Apr 16 17:24:19 PDT 2012
Memoizing a templated version of a function doesn't seem to work,
how would I do it properly? For example:
int test(int n)
{
return //Do memoizable stuff
}
T test2(T)(T n)
{
return //Do memoizable stuff
}
void main()
{
n = memoize!test(n); //is fine
n = test2(n); //is fine
n = memoize!test2(n); //gives errors
}
Error 1 Error: template instance ReturnType!(test)
ReturnType!(test) does not match template declaration
ReturnType(func...) if (func.length == 1 &&
isCallable!(func)) z:\Dlang\dmd2\src\phobos\std\functional.d 693
Error 2 Error: ReturnType!(test) is used as a
type z:\Dlang\dmd2\src\phobos\std\functional.d 693
Error 3 Error: template instance ParameterTypeTuple!(test)
ParameterTypeTuple!(test) does not match template declaration
ParameterTypeTuple(func...) if (func.length == 1 &&
isCallable!(func)) z:\Dlang\dmd2\src\phobos\std\functional.d 694
Error 4 Error: ParameterTypeTuple!(test) is used as a
type z:\Dlang\dmd2\src\phobos\std\functional.d 693
Error 5 Error: index is not a type or an
expression z:\Dlang\dmd2\src\phobos\std\functional.d 695
Error 6 Error: template std.typecons.tuple does not match any
function template
declaration z:\Dlang\dmd2\src\phobos\std\functional.d 696
Error 7 Error: template std.typecons.tuple(T...) cannot deduce
template function from argument types
!()(_error_) z:\Dlang\dmd2\src\phobos\std\typecons.d 687
Error 8 Error: template main.test does not match any function
template
declaration z:\Dlang\dmd2\src\phobos\std\functional.d 703
Error 9 Error: template main.test(T) cannot deduce template
function from argument types !()(_error_) C:\Documents and
Settings\Adam.LAPPY\My Documents\Visual Studio
2008\Projects\d\test2\test2\main.d 5
Error 10 Error: template instance std.functional.memoize!(test)
error instantiating C:\Documents and Settings\Adam.LAPPY\My
Documents\Visual Studio 2008\Projects\d\test2\test2\main.d 12
Error 11 Error: forward reference to memoize C:\Documents and
Settings\Adam.LAPPY\My Documents\Visual Studio
2008\Projects\d\test2\test2\main.d 12
More information about the Digitalmars-d-learn
mailing list