On 6/19/2022 11:55 AM, Paul Backus wrote:
On Sunday, 19 June 2022 at 15:34:48 UTC, Ruby The Roobster wrote:
On 6/19/2022 11:19 AM, Paul Backus wrote:
On Sunday, 19 June 2022 at 14:51:26 UTC, Ruby The Roobster wrote:
Is it possible to make a module constructor run at compile-time?  If so, how?

No, it's not.

What are you trying to accomplish that lead you to ask this question? There is probably a different way to do it without involving module constructors.

What I was trying to accomplish was to change a compile time array whenever a certain module was included.  The value of the array needs to be known at compile time.

You can do this with a `static if` check:

     static if (__traits(compiles, { import mymodule; }))
     {
         // mymodule is included
         enum compileTimeArray = ...;
     }

Curious - how exactly does this determine if the module is included? I thought __traits(compiles, ...) only checks if an expression is SEMANTICALLY correct.

Reply via email to