On Sun, Jun 07, 2015 at 12:43:16PM +0000, Nicholas Wilson via Digitalmars-d-learn wrote: > 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: > >>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(); > > or enum
Using an enum for an array or hash is usually a bad idea, because it causes a runtime allocation per reference to that symbol. T -- "I suspect the best way to deal with procrastination is to put off the procrastination itself until later. I've been meaning to try this, but haven't gotten around to it yet. " -- swr