On Thursday, 16 May 2013 at 07:53:08 UTC, TommiT wrote:
I'd like to make it easier to initialize function local immutable/const data. Here's the type of problem I'd like to alleviate:const string[100] int__str; const int[string] str__int; for (int i = 0; i < 100; ++i) { auto str = to!string(i); int__str[i] = str; // ERROR: Can't modify const str__int[str] = i; // ERROR: Can't modify const }In short, I want to initialize two different const variables at once (in the same loop or other block). If I needed to initialize only one const variable, I could use a lambda:const string[100] int__str = { string[100] tmp; // ... init tmp ... return tmp; }();
This is easy to work around that using a mutable data, construct it and then copy it to a const one.
You my argue that this is slower, and I answer you : maybe. Can you show what does GDC or LDC output doing so ?
