Skip to content
Back to skills

Cpp Exemplars

ASecurity

成熟开源 C++ 项目的真实代码片段库,作编码范例对照:写新类/新接口前、评审说不清"该怎么写"时按主题查阅。触发词:编码范例/代码风格样本/接口设计参考/示例代码/对标开源。

  • 2 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added November 13, 2026
ai-agentsgoc++

Security analysis

A100/100

Pro scans all 8 files and shows the line behind each finding

Scanned November 13, 2026

npx -y skills add guang-lee-cn/scaffold-skills --skill cpp-exemplars --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Cpp Exemplars?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Cpp Exemplars
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/guang-lee-cn-cpp-exemplars/badge)](https://www.skillsdirectory.com/skills/guang-lee-cn-cpp-exemplars)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: cpp-exemplars
description: 成熟开源 C++ 项目的真实代码片段库,作编码范例对照:写新类/新接口前、评审说不清"该怎么写"时按主题查阅。触发词:编码范例/代码风格样本/接口设计参考/示例代码/对标开源。
---

# C++ 编码范例库

## 用途

规则会腐化,样本不会。动手写一个新类、一组接口或一条异步生命周期之前,先看一页真实的好代码,比背条款有效;评审时说不清"该长什么样",也可以直接指样本。

适用时机:
- 动手写新类/新接口之前
- 评审只给得出"这样不好"、给不出"该怎么写"时
- 两个方案拿不准,想看成熟项目的实际取舍

## 用法

1. 先选主题,再读对应文件。样本分两类:
   - **按库取的**(一个库把某件事做到极致的样本):
     - 公开面控制 / const / string_view / 测试密度 → [references/fmt.md](references/fmt.md)
     - 基础类型设计 / StatusOr / span / 强类型 / 错误分层 → [references/abseil.md](references/abseil.md)
     - 异步接口面 / handler 语义 / 关闭顺序 / 在途回调收敛 → [references/asio.md](references/asio.md)
   - **按问题取的**(没有单一库能代表,用跨库对照回答「到什么程度为止」):
     - 并发原语 / 锁与数据的绑定 / 临界区边界 → [references/concurrency.md](references/concurrency.md)
     - 所有权 / 归还时机 / 析构期能做什么 → [references/ownership.md](references/ownership.md)
     - 抽象的度 / 类型擦除的代价 / 何时不该抽 → [references/abstraction.md](references/abstraction.md)
     - 返回值 / 错误码分档 / 借码 / 回调内自我撤销 → [references/status-codes.md](references/status-codes.md)
2. **「看什么」和「不看什么」两栏都要读。** 只看「看什么」会连同该项目的模板密度、宏和兼容层一起抄错。
3. 对照自己的代码逐条问:这个决定可迁移,还是只是该项目的规模与历史包袱?**尤其注意库与产品的差别**——七份样本大多来自通用库,它们的公开面纪律(自带视图、ABI 兼容、双标准入口)搬到单一产品里往往就是过度设计。
4. `status-codes.md` 是唯一一份 C 样本。收入标准不是语言相同,而是**问题形态与语言无关**:返回值闭集、码值分档、回调归还控制权,这三件事在 C 与 C++ 里是同一个问题、同一类解,因此可迁移;C 的 `goto` 清理梯、宏泛型、手工生命周期则不在样本范围内。

## 版本锚点

「出处」里的 `master` / `main` 是流动的,行号会漂。复核顺序:

1. 按「出处」的路径抓回同一文件;
2. 行号对不上但**内容还在** → 版本漂移,样本仍然有效,把行号更新掉;
3. 内容本身变了(注释被改写、签名被改) → 样本过期,重取并更新抓取日期。

所以引用样本时,「文件 + 函数名或注释首句」比「行号」可靠;行号只是当日快照的定位辅助。

## 红线

范例只用来对照,不复制代码。开源许可证(MIT / Apache-2.0 / BSD-2-Clause / BSL-1.0 等)都带署名与声明义务;片段进入自己的仓库前必须过许可证审查。不确定就不抄,只学结构与契约。

**源码可得 ≠ 可转录。** SSPLv1、RSALv2、BUSL、以及大部分「源码可见」许可都不是 OSI 认可的开源许可,不能进白名单:这类项目只能在「出处」里点名、用文字描述其机制,片段一律不转录(`status-codes.md` 对 redis 即按此处理)。

Files in this skill

  • SKILL.md3.6 KB
  • references/abseil.md2.6 KB
  • references/abstraction.md3.4 KB
  • references/asio.md2.2 KB
  • references/concurrency.md2.4 KB
  • references/fmt.md2.4 KB
  • references/ownership.md2.5 KB
  • references/status-codes.md3.5 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.