Is there any way to run loop at "compil-time"?

How to excute code at compile time

There are three variants of this:

  1. Any code inside the definition of a const or static is guaranteed to run at compile time, but it can only use const methods, and you can't e.g. read files or do web requests.
  2. Proc-macros can execute arbitrary code during compilation.
  3. A build script can also be used, which is also able to execute arbitrary code.

In the above three methods which method is best for run the iteration loop at compile time?

The iteration loop?

Means for example while loop

What does it do? Just compute a value? Which type? Does it print stuff or write to a file?

Just compute a value

If you are able to put it in a static or const, then do that.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.