Mastering C++ Polymorphism: Templates, Concepts, and Virtual Functions. Triggers: templates, concepts, vtable, CRTP, static polymorphism, dynamic polymorphism, SFINAE.
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. |
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer