Modern compiled languages allow for many operations and expressions to be done safely at compile-time. A big benefit of this is moving (possibly expensive) operations out of runtime.

These techniques are time-honoured traditions in programming (think pre-rendered graphics in video games). The difference is that previously, this was restricted to hard-coding values computed by hand (confusing!). Now, we can compute them in a more readable way.

In C/C++

Modern C++ also introduces several new key-words:

  • constexpr (since C23/C++11)
  • consteval (since C++20) is a function qualifier that forces all calls of the function to occur only at compile-time.