Heterogeneous CT array like structure

Engine Machine via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Aug 16 08:40:19 PDT 2016


struct Storage
{	
   // Getter
   static auto ref opDispatch(string name)()
   {

   }

   // Setter
   static auto ref opDispatch(string name, T)(T val)
   {
   }
}

auto y = Storage.Data;
Storage.Data = "x";
Storage.Foo = 3;

How can I actually store this data for runtime use that doesn't 
require the GC?

The indexing set is fixed at compile time. In fact, it could come 
from an enum(my first thought). The values for each index can 
have a different type, though, and I'd like them to be the proper 
types(no casting or variant).

Is there a simple way to add to Storage at compile time?

e.g., add

static string Data = "x";
static int Foo = 3;

The assignments are for default values, they will only occur once 
in program execution, what is important is the getter, which will 
create the data if it doesn't exist and set it to some default 
value initially if it needs to.



















More information about the Digitalmars-d-learn mailing list