Concepts - C Template Metaprogramming

TMP is a purely sub-language. Because the compiler cannot "change" a value once it is defined during a build, you don't use loops or variables. Instead, you use: Recursion: To mimic loops.

Uses a using alias or typedef to return a new type (e.g., removing a const qualifier). 3. SFINAE (Substitution Failure Is Not An Error) C Template Metaprogramming Concepts

This is a fundamental rule used to "sift" through template overloads. If a template fails to compile during the substitution of types, the compiler doesn't crash—it simply ignores that specific overload and looks for another that works. This is the backbone of and library-level introspection. 4. Type Traits TMP is a purely sub-language

Uses static constexpr to return a result (e.g., calculating a factorial at compile time). Uses a using alias or typedef to return a new type (e

C++ (TMP) is essentially a "program within a program." It allows you to execute logic during compilation rather than at runtime, using the compiler as an interpreter to generate optimized code. 1. The Core Mechanism: Functional Programming

Concepts are the modern evolution of TMP. Instead of relying on complex SFINAE "hacks" to restrict templates, allow you to explicitly define requirements for template arguments using the requires keyword. This makes error messages much more readable and the code intent clearer. 6. Variable Templates and constexpr

Modern C++ (C++14/17/20) has shifted much of the "heavy lifting" from pure template syntax to constexpr and consteval functions. These allow you to write logic that looks like normal C++ but is guaranteed to run at compile time, significantly reducing the complexity of traditional template syntax. Why Use It?