Set variable at compile time

Craig Dillabaugh cdillaba at cg.scs.carleton.ca
Wed Oct 30 13:11:11 PDT 2013


Hello,

I am writing code that uses a structure containing an array of
points where the points may be of arbitrary dimension (though
generally small).  I would like to be able to pass the point
dimension to my structure as a template parameter.

One solution is to create instances of these structures for all
reasonable dimensions and then select the correct instance at run
time I suppose. However, I don't really want to set a limit on
the point dimension.

Since the actual program is quite small, and the datasets I want
to apply it to are generally going to be large, I thought it
would make sense to generate the program from source for each
'run' and simply specify the dimension at compile time.  But that
is where I am stuck.

I looked at the compiler switches
(http://dlang.org/dmd-linux.html) but if there is a compiler
switch to do this I missed it.  I suppose I could use version()
statements, but that seems like a bit of a hack.

So my question is, is there some straightforward way of doing
what I want here.

Cheers,

Craig



More information about the Digitalmars-d-learn mailing list