template? mixin? template mixins? for modifying a struct setup

Christopher Katko ckatko at gmail.com
Fri May 20 14:54:31 UTC 2022


On Friday, 20 May 2022 at 02:30:10 UTC, Mike Parker wrote:
> On Friday, 20 May 2022 at 00:12:44 UTC, Chris Katko wrote:
>
>> Yeah that occurred to me as I was falling asleep. Though, do I 
>> have to a specify
>>
>> ```D
>> static auto myColor = grey(0.5);
>> ```
>> to ensure it's done at compile time? It's not the end of the 
>> world, but ideally, these are static / hardcoded values that 
>> can be used thousands of times a second.
>
> If the declarations are at module scope, `static` has no 
> effect, and CTFE will be used for initialization.

So wait, that means if I have a module with extra stuff like

````D
colors.d

auto red =
// grey
````

and then in my other file
````D
auto white = grey(1.0);
````

It won't use CTFE? Why is there a local module requirement?



More information about the Digitalmars-d-learn mailing list