Is it possible to add items to the arrays and hashes at compile time?
Nicholas Wilson via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Jun 7 05:42:10 PDT 2015
On Sunday, 7 June 2015 at 12:30:12 UTC, Dennis Ritchie wrote:
> Does D the ability to add items to arrays and hashes at compile
> time?
>
> For example, how do I do it in compile time?:
>
> int[][int][int] hash;
>
> hash[4][6] ~= [34, 65];
> hash[5][7] ~= [4, 78, 21];
try using a pure function + static e.g.
int[][int][int] somePureDefaultHash() pure
{
... //initialise it here
}
...
static hash = somePureDefaultHash();
More information about the Digitalmars-d-learn
mailing list