www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - compile time sequence through dub config or commandline.

reply Sjoerd Nijboer <dlang sjoerdnijboer.com> writes:
I would like to do something like
`
dmd --buildversion=fooCollection{"a", "b", "c"} -run app.d

...

void bar()
{
     static foreach(i; fooCollection)
     {
         ...
     }
}
`

The idea being that bar can be packed in a library and the 
program that includes this library can decide what parameters 
will be added to foo whitout any runtime overhead and ugly 
looking syntax.

Is something simular possible?
If not, could I achieve thesame result by including a file 
`programsettings.d` with some compile time constants in there 
whitout my library depending on it?
Dec 02 2018
parent reply Paul Backus <snarwin gmail.com> writes:
On Sunday, 2 December 2018 at 14:50:05 UTC, Sjoerd Nijboer wrote:
 The idea being that bar can be packed in a library and the 
 program that includes this library can decide what parameters 
 will be added to foo whitout any runtime overhead and ugly 
 looking syntax.
The normal way to do this would be to make bar a template and have the program that uses it pass these parameters to it as template arguments.
Dec 02 2018
parent Sjoerd Nijboer <dlang sjoerdnijboer.com> writes:
On Sunday, 2 December 2018 at 17:59:56 UTC, Paul Backus wrote:
 The normal way to do this would be to make bar a template and 
 have the program that uses it pass these parameters to it as 
 template arguments.
Why didn't I think of that? It's just initializing a library, of course! Thank you for your help and happy coding.
Dec 02 2018