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

Andrey saasecondbox at yandex.ru
Mon Aug 13 11:38:30 UTC 2018


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.


More information about the Digitalmars-d-learn mailing list