On Saturday, 18 July 2015 at 16:18:30 UTC, Clayton wrote:
Thanks , you were right . It seems there are some key words
though which one has to use so that the code gets executed on
compile-time .For example I had to change the second forloop to
a foreach loop,
`for` loops work just fine in CTFE. `foreach` is usually nicer,
though (regardless of CTFE or not).
and then put and enum to ensure that TableFromCompiler gets
evaluated at compiletime. Having written the code this way
though gives rise to some other question, D supports 2
approches to compiletime metaprogramming i.e. CTFE and
Templates, it seems am not very sure which paradigm my code
falls in.
Your computeAtCompileTime is a template that results in a
function when instantiated. You're calling such a generated
function and you're assigning the result to an enum, which makes
it a CTFE call.
So there's both CTFE and a template in your code.
You could probably do the whole pre-computation without CTFE,
using only templates. But (here) CTFE is more straight forward as
you can just write normal run time D.