CTFE in imported static initializers

Steven Schveighoffer schveiguy at gmail.com
Tue May 14 11:14:04 UTC 2019


On 5/13/19 9:39 PM, Steven Schveighoffer wrote:
> I have just discovered an interesting behavior, and I'm wondering if 
> this behavior is intentional or even necessary.
> 
> Let's say I have this module called mod2.d:
> 
> module mod2;
> 
> string buildModData()
> {
>      string result;
>      foreach(i; 0 .. 10000)
>          result = result ~ "lots and lots and lots of data";
>      return result;
> }
> 
> static moddata = buildModData();

A workaround found by Jonathan Davis:

string moddata() {
    static result = buildModData();
    return result;
}

-Steve


More information about the Digitalmars-d-learn mailing list