cpp-templates-metaprogramming

Implements generic C++ libraries using templates, SFINAE, concepts, and compile-time metaprogramming.

4|Updated Feb 5, 2026
One-click install
npx skills add https://github.com/ki2pixel/After-Effects-Scripts-Plugins-Bundle --skill cpp-templates-metaprogramming-ki2pixel
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cpp-templates-metaprogramming
Source: https://github.com/ki2pixel/After-Effects-Scripts-Plugins-Bundle/tree/main/.windsurf/skills/cpp-templates-metaprogramming
Command: npx skills add https://github.com/ki2pixel/After-Effects-Scripts-Plugins-Bundle --skill cpp-templates-metaprogramming-ki2pixel

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing reusable, type-safe C++ code without sacrificing performance requires deep knowledge of templates, and mistakes produce cryptic compiler errors. This Skill provides structured guidance and working patterns for generic programming so you can build compile-time-checked libraries correctly. ## Core Features & Use Cases - Generic Programming Patterns: Function templates, class templates, partial and full specialization, variadic templates, and fold expressions with complete code examples. - Compile-Time Constraints: SFINAE with std::enable_if, tag dispatching, if constexpr, and C++20 concepts for clear template constraints and better error messages. - Metaprogramming Techniques: Type traits, type lists, CRTP static polymorphism, expression templates, and constexpr/consteval compile-time computation. - Use Case: You are building a generic container library and need to constrain a function to only accept integral types. Use the concepts and SFINAE patterns to enforce the constraint at compile time with readable error messages. ## Quick Start Write a C++20 concept that constrains a template function to only accept container types with begin, end, and size methods.

Frequently Asked Questions about cpp-templates-metaprogramming

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I constrain a C++ template to specific types?

Use C++20 concepts with a requires clause or the abbreviated template syntax to constrain template parameters. For older standards, use std::enable_if with type traits like std::is_integral to enable overloads only for matching types.

What is the difference between SFINAE and C++20 concepts?

SFINAE removes invalid template overloads from consideration using substitution failure, typically via std::enable_if. Concepts express constraints directly and produce clearer compiler error messages, making them the preferred approach in C++20.

How do variadic templates and fold expressions work in C++?

Variadic templates accept parameter packs of any size using typename... Args. C++17 fold expressions like (args + ...) expand the pack with an operator, replacing recursive template instantiation for operations like summing all arguments.

When should I use constexpr instead of template metaprogramming?

Prefer constexpr functions for compile-time computation because they are more readable and debuggable than recursive template structs. Reserve template metaprogramming for type-level operations like type lists and trait manipulation.

Why do C++ template errors produce such long messages?

Template errors cascade through every instantiation layer, and the compiler reports the full substitution chain. Using concepts, static_assert with clear messages, and if constexpr reduces error depth and points directly to the violated constraint.

What is CRTP and when should I use it?

CRTP (Curiously Recurring Template Pattern) passes the derived class as a template parameter to its base, enabling static polymorphism resolved at compile time. Use it to avoid virtual function overhead in performance-critical code.