Conditional compilation inside an array initializer
    Ali Çehreli via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Mon Jan 18 16:41:34 PST 2016
    
    
  
On 01/18/2016 04:38 PM, Adam D. Ruppe wrote:
> On Tuesday, 19 January 2016 at 00:33:21 UTC, Johan Engelen wrote:
>> Is it possible to do conditional compilation inside an array initializer?
>
> No, but you might break it up:
>
> enum inttable_1 = [1,4];
> version(smth)
>      enum inttable_middle = [5,6];
> else
>      enum inttable_middle = [];
> enum inttable_2 = [8, 1345];
>
> int[] inttable = inttable_1 ~ inttable_middle ~ inttable_2;
I was writing something similar:
int[] table;
// Alternatively, consider 'shared static this()'
static this() {
     const tens  = [ 10, 20 ];
     const hundreds = [ 100, 200 ];
     const thousands = [ 1000, 2000 ];
     table ~= tens;
     version (smth) {
     table ~= hundreds;
     }
     table ~= thousands;
}
version = smth;
void main() {
     import std.stdio;
     writeln(table);
}
Ali
    
    
More information about the Digitalmars-d-learn
mailing list