smithery.ai

m04-zero-cost

Mastering C++ Polymorphism: Templates, Concepts, and Virtual Functions. Triggers: templates, concepts, vtable, CRTP, static polymorphism, dynamic polymorphism, SFINAE.

First seen Mar 27, 2026

Installation

$ npx skills add https://smithery.ai

Similar popular skills

Related neighbors and high-traction skills in the same topics — useful to compare before installing.

Also in this package

Other skills from smithery.ai · top by installs.

npx skills add https://smithery.ai

Browse all from smithery.ai

More details

Agent compatibility

Declared targets from SKILL.md / docs. Unmarked agents are not listed — the skill may still install via the CLI.

Claude Code Not declared
Cursor Not declared
Codex Not declared
GitHub Copilot Not declared
Windsurf Not declared
Gemini CLI Not declared
Cline Not declared
OpenCode Not declared

Package contents

Files included with this skill beyond the listing page.

  • skill md SKILL.md 2,541 B
  • docs SUMMARY.md 188 B

History

  1. First seen on skills.sh
  2. First recorded snapshot · 2 installs

SKILL.md

C++ Zero-Cost Abstractions

Core Question

When do we determine the type?

  • Compile Time (Static): Templates, Concepts, CRTP. Zero runtime cost, larger binary.
  • Runtime (Dynamic): Virtual functions, std::any, std::variant. Flexible, vtable overhead.

Error → Design Question

Issue Design Question
Template spew Are you missing Concepts constraints?
Linker error Did you define template in .cpp instead of .h?
Object slicing Did you assign Derived to Base value?
Slow build Are you overusing headers/templates?

Thinking Prompt

  1. Is the set of types known at compile time?

- Yes? → Templates or std::variant. - No? → Inheritance (Virtual functions).

  1. Do I need to store them in a list?

- Homogeneous? → std::vector<T>. - Heterogeneous? → std::vector<std::unique_ptr<Base>> or std::vector<std::variant<...>>.

  1. Does the interface match exactly?

- Duck typing needed? → Templates (Concepts). - Strict hierarchy? → Inheritance.

Trace Up / Down

  • Trace Up:

- Issue: "Virtual function call is too slow in tight loop." - Cause: Indirect branch misprediction. - Fix: Switch to Static Polymorphism (CRTP or Templates) if types are known.

  • Trace Down:

- Intent: "I want a function that accepts anything that has .draw()." - Code (C++20): void render(Drawable auto& item) { item.draw(); }

Quick Reference

Pattern Dispatch Cost Use When
virtual Dynamic Vtable + Cache miss Plugins, Runtime extensions.
Template Static Code bloat High perf, Type deduction.
std::function Dynamic Alloc + Indirect Storing callbacks.
std::variant Static branching Branch switch Closed set of types.
CRTP Static Zero Static inheritance.