digitalmars.D.learn - Conditional compilation inside an array initializer
- Johan Engelen (17/17) Jan 18 2016 Is it possible to do conditional compilation inside an array
- Adam D. Ruppe (9/11) Jan 18 2016 No, but you might break it up:
- =?UTF-8?Q?Ali_=c3=87ehreli?= (20/30) Jan 18 2016 I was writing something similar:
Is it possible to do conditional compilation inside an array initializer? Something like this: int[] inttable = [ 1, 4, version(smth) { // <--- does not compile 5, 6, } 8, 1345 ]; (real world case: https://github.com/ldc-developers/ldc/blob/merge-2.069/ddmd/idgen.d#L279) If it is not possible, what alternative solution would you use? Thanks!
Jan 18 2016
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;
Jan 18 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: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); } AliIs 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;
Jan 18 2016