Re: Templates vs CTFE

2011-01-07 Thread Steven Schveighoffer
On Thu, 06 Jan 2011 12:49:19 -0500, Max Samukha wrote: Some of us who have the knack of writing metaprograms in D know that many algorithms can be implemented with both recursive templates and CTFE. A simple example is map: Recursive template instantiation: template staticMap(alias pred

Re: Templates vs CTFE

2011-01-07 Thread Max Samukha
On 01/07/2011 03:12 PM, Don wrote: Max Samukha wrote: On 01/06/2011 09:28 PM, Robert Clipsham wrote: Put each of those implementations in its own file, then call it several times. Look at the binary size for each implementation, also run `strings ctfeTest` if you're on a *nix. This should give

Re: Templates vs CTFE

2011-01-07 Thread Don
Max Samukha wrote: On 01/06/2011 09:28 PM, Robert Clipsham wrote: Put each of those implementations in its own file, then call it several times. Look at the binary size for each implementation, also run `strings ctfeTest` if you're on a *nix. This should give you your answer :) The problem

Re: Templates vs CTFE

2011-01-07 Thread Max Samukha
On 01/06/2011 09:28 PM, Robert Clipsham wrote: Put each of those implementations in its own file, then call it several times. Look at the binary size for each implementation, also run `strings ctfeTest` if you're on a *nix. This should give you your answer :) The problem is they are not easy

Re: Templates vs CTFE

2011-01-07 Thread so
Actually they are not that related, you may solve a problem with each of them but this is different. What makes CTFE awesome is that you use same function for runtime and compile-time, without a single change. The answer to your question is just in this very definition i believe. It is not ea

Re: Templates vs CTFE

2011-01-06 Thread Robert Clipsham
On 06/01/11 17:49, Max Samukha wrote: Some of us who have the knack of writing metaprograms in D know that many algorithms can be implemented with both recursive templates and CTFE. A simple example is map: Recursive template instantiation: template staticMap(alias pred, A...) { static if (A.le

Re: Templates vs CTFE

2011-01-06 Thread Jonathan M Davis
On Thursday, January 06, 2011 09:49:19 Max Samukha wrote: > Some of us who have the knack of writing metaprograms in D know that > many algorithms can be implemented with both recursive templates and > CTFE. A simple example is map: > > Recursive template instantiation: > > template staticMap(ali

Re: Templates vs CTFE

2011-01-06 Thread Robert Jacques
On Thu, 06 Jan 2011 12:49:19 -0500, Max Samukha wrote: Some of us who have the knack of writing metaprograms in D know that many algorithms can be implemented with both recursive templates and CTFE. A simple example is map: Recursive template instantiation: template staticMap(alias pred

Re: Templates vs CTFE

2011-01-06 Thread Max Samukha
On 01/06/2011 07:49 PM, Max Samukha wrote: template staticMap(alias pred, A...) { static if (A.length) alias TypeTuple!(pred!(A[0]), staticMap!(A[1..$])) staticMap; } Should be: template staticMap(alias pred, A...) { static if (A.length) alias TypeTuple!(pred!(A[0]), staticMap!(A[

Templates vs CTFE

2011-01-06 Thread Max Samukha
Some of us who have the knack of writing metaprograms in D know that many algorithms can be implemented with both recursive templates and CTFE. A simple example is map: Recursive template instantiation: template staticMap(alias pred, A...) { static if (A.length) alias TypeTuple!(pr