m04-zero-cost/SKILL.md
Mastering C++ Polymorphism: Templates, Concepts, and Virtual Functions. Triggers: templates, concepts, vtable, CRTP, static polymorphism, dynamic polymorphism, SFINAE.
npx skillsauth add 13eholder/modern-cpp-skills m04-zero-costInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
When do we determine the type?
std::any, std::variant. Flexible, vtable overhead.| 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? |
Is the set of types known at compile time?
std::variant.Do I need to store them in a list?
std::vector<T>.std::vector<std::unique_ptr<Base>> or std::vector<std::variant<...>>.Does the interface match exactly?
Trace Up:
Trace Down:
.draw()."void render(Drawable auto& item) { item.draw(); }| 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. |
tools
Common C++ Anti-Patterns. Triggers: global variables, new/delete, C-style cast, macros, void*.
data-ai
C++ Mental Models: Pointer vs Reference, Initialization, Undefined Behavior.
data-ai
Mastering C++ Domain Errors: Exception Hierarchies, System Errors, and Expected.
data-ai
Mastering C++ Lifecycle: RAII, Destructors, Static Initialization, Rule of 5.