Optimizing compilers seek try to push as much of the computation as possible at compile time.
C++20: consteval and constexpr Functions
by Daniel Lemire
From the article:
In modern C++, you can declare a function as ‘constexpr’, meaning that you state explicitly that the function may be executed at compile time.
The constexpr qualifier is not magical. There may not be any practical difference in practice between an inline function and a constexpr function, as in this example:
inline int f(int x) { return x+1; } constexpr int fc(int x) { return x+1; }
Add a Comment
Comments are closed.