cpp
Language-specific super-code guidelines for cpp.
C++: Idiomatic Efficiency Reference
When to Use
- Use this skill when the task matches this description: Language-specific super-code guidelines for cpp.
Table of Contents
- [Memory & Ownership](#memory)
- [Modern Types & Containers](#types)
- [Move Semantics & References](#move)
- [Templates & Concepts](#templates)
- [Error Handling](#errors)
- [Concurrency](#concurrency)
- [Anti-patterns specific to C++](#antipatterns)
1. Memory & Ownership {#memory}
// ❌ Raw new/delete
Widget* w = new Widget();
// ... 15 lines later ...
delete w;
// ✅
auto w = std::make_unique<Widget>();
// ❌ Shared ownership when unique suffices
auto w = std::make_shared<Widget>();
transfer(w); // only one owner
// ✅ — unique_ptr; move when transferring
auto w = std::make_unique<Widget>();
transfer(std::move(w));
// ❌ new[] for dynamic arrays
int* arr = new int[n];
// ... use ...
delete[] arr;
// ✅
std::vector<int> arr(n);
// ❌ Manual RAII wrapper for file/mutex
FILE* f = fopen(path, "r");
// ... must remember fclose ...
// ✅
std::ifstream f(path);
// closes automatically at scope exit
// For non-standard resources: use unique_ptr with custom deleter
auto f = std::unique_ptr<FILE, decltype(&fclose)>(fopen(path, "r"), fclose);
Rule: if you type new, you almost certainly want make_unique or make_shared.
2. Modern
Subscribers only
The full skill, its 1 bundled files and every download is included with every paid Complete AI plan.
Details
| Source | community |
|---|---|
| License | — |
| Risk label | safe ("critical" means the skill may run commands or touch files — read before use) |
| Files | SKILL.md |
| Added | 2026-06-16 |
