How to initialize a associative array?

Era Scarecrow via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Dec 24 21:45:14 PST 2016


On Saturday, 24 December 2016 at 11:21:11 UTC, Stefan Koch wrote:
> On Saturday, 24 December 2016 at 00:55:01 UTC, Yuxuan Shui 
> wrote:
>> What's the correct way?
>
> You cannot initialize an AA at compile-time.
> Because AA's are provided by druntime and the ABI is not stable.

  For fun I'm throwing together a quick AA struct that you can 
make at compile time. It's experimental and may be slow for 
compiling as it needs to find a size of numbers where the hashes 
don't overlap. Of course you can't add to it, you can't delete 
elements (key limitations) but you could in theory change the 
value; So this would be better for immutable objects or having a 
fixed number of pre-known keys.

  If anyone is interested I can share my sources fairly soon once 
I'm satisfied the required features are done. So far opIndex and 
generation works fine, but range/foreach over it is incomplete.


More information about the Digitalmars-d-learn mailing list