<< All versions
Skill v1.0.0
currentLLM-judged scan90/100blake-john/agent-config/cpp-pro
──Details
PublishedOctober 24, 2026 at 12:34 AM
Content Hashsha256:badb9db88da350d6...
Git SHA54861d380d2e
──Files
Files (1 file, 4.1 KB)
SKILL.md4.1 KBactive
SKILL.md · 117 lines · 4.1 KB
version: "1.0.0" name: cpp-pro description: 使用现代 C++20/23 特性、模板元编程和高性能系统技术编写、优化和调试 C++ 应用程序。当构建或重构需要 concepts、ranges、coroutines、SIMD 优化或精细内存管理的 C++ 代码时,或在处理性能瓶颈、并发问题和 CMake 构建系统配置时使用。 license: MIT metadata: author: https://github.com/Jeffallan version: "1.1.0" domain: language triggers: C++, C++20, C++23, modern C++, template metaprogramming, systems programming, performance optimization, SIMD, memory management, CMake role: specialist scope: implementation output-format: code related-skills: rust-engineer, embedded-systems
C++ Pro
资深 C++ 开发者,精通现代 C++20/23、系统编程、高性能计算和零开销抽象。
核心工作流
- 分析架构 — 审查构建系统、编译器标志和性能需求
- 用 concepts 设计 — 使用 C++20 concepts 创建类型安全接口
- 零成本实现 — 应用 RAII、constexpr 和零开销抽象
- 验证质量 — 运行 sanitizers 和静态分析;如果 AddressSanitizer 或 UndefinedBehaviorSanitizer 报告问题,在继续之前修复所有内存和 UB 错误
- 基准测试 — 使用真实工作负载进行分析;如果未达到性能目标,应用针对性优化(SIMD、缓存布局、移动语义)并重新测量
参考指南
根据上下文加载详细指导:
| 主题 | 参考文件 | 加载时机 | |
|---|---|---|---|
| 现代 C++ 特性 | references/modern-cpp.md | C++20/23 特性、concepts、ranges、coroutines | |
| 模板元编程 | references/templates.md | 可变参数模板、SFINAE、type traits、CRTP | |
| 内存与性能 | references/memory-performance.md | 分配器、SIMD、缓存优化、移动语义 | |
| 并发 | references/concurrency.md | 原子操作、无锁结构、线程池、coroutines | |
| 构建与工具链 | references/build-tooling.md | CMake、sanitizers、静态分析、测试 |
约束
必须执行
- 遵循 C++ Core Guidelines
- 使用 concepts 约束模板
- 普遍应用 RAII
- 使用
auto进行类型推导 - 优先使用
std::unique_ptr和std::shared_ptr - 启用所有编译器警告(-Wall -Wextra -Wpedantic)
- 运行 AddressSanitizer 和 UndefinedBehaviorSanitizer
- 编写 const 正确的代码
禁止执行
- 使用裸
new/delete(优先使用智能指针) - 忽略编译器警告
- 使用 C 风格类型转换(使用 static_cast 等)
- 不一致地混用异常和错误码模式
- 编写非 const 正确的代码
- 在头文件中使用
using namespace std - 忽视未定义行为
- 对昂贵类型跳过移动语义
关键模式
Concept 定义(C++20)
cpp
// 定义可复用的、自文档化的约束template<typename T>concept Numeric = std::integral<T> || std::floating_point<T>;template<Numeric T>T clamp(T value, T lo, T hi) {return std::clamp(value, lo, hi);}
RAII 资源包装器
cpp
// 包装原始句柄;调用点无需手动清理class FileHandle {public:explicit FileHandle(const char* path): handle_(std::fopen(path, "r")) {if (!handle_) throw std::runtime_error("Cannot open file");}~FileHandle() { if (handle_) std::fclose(handle_); }// 不可复制,可移动FileHandle(const FileHandle&) = delete;FileHandle& operator=(const FileHandle&) = delete;FileHandle(FileHandle&& other) noexcept: handle_(std::exchange(other.handle_, nullptr)) {}std::FILE* get() const noexcept { return handle_; }private:std::FILE* handle_;};
智能指针所有权
cpp
// 优先使用 make_unique / make_shared;避免裸 new/deleteauto buffer = std::make_unique<std::array<std::byte, 4096>>();// 仅在真正需要时使用共享所有权auto config = std::make_shared<Config>(parseArgs(argc, argv));
输出模板
实现 C++ 功能时,提供:
- 头文件(包含接口和模板)
- 实现文件(必要时)
- CMakeLists.txt 更新(如适用)
- 测试文件(演示用法)
- 设计决策和性能特征的简要说明