Compile-time function execution

The Metacode extension to C++ (Vandevoorde 2003)[1] was an early experimental system to allow compile-time function evaluation (CTFE) and code injection as an improved syntax for C++ template metaprogramming.

[2] C++14 relaxes the constraints on constexpr – allowing local declarations and use of conditionals and loops (the general restriction that all data required for the execution be available at compile-time remains).

Since function Factorial is marked consteval, it is guaranteed to invoke at compile-time without being forced in another manifestly constant-evaluated context.

Hence, the usage of immediate functions offers wide uses in metaprogramming, and compile-time checking (used in C++20 text formatting library).

[4] CTFE can be used to populate data structures at compile-time in a simple way (D version 2): CTFE can be used to generate strings which are then parsed and compiled as D code in D. Here's an example of compile-time function evaluation in the Zig programming language:[5] This example specifies a valid Zig function called "factorial" which would typically be evaluated at run time.