August 27, 2016
On 08/27/2016 07:35 PM, cy wrote:
> When I saw `auto a = b;` at the module level, I thought that b had to be
> something you could evaluate at compile time.

That's right.

> But I guess it can be a
> runtime calculated value, acting like it was assigned in a a static
> this() clause,

No, that's not right. The initializer for a module level variable has to be a compile-time constant.

If the initializer is a function call, the compiler attempts to evaluate it at compile time. We have an acronym for that: CTFE = Compile Time Function Evaluation. `regex("foobar")` can be evaluated that way, so it can be used as an initializer for a module level variable.
1 2
Next ›   Last »