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 從公開儲存庫中收錄這些內容。

檢舉或申請下架