agentleFS
Premchand006Premchand006/AI-assistant-skills/skills/cpp-coding-standards/SKILL.md

cpp-coding-standards

Skill0 starsChanged 52 days agoMITView on GitHub

Enforce modern C++ guidelines (C++17/20/23) derived from the ISO C++ Core Guidelines. Covers RAII, resource ownership, const-correctness, Rule of Zero and Five, smart pointer selection, bounds safety, concepts, and avoiding undefined behavior. Use when writing, reviewing, or refactoring C++ code, headers, classes, or systems modules, or when checking that C++ interfaces enforce memory and type safety at compile time.

19 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use agent-payment-x402, openclaw-persona-forge and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • TironFoxSkill

    agent-payment-x402

    Add x402 payment execution to AI agents — per-task budgets, spending controls, and non-custodial wallets via MCP tools. Use when agents need to pay for APIs, services, or other agents.

    Also in 6 projects that use this

  • TironFoxSkill

    openclaw-persona-forge

    为 OpenClaw AI Agent 锻造完整的龙虾灵魂方案。根据用户偏好或随机抽卡, 输出身份定位、灵魂描述(SOUL.md)、角色化底线规则、名字和头像生图提示词。 如当前环境提供已审核的生图 skill,可自动生成统一风格头像图片。 当用户需要创建、设计或定制 OpenClaw 龙虾灵魂时使用。 不适用于:微调已有 SOUL.md、非 OpenClaw 平台的角色设计、纯工具型无性格 Agent。 触发词:龙虾灵魂、虾魂、OpenClaw 灵魂、养虾灵魂、龙虾角色、龙虾定位、 龙虾剧本杀角色、龙虾游戏角色、龙虾 NPC、龙虾性格、龙虾背景故事、 lobster soul、lobster character、抽卡、随机龙虾、龙虾 SOUL、gacha。

    Also in 5 projects that use this

  • loulanyueSkill

    nuxt4-patterns

    Nuxt 4 app patterns for hydration safety, performance, route rules, lazy loading, and SSR-safe data fetching with useFetch and useAsyncData.

    Also in 9 projects that use this

  • junimnjwSkill

    ralphinho-rfc-pipeline

    RFC-driven multi-agent DAG execution pattern with quality gates, merge queues, and work unit orchestration.

    Also in 10 projects that use this

  • loulanyueSkill

    santa-method

    Multi-agent adversarial verification with convergence loop. Two independent review agents must both pass before output ships.

    Also in 8 projects that use this

  • renepfSkill

    motion-advanced

    Advanced motion patterns for React / Next.js — drag & drop, gestures, text animations, SVG path drawing, custom hooks, imperative sequences (useAnimate), loaders, and the full API decision tree. Requires motion-foundations.

    Also in 4 projects that use this

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 2 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Value semantics: Prefer returning values or structured bindings rather than passing output parameters.

    line 24
  2. Very specific:

    Compile-time enforcement: Prefer static_assert and C++20 concepts over runtime dynamic checks where feasible.

    line 25
  3. Very specific:

    When shared ownership is genuinely necessary across independent async subsystems, use std::shared_ptr.

    line 40
  4. Distinctive:

    If a class directly wraps a low-level OS handle or hardware resource, handle all special members explicitly (Rule of Five):

    line 55

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Modern C++ Standards (ISO C++ Core Guidelines)

The bugs that cost the most in C++ arise from ambiguous resource ownership, dangling pointers, uninitialized state, and silent slicing during polymorphic copies. The ISO C++ Core Guidelines eliminate these classes of defects by relying on the compiler's type system, value semantics, and deterministic resource destruction.

// RAII and value semantics: no explicit memory calls required
auto buffer = std::make_unique<uint8_t[]>(length);
std::span<const uint8_t> view(buffer.get(), length);

Extended rule tables and cross-cutting guideline mappings live in references/core-guidelines.md. Consult that reference when deciding between language features or verifying specific rule numbers (P, I, F, C, R, T, SL).

Core Principles

  1. RAII everywhere: Tie resource acquisition and release directly to object lifetimes. Raw new and delete should not appear in application code.
  2. Immutability by default: Mark data members and variables const or constexpr unless mutation is required.
  3. Value semantics: Prefer returning values or structured bindings rather than passing output parameters.
  4. Compile-time enforcement: Prefer static_assert and C++20 concepts over runtime dynamic checks where feasible.

Ownership and Pointers

A raw pointer represents an observation, not an owner. An interface that receives a raw pointer assumes the caller manages lifetime.

// Explicit ownership transfer via unique_ptr
void ingest(std::unique_ptr<Packet> packet);

// Borrowed view: non-owning observation
void inspect(const Packet& packet);
void inspect_range(std::span<const uint8_t> bytes);

When shared ownership is genuinely necessary across independent async subsystems, use std::shared_ptr. Otherwise, prefer std::unique_ptr because it avoids atomic reference counting overhead.

Rule of Zero and Rule of Five

A class that relies on standard containers (std::vector, std::string, std::unique_ptr) requires no custom copy, move, or destructor logic. This is the Rule of Zero.

struct Session {
    std::string id;
    std::vector<uint8_t> payload;
    std::unique_ptr<SocketHandle> socket;
    // Special member functions generated automatically by compiler
};

If a class directly wraps a low-level OS handle or hardware resource, handle all special members explicitly (Rule of Five):

  1. Destructor
  2. Copy constructor
  3. Copy assignment operator
  4. Move constructor
  5. Move assignment operator

Polymorphic base classes should declare their destructor public virtual or protected non-virtual to avoid undefined behavior during deletion.

Interfaces and Parameter Passing

  • Pass cheaply copied types (e.g., primitives, std::string_view, std::span) by value.
  • Pass expensive or polymorphic types by const&.
  • Single-argument constructors should be marked explicit to prevent unintended implicit conversions.
  • Scoped enumerations (enum class) prevent unscoped identifier collisions.
enum class Channel : uint8_t {
    primary,
    backup,
    telemetry
};

class Node {
public:
    explicit Node(std::string_view identifier);
};

Honest limits

This skill enforces stylistic and architectural guidelines. It does not replace a static analysis engine (such as clang-tidy or SonarQube) or a dynamic memory sanitizer (ASan/TSan). Adhering to the Core Guidelines minimizes runtime defects, but cannot mathematically prove freedom from race conditions or lock contention in complex multithreaded systems.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.