Thread overview
Dynamic length string array at compile time?
Jun 05, 2023
Dany12L
Jun 06, 2023
Dany12L
Jun 16, 2023
Mark Fisher
June 05, 2023

Hi, I'd be interested to know if it's possible to have a dynamic length array containing strings generated at compile time.

June 06, 2023

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.

-Steve

June 06, 2023

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.

-Steve

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.

I would like to know if it is possible to do something similar

June 06, 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:

immutable string[] strs = mod1.makeStrings() ~ mod2.makeStrings() ~ ...;

In a centralized place.

-Steve

June 16, 2023

On Wednesday, 7 June 2023 at 00:18:54 UTC, Steven Schveighoffer wrote:

>

So for instance, you can do:

immutable string[] strs = mod1.makeStrings() ~ mod2.makeStrings() ~ ...;

In a centralized place.

-Steve

Hi,
So what if I wanted to build the strings within my library but have the client append their own data, for example if I want to have declarative extensions? Could this be done by using a mixin template to create the strings in the client?

June 15, 2023

On 6/15/23 9:59 PM, Mark Fisher wrote:

>

Hi,
So what if I wanted to build the strings within my library but have the client append their own data, for example if I want to have declarative extensions? Could this be done by using a mixin template to create the strings in the client?

Well, as long as it's not compile time, but runtime, you can definitely do it. Just use shared static constructors.

As far as I know, there's no way to have the compiler build a compile-time list of all compiled modules to be used to build such a thing. You might be able to do it as a pre-build step.

One thing you could do is have a convention where some "master" module that knows all of the important modules to includes passes it to some mixin to instantiate.

-Steve