some template questions
Jarrett Billingsley
kb3ctd2 at yahoo.com
Sat May 20 18:18:39 PDT 2006
"BCS" <BCS_member at pathlink.com> wrote in message
news:e4oca5$8pj$1 at digitaldaemon.com...
> This is supposed to make a list of all numbers from 0 to i, can it be made
> to
> work, and if so how?
>
> template list(int i)
> {
> static if(i==0)
> int[] list = [0];
> else
> int[] list = list!(i-1) ~ i;
> }
This seems to be a problem in D. I say this because Don Clugston, who knows
more about templates than anyone I've ever met, does the following:
http://svn.dsource.org/projects/ddl/trunk/meta/generatetable.d
http://svn.dsource.org/projects/ddl/trunk/meta/hack/hackgenerate.d
He just uses a templated "generator" function instead of a fixed function to
create the array, but the point is that you'll notice he uses that hack,
which generates the array by brute force - by just creating the elements
statically!
More information about the Digitalmars-d-learn
mailing list