Complete AI TrainingYourJobSkills for your job

Skills / super-code

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

  1. [Memory & Ownership](#memory)
  2. [Modern Types & Containers](#types)
  3. [Move Semantics & References](#move)
  4. [Templates & Concepts](#templates)
  5. [Error Handling](#errors)
  6. [Concurrency](#concurrency)
  7. [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

Sourcecommunity
License
Risk labelsafe ("critical" means the skill may run commands or touch files — read before use)
FilesSKILL.md
Added2026-06-16

Related skills

bash

Language-specific super-code guidelines for bash.

c

Language-specific super-code guidelines for c.

csharp

Language-specific super-code guidelines for csharp.

dart

Language-specific super-code guidelines for dart.

elixir

Language-specific super-code guidelines for elixir.

go

Language-specific super-code guidelines for go.