cpp-coding-standards
This skill delivers comprehensive coding standards rooted in the C++ Core Guidelines, covering modern C++17/20/23 practices. It emphasizes type safety, resource management through RAII, immutability by default, and clear intent in code design. Use it when writing new code, reviewing existing implementations, or making architectural decisions to enforce consistent, safe, and idiomatic C++ across your projects.
C++ Coding Standards teaches modern C++ best practices grounded in the Core Guidelines for safer, clearer code.
AI-generated summary based on this skill's SKILL.md
Install
xu-xiang/everything-claude-code-zh/cpp-coding-standards · repository language: JavaScript
git clone https://github.com/xu-xiang/everything-claude-code-zh
cp -r everything-claude-code-zh/skills/cpp-coding-standards ~/.claude/skills/cpp-coding-standardsFrequently asked questions
AI-generated answers based on this skill's SKILL.md and metadata
What C++ coding standards guidelines does this skill cover?
cpp-coding-standards delivers comprehensive coding standards rooted in the C++ Core Guidelines, covering modern C++17/20/23 practices. It emphasizes type safety, resource management through RAII, immutability by default, and clear intent in code design. Use it when writing new code, reviewing existing implementations, or making architectural decisions to enforce consistent, safe, and idiomatic C++ across your projects.
How does cpp-coding-standards help with RAII and resource management?
cpp-coding-standards teaches RAII (Resource Acquisition Is Initialization) patterns as a core mechanism for safe resource management. It guides you through proper use of smart pointers like unique_ptr and shared_ptr, exception-safe code design, and the Rule of Five for class lifecycle management. These patterns ensure resources are automatically cleaned up and memory leaks are prevented.
What type safety and const correctness principles does cpp-coding-standards apply?
cpp-coding-standards promotes type safety by encouraging const by default, proper use of const references, and avoiding unsafe casts. It teaches const correctness principles to make intent explicit, prevent accidental mutations, and enable compiler-enforced contracts. These practices reduce bugs and improve code clarity across modern C++ codebases.
Can cpp-coding-standards help with C++ code review for safety and style?
Yes. cpp-coding-standards provides a code review framework aligned with C++ Core Guidelines, checking for safety violations, style compliance, and idiomatic patterns. It covers naming conventions, header file organization, function parameter passing, enum class usage, and anti-pattern avoidance—enabling consistent, maintainable reviews across your team.
How does cpp-coding-standards address modern C++ best practices?
cpp-coding-standards covers modern C++17/20/23 features and idioms: smart pointers for memory safety, template concepts for generic code clarity, exception handling patterns, and concurrent threading with mutex and thread safety. It balances performance optimization with safety, helping you write efficient, maintainable code that leverages the latest language capabilities.
What concurrent C++ code patterns does cpp-coding-standards teach?
cpp-coding-standards addresses concurrent C++ design with guidance on thread safety, mutex usage, and synchronization patterns. It helps you design thread-safe code that avoids race conditions and deadlocks, integrating concurrency principles into your broader C++ architecture for reliable multi-threaded applications.
SKILL.md
rendered from the published skill — quoted content, verbatim
C++ 编码规范 (C++ Core Guidelines)
源自 C++ 核心指南 (C++ Core Guidelines) 的现代 C++ (C++17/20/23) 综合编码规范。强制执行类型安全 (Type safety)、资源安全 (Resource safety)、不变性 (Immutability) 和清晰度。
何时使用
- 编写新的 C++ 代码(类、函数、模板)
- 评审或重构现有的 C++ 代码
- 在 C++ 项目中做出架构决策
- 在 C++ 代码库中强制执行一致的风格
- 在语言特性之间进行选择(例如
enumvsenum class,原始指针 vs 智能指针)
何时不使用
- 非 C++ 项目
- 无法采用现代 C++ 特性的遗留 C 代码库
- 特定指南与硬件约束冲突的嵌入式/裸机上下文(需选择性调整)
核心原则 (Cross-Cutting Principles)
以下主题贯穿整个指南并构成基础:
- 处处 RAII (P.8, R.1, E.6, CP.20):将资源生命周期与对象生命周期绑定。资源获取即初始化 (RAII)
- 默认不变性 (P.10, Con.1-5, ES.25):优先使用
const/constexpr;可变性应当是例外。不变性 (Immutability) - 类型安全 (P.4, I.4, ES.46-49, Enum.3):利用类型系统在编译时防止错误。类型安全 (Type safety)
- 表达意图 (P.3, F.1, NL.1-2, T.10):名称、类型和概念应能传达目的。表达意图 (Express intent)
- 最小化复杂性 (F.2-3, ES.5, Per.4-5):简单的代码才是正确的代码
- 值语义优于指针语义 (C.10, R.3-5, F.20, CP.31):优先考虑按值返回和作用域对象。值语义 (Value semantics)
哲学与接口 (P., I.)
核心规则
| 规则 | 摘要 |
|---|---|
| P.1 | 直接在代码中表达思想 |
| P.3 | 表达意图 |
(truncated - see the full file via the links below)
Read as markdown · JSON record · Browse the source repository
File tree — 1 file
skills/cpp-coding-standards/SKILL.md