cpp-templates-metaprogramming

Enable compile-time generic programming with C++ templates, SFINAE, type traits, and concepts.

187|20|Updated Nov 20, 2025
One-click install
npx skills add https://github.com/TheBushidoCollective/han --skill cpp-templates-metaprogramming
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cpp-templates-metaprogramming
Source: https://github.com/TheBushidoCollective/han/tree/main/jutsu/jutsu-cpp/cpp-templates-metaprogramming
Command: npx skills add https://github.com/TheBushidoCollective/han --skill cpp-templates-metaprogramming

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Compile-time computation and abstractions via templates and concepts enable efficient, generic code.

Core Features & Use Cases

  • Function and class templates with specialization
  • SFINAE, type traits, and concepts-based constraints
  • Examples across containers and utilities

Quick Start

Implement a simple generic Stack and a specialized string container.

Frequently Asked Questions about cpp-templates-metaprogramming

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

FAQPage Schema
How do C++ templates enable compile-time generic programming?

C++ templates allow you to write generic code that the compiler instantiates at compile time for different types. Templates parameterize functions and classes over types, enabling zero-runtime overhead abstractions. Type traits and concepts add compile-time type checking to ensure safety without runtime costs.

What's the difference between function templates, class templates, and template specialization?

Function templates define generic functions instantiated for each type used; class templates define parameterized classes. Template specialization lets you provide custom implementations for specific types or type combinations, overriding the generic version when needed for optimization or correctness.

How do SFINAE and concepts constrain template overload resolution?

SFINAE (Substitution Failure Is Not An Error) removes template candidates during overload resolution when type substitution fails. Concepts provide explicit type constraints checked at compile time, replacing complex SFINAE patterns with readable, reusable predicates for cleaner, safer generic code.

Can I use type traits to check template parameter properties at compile time?

Yes. Type traits are compile-time predicates that inspect type properties—is it a pointer, integral, const-qualified—without runtime overhead. You can conditionally enable code branches or specialize templates based on type trait checks, enabling type-safe generic algorithms and containers.

When should I use template specialization instead of overloading?

Use specialization to customize behavior for specific types or patterns while keeping the same template name; use overloading for related but distinct function signatures. Specialization avoids overload resolution ambiguity and enables partial specialization for template templates and pointer types.

What compile-time overhead do templates introduce?

Templates generate no runtime overhead—instantiation happens at compile time, producing the same code as hand-written specializations. Code size may increase due to template instantiation for multiple types, but you can control this with explicit instantiation and careful design.