Is it possible to add items to the arrays and hashes at compile time?

Dennis Ritchie via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jun 7 05:56:19 PDT 2015


On Sunday, 7 June 2015 at 12:42:12 UTC, Nicholas Wilson wrote:
> On Sunday, 7 June 2015 at 12:30:12 UTC, Dennis Ritchie wrote:
> try using a pure function + static e.g.
>
>  int[][int][int] somePureDefaultHash() pure
> {
>     ... //initialise it here
> }
>
> ...
> static hash = somePureDefaultHash();

static int[][int][int] hash;

hash[4][6] ~= [34, 65];
static if (!!(4 in hash)) {}
// Error: static variable hash cannot be read at compile time


More information about the Digitalmars-d-learn mailing list