Re: template deduction

2010-08-23 Thread Mafi
Am 22.08.2010 21:45, schrieb bearophile: (...) import std.stdio: writeln; import std.typecons: Tuple, tuple; import std.traits: ReturnType, ParameterTypeTuple; struct Memoize(alias F) { ReturnType!F opCall(ParameterTypeTuple!F args) { alias ReturnType!F ResultType; static

template deduction

2010-08-22 Thread Mafi
Hey, I've written some caching template which should cache the return values. It looks like this: // template cached(F : R function(P), R, P...) { R cached(P p) { static R[Tuple!(P)] cache = []; R* pointer = Tuple!(P)(p) in cache; if(pointer !is null) {

Re: template deduction

2010-08-22 Thread bearophile
Mafi: I am not able to instatiate ths template in any way. You are doing it wrong. Such template tricks are not easy to get right, so probably the best thing you may do is to start from an empty program that works, and then keep adding to it, and keep it working, until you reach something

Re: template deduction

2010-08-22 Thread bearophile
but it's not nice, maybe you can improve it, I have had to use a delegate because I have found a forward reference problem (I am not sure if it's worth for Bugzilla): This was one problem, but maybe there are other ones: struct Foo(alias f) {} Foo!main baz; void main() {} I have added it