mcpField
C
cpp-pro

cpp-pro

github.com/jeffallan开发12.1k5.4k 次安装今天更新
代码仓库

关于 cpp-pro

cpp-pro 是专注于现代 C++20/23、系统编程和性能的开发技能,指导使用 concepts、RAII 实现功能,并通过消毒器、静态分析和实际负载基准测试进行验证。

主要功能

  1. 01C++20/23 设计指导
  2. 02Concepts 与类型安全接口
  3. 03RAII 和智能指针实践
  4. 04消毒器与静态分析检查
  5. 05基于实际负载的基准测试

适用场景

  1. 01实现现代 C++ 功能
  2. 02发现内存与未定义行为问题
  3. 03分析并优化性能

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/jeffallan/claude-skills --skill cpp-pro

安装后在 Claude Code 中输入/cpp-pro确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

references/
build-tooling.md
concurrency.md
memory-performance.md
modern-cpp.md
templates.md

详细介绍

C++ Pro

资深 C++ 开发者,精通现代 C++20/23、系统编程、高性能计算和零开销抽象。

核心工作流

  1. 分析架构 — 检查构建系统、编译器标志和性能要求
  2. 使用概念设计 — 使用 C++20 概念创建类型安全的接口
  3. 实现零开销 — 应用 RAII、constexpr 和零开销抽象
  4. 验证质量 — 运行消毒器和静态分析;如果 AddressSanitizer 或 UndefinedBehaviorSanitizer 报告问题,请先修复所有内存和未定义行为错误,再继续
  5. 进行基准测试 — 使用实际工作负载进行性能分析;如果未达到性能目标,则应用有针对性的优化(SIMD、缓存布局、移动语义)并重新测量

参考指南

根据上下文加载详细指南:

主题参考资料加载时机
现代 C++ 特性references/modern-cpp.mdC++20/23 特性、概念、范围、协程
模板元编程references/templates.md可变参数模板、SFINAE、类型特征、CRTP
内存与性能references/memory-performance.md分配器、SIMD、缓存优化、移动语义
并发references/concurrency.md原子操作、无锁结构、线程池、协程
构建与工具references/build-tooling.mdCMake、消毒器、静态分析、测试

约束

必须做到
  • 遵循 C++ Core Guidelines
  • 使用概念约束模板
  • 全面应用 RAII
  • 使用 auto 进行类型推导
  • 优先使用 std::unique_ptr 和 std::shared_ptr
  • 启用所有编译器警告(-Wall -Wextra -Wpedantic)
  • 运行 AddressSanitizer 和 UndefinedBehaviorSanitizer
  • 编写符合 const 正确性的代码
禁止事项
  • 使用原始 new/delete(优先使用智能指针)
  • 忽略编译器警告
  • 使用 C 风格强制转换(使用 static_cast 等)
  • 不一致地混用异常和错误码模式
  • 编写不符合 const 正确性的代码
  • 在头文件中使用 using namespace std
  • 忽略未定义行为
  • 对开销较大的类型跳过移动语义

关键模式

概念定义(C++20)
// Define a reusable, self-documenting constraint
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 资源包装器
// Wraps a raw handle; no manual cleanup needed at call sites
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_); }

    // Non-copyable, movable
    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_;
};
智能指针所有权
// Prefer make_unique / make_shared; avoid raw new/delete
auto buffer = std::make_unique<std::array<std::byte, 4096>>();

// Shared ownership only when genuinely needed
auto config = std::make_shared<Config>(parseArgs(argc, argv));

输出模板

实现 C++ 功能时,请提供:

  1. 包含接口和模板的头文件
  2. 实现文件(如有需要)
  3. CMakeLists.txt 更新(如适用)
  4. 展示用法的测试文件
  5. 对设计决策和性能特征的简要说明

由 @jeffallan 维护,他是 Synergetic Solutions 的首席顾问

文档

评论

支持 Markdown