memoize

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Jan 4 05:48:24 PST 2011


On 1/4/11 2:48 AM, %u wrote:
> Hi,
>
> I just wanted to say, it's funny how I did the *EXACT* same thing only **a few
> days ago**:
> http://stackoverflow.com/questions/245584/d-templates-coolest-hack/4437847#4437847
>
> Not counting the braces, the actual code is just 4 lines for the compile-time
> version, and 5 lines for the run-time version. The page above only has a link to
> one of these; both of the versions are here:
> http://ideone.com/q8lvf
>
> Pretty short, eh? I doubt that it can get any shorter than that code. :) Feel free
> to use my version inside the library. ("I hereby release the code to the public
> domain," to cover the legal stuff.)

Wow. I swear I didn't see this! "Great minds think alike" eh? :o)

I think your implementation that defines the function directly is 
better. However, when we plan to make the whole thing work with 
overloading, we'll probably want to go with the template solution.

BTW, right now ParameterTypeTuple catches the lexically first overload 
or something. Instantiating memoize!sqrt latches on sqrt(float). We need 
to generalize ParameterTypeTuple to work with overloaded functions. This 
is where implicit flattening of tuples is going to turn a bit troublesome.


Andrei


More information about the Digitalmars-d mailing list