m04-zero-cost
Skill14 starsChanged 9 months agoMITView on GitHub
Mastering C++ Polymorphism: Templates, Concepts, and Virtual Functions. Triggers: templates, concepts, vtable, CRTP, static polymorphism, dynamic polymorphism, SFINAE.
7 other projects use a version of this.
Adopted by
Most recently taken up by
- TeddyAlbina/skillstheir own version, first seen Nov 1, 2026
- moeru-ai/auvtheir own version, first seen Oct 10, 2026
- fjrevoredo/mini-diariumtheir own version, first seen Oct 8, 2026
- ZhangHanDong/rust-skillstheir own version, first seen Oct 8, 2026
- MovGP0/Skillstheir own version, first seen Jun 30, 2026
- pocket-veto/pocket-vetotheir own version, first seen Jun 27, 2026
Other versions7 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 7
- ZhangHanDong/rust-skills★ 1.5ksame name
- actionbook/rust-skills★ 1.5ksame name
- fjrevoredo/mini-diarium★ 318same name
- moeru-ai/auv★ 207same name
- TeddyAlbina/skills★ 2same name
- MovGP0/Skills★ 1same name
- pocket-veto/pocket-veto★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository14 other files it gives its agents.
- cpp20-skill-creatorSkill
- m01-ownershipSkill
- m02-resourceSkill
- m03-mutabilitySkill
- m05-type-drivenSkill
- m06-error-handlingSkill
- m07-concurrencySkill
- m09-domainSkill
- m10-performanceSkill
- m11-ecosystemSkill
- m12-lifecycleSkill
- m13-domain-errorSkill
- m14-mental-modelSkill
- m15-anti-patternSkill
The file
Files
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
- Is the set of types known at compile time?
- Yes? → Templates or
std::variant. - No? → Inheritance (Virtual functions).
- Yes? → Templates or
- Do I need to store them in a list?
- Homogeneous? →
std::vector<T>. - Heterogeneous? →
std::vector<std::unique_ptr<Base>>orstd::vector<std::variant<...>>.
- Homogeneous? →
- 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(); }
- Intent: "I want a function that accepts anything that has
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. |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

