How to declare static compile-time assoc array inside struct?

rikki cattermole rikki at cattermole.co.nz
Mon Aug 13 11:53:06 UTC 2018


On 13/08/2018 11:38 PM, Andrey wrote:
> Hello,
> I need to declare a static compile-time assoc array inside struct:
>      struct Test
>      {
>          enum Type : ubyte
>          {
>              One,
>              Two,
>              Three
>          }
> 
>          static immutable string[Type] DESCRIPTION = [Type.One: "One!", 
> Type.Two: "It's Two...", Type.Three: "And... Three!"];
>      }
> 
> I have an error: "non-constant expression". What should I do?
> 
> I want to declare it and init at compile-time (to reduce run-time 
> overhead). After that it will be used in run-time expressions and in 
> compile-time expressions.
> 
> Regards, Andrey.

Unsupported. AA's don't go between CT and RT. You must use a module 
constructor to initialize it.


More information about the Digitalmars-d-learn mailing list