cpp
What it does
This guide helps you write more modern, safe, and efficient C++ code. It shows how to use best practices for managing memory, data types, handling errors, and working with multiple processes concurrently.
When to use it
- βWhen learning modern C++.
- βWhen reviewing existing C++ code.
- βWhen writing C++ code that needs to be fast and safe.
Skill link
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/super-code/cpp/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agentβs skills folder.
Example of what to ask your AI
βHow can I safely manage memory in C++?β
5 new skills a week. 1 minute to read.
How it works
The guide compares 'bad' code examples with 'good' C++ examples. It explains why modern approaches are better for avoiding common errors and improving performance.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
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
- Modern Types & Containers
- Move Semantics & References
- Templates & Concepts
- Error Handling
- Concurrency
- Anti-patterns specific to C++
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 Types & Containers {#types}
// β C-style string manipulation
char buf[256];
sprintf(buf, "%s:%d", host, port);
// β
auto addr = std::format("{}:{}", host, port); // C++20
// or: auto addr = host + ":" + std::to_string(port);
// β out-parameter for multiple returns
void compute(int input, int& result, std::string& error);
// β
struct ComputeResult { int value; std::string error; };
ComputeResult compute(int input);
// or: std::pair / std::tuple with structured bindings
auto [value, error] = compute(input);
// β Manual loop to find element
int idx = -1;
for (int i = 0; i < vec.size(); i++) {
if (vec[i] == target) { idx = i; break; }
}
// β
auto it = std::ranges::find(vec, target); // C++20
// or: std::find(vec.begin(), vec.end(), target);
// β Checking .find() != .end() then accessing
auto it = map.find(key);
if (it != map.end()) { use(it->second); }
// β
(C++20)
if (map.contains(key)) { use(map[key]); }
// or keep iterator version when you need the value without double lookup
Use std::string_view for function parameters that don't need ownership.
3. Move Semantics & References {#move}
// β Copying a large container into a function
void process(std::vector<Data> items) { ... } // copies on call
// β
β const ref for read, move for sink
void process(const std::vector<Data>& items) { ... } // read-only
void consume(std::vector<Data> items) { ... } // sink: caller moves in
// β std::move on const object (silently copies)
const std::string s = "hello";
take(std::move(s)); // still copies
// β
β don't const things you intend to move
std::string s = "hello";
take(std::move(s));
// β Returning std::move from local (prevents NRVO)
std::vector<int> build() {
std::vector<int> v;
// ... fill ...
return std::move(v); // pessimization
// β
β just return the local; compiler applies NRVO or implicit move
return v;
}
4. Templates & Concepts {#templates}
// β SFINAE soup
template<typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
T square(T x) { return x * x; }
// β
(C++20 concepts)
template<std::integral T>
T square(T x) { return x * x; }
// β Template for one type
template<typename T>
void log(T msg) { std::cout << msg; }
// Only ever called with std::string
// β
β don't templatize unless you need multiple types
void log(std::string_view msg) { std::cout << msg; }
Concepts make template errors readable β prefer them over SFINAE and static_assert.
5. Error Handling {#errors}
// β Error codes via int returns (C-style in C++)
int parse(const std::string& input, Data& out);
// β
β std::expected (C++23) or exceptions
std::expected<Data, ParseError> parse(const std::string& input);
// or throw for exceptional conditions
Data parse(const std::string& input); // throws ParseError
// β Catching by value (slices derived exceptions)
try { ... }
catch (std::exception e) { ... }
// β
catch (const std::exception& e) { ... }
β¦
FAQ
What is 'RAII'?
RAII stands for 'Resource Acquisition Is Initialization'. It's a C++ technique where resources (like memory or files) are managed automatically when an object is created or destroyed. For example, a file is automatically closed when the object representing it goes out of scope.
Why use `std::vector` instead of `new int[n]`?
`std::vector` manages memory automatically, saving you from having to worry about allocating and deallocating memory manually, which can lead to errors. It also offers more useful features.
What are 'move semantics'?
Move semantics is a way to optimize the transfer of resources (like large data blocks) between objects. Instead of copying everything, which can be slow, it 'moves' ownership of the resources, making the operation much faster.
Details
Original description by the author
Language-specific super-code guidelines for cpp.
Popularity
- GitHub stars
- 48k
- Ranking position
- #5888
- License
- MIT
- Updated
- 10/15/2026
Comments
- β¦
More skills from this repository
00-andruia-consultant
48kHelps your agent start or improve AI projects. It analyzes code, suggests tools, and creates action plans in Spanish.
007
48kLets your agent perform security audits and threat modeling. It's useful for protecting projects against attacks and vulnerabilities.
10-andruia-skill-smith
48kHelps your agent create or improve AI tools. It defines how tools work, writes documentation, and validates the structure.
20-andruia-niche-intelligence
48kLets your agent create a summary about a specific industry. It's useful for understanding the context, rules, usage patterns, and risks of a project, using reliable sources.
Similar skills
diffs
394kLets your agent produce a real, shareable diff of edits as a viewer link or image file, instead of a hand-written summary.
coding-agent
394kHelps your agent hand a larger coding job to Codex, Claude Code, or OpenCode as a background worker, then check on its progress.
gh-issues
394kHelps your agent find GitHub issues, pick the ones to work on, and open pull requests with fixes, including follow-up on review comments.