Recursive template problem

Lars Kyllingstad public at kyllingen.NOSPAMnet
Wed Jul 30 03:06:34 PDT 2008


maelp wrote:
> I think what he looks for is not the actual result since his array of reals isn't const (not known at compile time), and he simply wants the actual *code* to be generated at compile time, so none of your solution will work. I've had similar problems of recursive template construction, so since there are several posts, maybe we'll have some answers.

That's right. I am using D for numerical computations, so fast-executing 
code is essential. Therefore, I want to use static arrays whenever 
possible, and instead of having to write

   foreach (real r; v) sum += r;

or similar, i would like expressions such as

   sum = v[0] + v[1] + ...

to be created at compile time for arrays of any given length. I was 
kinda hoping templates could provide a solution...

-Lars



More information about the Digitalmars-d mailing list