May 16, 2023

Hi,

I just run into this problem again:

https://stackoverflow.com/questions/26861708/what-is-the-syntax-for-declaring-a-constant-stringchar-aa

So, the solution still is to use:

static this () {
  ...
}

What happened to this comments:
"""
It should be noted that this restriction will eventually go away, once there is a solid library implementation of associative arrays. There is currently work in progress to this effect, which seems to be nearing completion. –
Meta Nov 14, 2014 at 17:41
"""

Still not there yet, after ~10 years?

May 17, 2023

On 5/16/23 7:17 PM, mw wrote:

>

Hi,

I just run into this problem again:

https://stackoverflow.com/questions/26861708/what-is-the-syntax-for-declaring-a-constant-stringchar-aa

So, the solution still is to use:

static this () {
   ...
}

What happened to this comments:
"""
It should be noted that this restriction will eventually go away, once there is a solid library implementation of associative arrays. There is currently work in progress to this effect, which seems to be nearing completion. –
Meta  Nov 14, 2014 at 17:41
"""

Still not there yet, after ~10 years?

Yep.

I have a library solution: https://code.dlang.org/packages/newaa

You can declare a Hash!(char, string) in module space, and then use it as an AA later.

However, it needs to not be const. The Hash type does not set itself up as an AA doppelganger until you call asAA on it, which means it needs to set up some internal things, and therefore needs to be mutable. I think I can make a method that does this, so you can use const Hash!(char, string) = [ ... ], but it still can't change the type to an actual AA (the compiler won't let that work).

Wow, over a year since I did anything on it. Probably should tinker a bit more.

-Steve