cpp-core-guidelines

📁 ariaszzzhc/cpp-core-guidelines 📅 10 days ago
2
总安装量
2
周安装量
#62867
全站排名
安装命令
npx skills add https://github.com/ariaszzzhc/cpp-core-guidelines --skill cpp-core-guidelines

Agent 安装分布

amp 2
gemini-cli 2
claude-code 2
github-copilot 2
codex 2
kimi-cli 2

Skill 文档

C++ Core Guidelines

Overview

These guidelines help write C++ code that is:

  • Type-safe: No implicit violations of the type system
  • Resource-safe: No leaks (memory, handles, locks, etc.)
  • Performant: Efficient without sacrificing correctness
  • Correct: Catches more logic errors at compile time

Load Reference by Scenario

Choose the reference file based on what you’re doing:

Scenario Reference File Rules
Checking memory leaks, RAII, pointers memory-safety.md R., ES., Con.*
Designing function signatures, APIs api-design.md I., F.
Designing or reviewing classes class-design.md C.*
Thread safety, data races, locks concurrency.md CP.*
Exceptions, error codes, error handling error-handling.md E.*
Templates, STL, generic code templates.md T., SL., Enum.*
Coding style, naming, philosophy modern-style.md P., NL., SF.*
Performance optimization, C compatibility performance.md Per., CPL., A.*

Quick Reference

Memory Safety

// Bad: manual management
X* p = new X;
delete p;

// Good: RAII
auto p = make_unique<X>();

API Design

// Bad: unclear ownership
void process(int* data, int n);

// Good: explicit ownership and size
void process(span<const int> data);

Class Design

// Rule of zero - let compiler generate
class Widget {
    unique_ptr<Impl> pImpl;  // No explicit dtor/copy/move needed
};

Concurrency

// Bad: manual lock
mutex mtx;
mtx.lock();
// ...
mtx.unlock();

// Good: RAII lock
lock_guard<mutex> lock(mtx);

Code Review Checklist

When reviewing C++ code, load the appropriate reference and check:

Memory Safety → memory-safety.md

  • No raw new/delete
  • RAII for all resources
  • No dangling pointers
  • Proper const usage

API Design → api-design.md

  • Interfaces are explicit
  • Parameters express ownership
  • Return values over output params

Class Design → class-design.md

  • Class has clear invariant
  • Rule of zero/five followed
  • Virtual destructor for base classes

Thread Safety → concurrency.md

  • No data races
  • lock_guard/scoped_lock used
  • No deadlocks