C Template Metaprogramming Concepts -

In standard C++, a function takes values and returns a value. In TMP, a takes types or constants and "returns" a new type or constant.

Passing types ( int , std::vector ) into templates as if they were data. 2. Metafunctions

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 C Template Metaprogramming Concepts

Introduced heavily in , these are standard metafunctions used to query properties of types. They allow your code to ask questions like: "Is this type a pointer?" ( std::is_pointer ) "Are these two types the same?" ( std::is_same ) "Can I add these two types together?" 5. Concepts (C++20)

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) In standard C++, a function takes values and returns a value

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

Uses static constexpr to return a result (e.g., calculating a factorial at compile time). calculating a factorial at compile time).

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?