Factorial macro example in C++23 metaprogramming,<p><pre><code> #include <iostream>
consteval long factorial (int n) {
if (n == 0) return 1;
return n * factorial(n - 1);
}
int main() {
std::cout << factorial(7) << std::endl;
}
</code></pre>
Exercise for the reader if using VC++ or clang/ninja, use <i>import std</i> instead.<p>-- <a href="https://godbolt.org/z/TWe11hM6j" rel="nofollow">https://godbolt.org/z/TWe11hM6j</a><p>Nicely put 5040 in ESI register at compile time.<p>Granted, C++ isn't Lisp, but already has quite a room for creativity at compile time, and C++26 might finally have compile time reflection as well.