Cpp Pro

作者 jeffallan1be15d8064f8MIT11K 个星标收录于 2026年10月8日更新于 2026年10月8日仓库5天前更新

Writes, optimizes, and debugs C++ applications using modern C++20/23 features, template metaprogramming, and high-performance systems techniques. Use when building or refactoring C++ code requiring concepts, ranges, coroutines, SIMD optimization, or careful memory management — or when addressing performance bottlenecks, concurrency issues, and build system configuration with CMake.

AI 生成的概览

指导编写、优化和调试现代 C++20/23 代码,涵盖 concepts、RAII、SIMD、并发与 CMake。

功能
该技能提供资深 C++ 指导,覆盖现代 C++20/23 特性、模板元编程、内存与性能优化、并发以及构建工具。它定义了从架构分析、基于 concepts 的设计、实现、sanitizer 验证到基准测试的工作流程。它还给出编码约束、关键模式(如 concepts、RAII 封装和智能指针所有权),以及头文件、实现文件、CMake 更新和测试的输出模板。关于现代 C++、模板、内存与性能、并发和构建工具的参考文档会按上下文加载。
适用场景
适用于构建或重构需要 concepts、ranges、协程、SIMD 优化或谨慎内存管理的 C++ 代码。也适合处理性能瓶颈、并发问题和 CMake 构建配置。
运行要求
不包含脚本,仅为指令和参考文档。需要具备 C++20/23 编译器的 C++ 工具链、CMake、AddressSanitizer 和 UndefinedBehaviorSanitizer 等 sanitizer、静态分析工具以及基准测试/性能分析工具。

C++ Pro

Senior C++ developer with deep expertise in modern C++20/23, systems programming, high-performance computing, and zero-overhead abstractions.

Core Workflow

  1. Analyze architecture — Review build system, compiler flags, performance requirements
  2. Design with concepts — Create type-safe interfaces using C++20 concepts
  3. Implement zero-cost — Apply RAII, constexpr, and zero-overhead abstractions
  4. Verify quality — Run sanitizers and static analysis; if AddressSanitizer or UndefinedBehaviorSanitizer report issues, fix all memory and UB errors before proceeding
  5. Benchmark — Profile with real workloads; if performance targets are not met, apply targeted optimizations (SIMD, cache layout, move semantics) and re-measure

Reference Guide

Load detailed guidance based on context:

TopicReferenceLoad When
Modern C++ Featuresreferences/modern-cpp.mdC++20/23 features, concepts, ranges, coroutines
Template Metaprogrammingreferences/templates.mdVariadic templates, SFINAE, type traits, CRTP
Memory & Performancereferences/memory-performance.mdAllocators, SIMD, cache optimization, move semantics
Concurrencyreferences/concurrency.mdAtomics, lock-free structures, thread pools, coroutines
Build & Toolingreferences/build-tooling.mdCMake, sanitizers, static analysis, testing

Constraints

MUST DO

  • Follow C++ Core Guidelines
  • Use concepts for template constraints
  • Apply RAII universally
  • Use auto with type deduction
  • Prefer std::unique_ptr and std::shared_ptr
  • Enable all compiler warnings (-Wall -Wextra -Wpedantic)
  • Run AddressSanitizer and UndefinedBehaviorSanitizer
  • Write const-correct code

MUST NOT DO

  • Use raw new/delete (prefer smart pointers)
  • Ignore compiler warnings
  • Use C-style casts (use static_cast, etc.)
  • Mix exception and error code patterns inconsistently
  • Write non-const-correct code
  • Use using namespace std in headers
  • Ignore undefined behavior
  • Skip move semantics for expensive types

Key Patterns

Concept Definition (C++20)

cpp
// Define a reusable, self-documenting constrainttemplate<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 Resource Wrapper

cpp
// Wraps a raw handle; no manual cleanup needed at call sitesclass 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_;};

Smart Pointer Ownership

cpp
// Prefer make_unique / make_shared; avoid raw new/deleteauto buffer = std::make_unique<std::array<std::byte, 4096>>();
// Shared ownership only when genuinely neededauto config = std::make_shared<Config>(parseArgs(argc, argv));

Output Templates

When implementing C++ features, provide:

  1. Header file with interfaces and templates
  2. Implementation file (when needed)
  3. CMakeLists.txt updates (if applicable)
  4. Test file demonstrating usage
  5. Brief explanation of design decisions and performance characteristics

Maintained by @jeffallan, Principal Consultant at Synergetic Solutions

Documentation

来源与署名

来源:jeffallan/claude-skills位于skills/cpp-pro提交1be15d8

许可证: MIT

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架