cpp

A guide to modern C++ programming patterns, including smart pointers, templates, and the standard library. Smart pointers manage when dynamically allocated objects are released.

In plain words
What is it for?
Use it when choosing between unique, shared, and weak ownership, applying resource-management patterns, and writing modern C++ with standard library tools.
Why use it?
It helps prevent common memory-ownership mistakes and makes C++ code easier to manage and maintain.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/miles990/claude-software-skills/cpp
Any agent
npx skills add miles990/claude-software-skills --skill cpp
Clone the repo
git clone --depth 1 https://github.com/miles990/claude-software-skills

Made for: Claude Code, Codex.

Per session 10 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,489 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00010 $0.03489
Opus 5 $0.00005 $0.01744
Sonnet 5 $0.00002 $0.00698
Haiku 4.5 $0.00001 $0.00349

Measured 2d ago against content hash 74db424583f9, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

cpp scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

programming-languages/cpp/SKILL.md · 615 lines

How it starts

The opening of the file, as written. The whole thing — 615 lines — stays where its author put it; the contents beside it link to each section on GitHub.

C++

Overview

Modern C++ (C++11 and beyond) patterns including RAII, smart pointers, templates, and STL.


Modern C++ Fundamentals

Smart Pointers

#include <memory>
#include <iostream>

// unique_ptr - exclusive ownership
class Resource {
public:
    Resource() { std::cout << "Resource acquired\n"; }
    ~Resource() { std::cout << "Resource released\n"; }
    void use() { std::cout << "Resource used\n"; }
};

void unique_ptr_example() {
    // Create unique_ptr
    auto ptr = std::make_unique<Resource>();
    ptr->use();

    // Transfer ownership
    auto ptr2 = std::move(ptr);
    // ptr is now nullptr

    // Array support
    auto arr = std::make_unique<int[]>(10);
}

// shared_ptr - shared ownership
void shared_ptr_example() {
    auto shared1 = std::make_shared<Resource>();
    {
        auto shared2 = shared1; // Reference count = 2
        shared2->use();
    } // shared2 destroyed, count = 1

    std::cout << "Use count: " << shared1.use_count() << "\n";
} // shared1 destroyed, resource released

// weak_ptr - non-owning reference
class Node {
public:
    std::shared_ptr<Node> next;
    std::weak_ptr<Node> prev; // Avoid circular reference

    ~Node() { std::cout << "Node destroyed\n"; }
};

void weak_ptr_example() {
    auto node1 = std::make_shared<Node>();
    auto node2 = std::make_shared<Node>();

    node1->next = node2;
    node2->prev = node1; // weak_ptr, no ownership

    if (auto locked = node2->prev.lock()) {
        // Use locked (shared_ptr)
    }
}

RAII Pattern

#include <fstream>
#include <mutex>

// File wrapper with RAII
class File {
    std::fstream file_;

public:
    explicit File(const std::string& filename)
        : file_(filename, std::ios::in | std::ios::out) {
        if (!file_.is_open()) {
            throw std::runtime_error("Failed to open file");
        }
    }

    ~File() {
        if (file_.is_open()) {
            file_.close();
        }
    }

    // Delete copy operations
    File(const File&) = delete;
    File& operator=(const File&) = delete;

    // Allow move operations
    File(File&& other) noexcept : file_(std::move(other.file_)) {}
    File& operator=(File&& other) noexcept {
        file_ = std::move(other.file_);
        return *this;
    }

    void write(const std::string& data) {
        file_ << data;
    }
};

// Lock guard (RAII for mutex)
class ThreadSafeCounter {
    mutable std::mutex mutex_;
    int count_ = 0;

public:
    void increment() {
        std::lock_guard<std::mutex> lock(mutex_);
        ++count_;
    }

    int get() const {
        std::lock_guard<std::mutex> lock(mutex_);
        return count_;
    }
};

// Scoped cleanup
template<typename F>
class ScopeGuard {
    F cleanup_;
    bool active_ = true;

public:
    explicit ScopeGuard(F cleanup) : cleanup_(std::move(cleanup)) {}

    ~ScopeGuard() {
        if (active_) cleanup_();
    }

    void dismiss() { active_ = false; }

    ScopeGuard(const ScopeGuard&) = delete;
    ScopeGuard& operator=(const ScopeGuard&) = delete;
};

// Usage
void example() {
    auto resource = acquireResource();
    ScopeGuard guard([&]() { releaseResource(resource); });

    // Do work...

    guard.dismiss(); // Don't cleanup if successful
}

Read the full file on GitHub · 615 lines

Files

What ships with it

2 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 615 lines · 10 tokens per session scan A 74db424583f9

Subscribe to this mod's changes

cpp is a skill published in the GitHub repository miles990/claude-software-skills (20 stars, last pushed 7mo ago), licensed MIT. It adds 10 tokens to every session and 3,489 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

cpp-docs

Comprehensive C++26 reference covering all language features: basic syntax, fundamental types, type inference (auto, decltype), variables, storage duration, operators (arithmetic, comparison, logical, bitwise, member access, ternary, spaceship), control structures (if, switch, while, for, range-for), functions…

pledgeandgrow/pledge-skills · 472 tokens

cpp

Use when writing, reviewing, modernizing, building, or debugging C++ - RAII and resource lifetime, smart-pointer ownership, move semantics and the Rule of Zero/Five, target-based CMake with FetchContent, and killing undefined behavior with ASan/UBSan/TSan plus clang-tidy. NOT borrow-checker / Result-Option / cargo…

ericrisco/rsc-harness · 81 tokens

readable-cpp

Readable C/C++/Rust/CUDA code rules inspired by The Art of Readable Code. Use when writing, reviewing, or refactoring C, C++, Rust, or CUDA code. Enforces short functions, flat control flow, clear naming, readable structure, and idiomatic patterns.

crazyguitar/cppcheatsheet · 63 tokens

cpp

Comprehensive C/C++ programming reference covering everything from C11-C23 and C++11-C++23, system programming, CUDA GPU computing, debugging tools, Rust interop, and advanced topics. Use for: C/C++ questions, C/C++ interview preparation, modern language features, RAII/memory management, templates/generics, CUDA…

crazyguitar/cppcheatsheet · 107 tokens

subzeroclaw-contribute

Develop SubZeroClaw — the single-file 550-line C agentic runtime. Load this before changing src/subzeroclaw.c or src/test.c: it carries the anti-framework thesis (the goal is NOT to grow), the code map (the loop, config, the shell tool, async compaction), what will and won't be merged, and the build/test loop. To…

genlayerlabs/subzeroclaw · 100 tokens

misra

MISRA C:2025 expert that operates in two modes: (1) Review — scan existing C code for violations across all 223 guidelines (22 directives + 201 rules), report findings with rule IDs, corrected code, and deviation justification templates; (2) Develop — generate new C functions, modules, or data structures that are…

ptsilivis/autonomousguy · 221 tokens