Install
$ agentstack add skill-miaoge-ge-coding-agent-skills-cpp-expert ✓ scanned · ✓ verified — works with Claude Code, Cursor, and more.
Security review
✓ PassedNo issues found. Passed automated security review. · v0.1.0 How review works →
- ✓ Prompt-injection patterns
- ✓ Secret / credential exfiltration
- ✓ Dangerous shell & filesystem operations
- ✓ Untrusted network calls
- ✓ Known-malicious package signatures
What it can access
- ✓ Network access No
- ✓ Filesystem access No
- ✓ Shell / process execution No
- ✓ Environment & secrets No
- ✓ Dynamic code execution No
From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.
About
C++ Expert
> RAII owns every resource; values move, don't copy. Make ownership explicit, lean on the STL, and treat undefined behavior as a bug to prevent — not a surprise to debug.
When to Use
- Writing or reviewing C++.
- Modern features (C++17/20/23), templates/metaprogramming, STL.
- Performance/memory tuning; smart pointers and ownership.
- Compile errors, crashes, leaks, or undefined behavior (UB).
When NOT to Use
- Another language → relevant language skill.
- Contest algorithms (language incidental) →
competitive-programming-expert. - System/architecture design →
software-architect.
Core Principles
1. Modern by default
- Target C++17/20 unless constrained. Prefer
auto, range-basedfor, structured bindings,std::optional/variant/string_view/span. - Constrain templates with Concepts (C++20) or
static_assertso errors surface at the call site, not deep in instantiation.
2. Ownership & RAII
- No owning raw pointers.
std::unique_ptrfor sole ownership,shared_ptronly when ownership is genuinely shared; create withmake_unique/make_shared. Raw pointers/references are non-owning observers. - Every resource (memory, file, lock, socket) is owned by an object that releases it in its destructor. Locks via
std::scoped_lock/lock_guard. - Follow the Rule of 0 (no manual special members) — or Rule of 5 if you manage a resource directly.
3. Value semantics & performance
- Pass
const&for read-only, by value +std::moveto sink,string_view/spanfor non-owning views. Rely on (N)RVO — return by value. - Avoid premature
shared_ptr(atomic refcount cost) and needless copies;emplace_back,reserve. Choose containers deliberately (vectorby default).constexpr/constevalfor compile-time work. Profile before micro-optimizing.
4. Avoid UB proactively
- Dangling refs/views, use-after-move, out-of-bounds, signed overflow, uninitialized reads, iterator invalidation, data races. Build with warnings (
-Wall -Wextra), sanitizers (ASan/UBSan/TSan), and tools (clang-tidy).
Common Mistakes
- Owning raw
new/delete→ leaks/double-free; use smart pointers + RAII. - Returning
string_view/reference to a local/temporary → dangling. - Using a moved-from object beyond a valid-but-unspecified state.
shared_ptreverywhere → atomic overhead + cycles (useweak_ptrto break).- C-style casts /
reinterpret_cast→ usestatic_cast/dynamic_cast. - Iterator/reference invalidation after container growth/erase.
std::endlin loops → forced flush; use'\n'.
Examples
RAII + move-only ownership (C++17)
#include
#include
#include
class Connection {
public:
explicit Connection(std::string dsn) : dsn_(std::move(dsn)) { /* open */ }
~Connection() noexcept { /* close */ }
Connection(const Connection&) = delete; // non-copyable
Connection& operator=(const Connection&) = delete;
Connection(Connection&&) noexcept = default; // movable
Connection& operator=(Connection&&) noexcept = default;
private:
std::string dsn_;
};
auto make_conn(std::string dsn) {
return std::make_unique(std::move(dsn)); // ownership is explicit
}
Concept-constrained template (clear errors, no overflow)
#include
template
constexpr T midpoint(T a, T b) noexcept { return a + (b - a) / 2; }
See Also
competitive-programming-expert— STL-heavy solutions and constant-factor tuning.performance-expert— profiling and allocation reduction.rust-expert— comparing systems-language ownership models.rules/cpp-style-guide.md— enforceable style rules.
Source & license
This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.
- Author: Miaoge-Ge
- Source: Miaoge-Ge/coding-agent-skills
- License: MIT
Install and usage instructions live in the source repository linked above.
Reviews
No reviews yet — be the first.
Write a review
Versions
- v0.1.0 Imported from the upstream source.