13eholder/modern-cpp-skills/m04-zero-cost

Claude Code and agent skill by 13eholder/modern-cpp-skills

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

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

Install

npx vskill@latest install 13eholder/modern-cpp-skills/m04-zero-cost

SKILL.md

The same SKILL.md was published earlier as 13eholder/modern-cpp-skills/m04-zero-cost.

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

IssueDesign Question
Template spewAre you missing Concepts constraints?
Linker errorDid you define template in .cpp instead of .h?
Object slicingDid you assign Derived to Base value?
Slow buildAre 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

PatternDispatchCostUse When
`virtual`DynamicVtable + Cache missPlugins, Runtime extensions.
TemplateStaticCode bloatHigh perf, Type deduction.
`std::function`DynamicAlloc + IndirectStoring callbacks.
`std::variant`Static branchingBranch switchClosed set of types.
CRTPStaticZeroStatic inheritance.

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
5

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/13eholder/modern-cpp-skills/m04-zero-cost/badge)](https://verified-skill.com/skills/13eholder/modern-cpp-skills/m04-zero-cost)

Something wrong with this skill or its page? Tell us.