Dynamic length string array at compile time?
Steven Schveighoffer
schveiguy at gmail.com
Wed Jun 7 00:18:54 UTC 2023
On 6/6/23 4:38 PM, Dany12L wrote:
> On Tuesday, 6 June 2023 at 14:26:01 UTC, Steven Schveighoffer wrote:
>> On 6/5/23 11:45 AM, Dany12L wrote:
>>> Hi, I'd be interested to know if it's possible to have a dynamic
>>> length array containing strings generated at compile time.
>>>
>>>
>>
>> Sure. Just do it. Probably the reason nobody answered the question yet
>> is that it trivially works if you try it :) Unless you did try it and
>> it didn't work? In that case, post your code, I'm sure we can fix it.
>>
>
> My concern would be to create an immutable array (or other "equivalent")
> of strings by adding elements to the array at compile time from
> different modules.
OK, so you want to affect the same static variable from multiple places?
No, that can't happen that way. You can do it in a functional
programming fashion, but there can only be one initialization, you can't
edit the thing afterwards.
So for instance, you can do:
```d
immutable string[] strs = mod1.makeStrings() ~ mod2.makeStrings() ~ ...;
```
In a centralized place.
-Steve
More information about the Digitalmars-d-learn
mailing list