template deduction

Mafi mafi at example.org
Sun Aug 22 11:21:08 PDT 2010


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) {
             return *pointer;
         } else {
             cache[Tuple!(P)(p)] = F(p);
             return cache[Tuple!(P)(p)];
         }
     }
}
//////
I am not able to instatiate ths template in any way. In my opinion there 
is enough information so that I can my template like this:
//////
alias cached!(&func) cfunc;
//////
But this doesn't work. It doesn't work the verbose way either. I've 
attached the whole test code so you can see if the error is somewhere else.
Thanks for reading!

Mafi

PS: I used the verbose variant of template declaration because my old 
template signature didn't work with the short form.

PPS: I'm usinng D2
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: caching.d
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20100822/b414f010/attachment.ksh>


More information about the Digitalmars-d-learn mailing list