compile time compression for associatve array literal

Brian Tiffin btiffin at gnu.org
Mon Aug 23 06:14:14 UTC 2021


 From ~~a~~ little reading, it seems associative array literal 
initialization is still pending for global scope, but allowed in 
a module constructor?  *If I understood the skimming surface 
reading so far*.

```d
immutable string[string] things;
static (this) {
    things = ["key1": "value 1", "key2": "value 2"];
}
```

Is there a magic incantation that could convert the values to a 
`std.zlib.compress`ed ubyte array, at compile time?  So the 
object code gets keys:compvals instead of the full string value?  
Can't use `auto` for the AA, I don't think, as the initial data 
is separated from the declaration. I'm not sure about

a) if code in a module constructor is even a candidate for CTFE?
b) what a cast might look like to get a `q"DELIM ... DELIM"` 
delimited string for use as input to std.zlib.compress?
and I guess c), is the value field of an associative array a 
candidate for CTFE?

The plan is embedding a bunch of source code fragments, and a 
couple of them will be complete programs of a few pages.  
Wondering if it could be compressed at compile time, during an 
associative array init?

Cheers


More information about the Digitalmars-d-learn mailing list