Filling an array at compile time
acehreli at yahoo.com
Wed Feb 9 16:37:22 UTC 2022
On 2/9/22 01:07, bauss wrote:
> It will not run at compile-time because csvText is a runtime variable.
> It should be enum to be accessible at compile-time.
Yes. For the sake of completeness, any expression needed at compile time
will be (attempted to be) executed at compile time. For example, an
expression used as a template parameter will be executed at compile time
> The append operation
> will be executed at runtime, which means that even if the loop runs at
> compile-time then you're effectively not winning anything and it
> basically just becomes a loop-unroll manually done.
That's not true. It all depends on how the expression is needed. If for
example, the variable were defined as enum, the compiler had to execute
the code at compile time to compute its value.
> The solution would be to create a function that returns a string [...]
> And then simply using mixin
That is unnecessary and hurts readability. :/ Most programmers see
string mixins as a last resort.
In any case, some people may find a compile-time file parsing example
that I included in a presentation:
More information about the Digitalmars-d-learn