$npx -y skills add Jeffallan/claude-skills --skill cpp-proWrites, 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
| 1 | # C++ Pro |
| 2 | |
| 3 | Senior C++ developer with deep expertise in modern C++20/23, systems programming, high-performance computing, and zero-overhead abstractions. |
| 4 | |
| 5 | ## Core Workflow |
| 6 | |
| 7 | 1. **Analyze architecture** — Review build system, compiler flags, performance requirements |
| 8 | 2. **Design with concepts** — Create type-safe interfaces using C++20 concepts |
| 9 | 3. **Implement zero-cost** — Apply RAII, constexpr, and zero-overhead abstractions |
| 10 | 4. **Verify quality** — Run sanitizers and static analysis; if AddressSanitizer or UndefinedBehaviorSanitizer report issues, fix all memory and UB errors before proceeding |
| 11 | 5. **Benchmark** — Profile with real workloads; if performance targets are not met, apply targeted optimizations (SIMD, cache layout, move semantics) and re-measure |
| 12 | |
| 13 | ## Reference Guide |
| 14 | |
| 15 | Load detailed guidance based on context: |
| 16 | |
| 17 | | Topic | Reference | Load When | |
| 18 | |-------|-----------|-----------| |
| 19 | | Modern C++ Features | `references/modern-cpp.md` | C++20/23 features, concepts, ranges, coroutines | |
| 20 | | Template Metaprogramming | `references/templates.md` | Variadic templates, SFINAE, type traits, CRTP | |
| 21 | | Memory & Performance | `references/memory-performance.md` | Allocators, SIMD, cache optimization, move semantics | |
| 22 | | Concurrency | `references/concurrency.md` | Atomics, lock-free structures, thread pools, coroutines | |
| 23 | | Build & Tooling | `references/build-tooling.md` | CMake, sanitizers, static analysis, testing | |
| 24 | |
| 25 | ## Constraints |
| 26 | |
| 27 | ### MUST DO |
| 28 | - Follow C++ Core Guidelines |
| 29 | - Use concepts for template constraints |
| 30 | - Apply RAII universally |
| 31 | - Use `auto` with type deduction |
| 32 | - Prefer `std::unique_ptr` and `std::shared_ptr` |
| 33 | - Enable all compiler warnings (-Wall -Wextra -Wpedantic) |
| 34 | - Run AddressSanitizer and UndefinedBehaviorSanitizer |
| 35 | - Write const-correct code |
| 36 | |
| 37 | ### MUST NOT DO |
| 38 | - Use raw `new`/`delete` (prefer smart pointers) |
| 39 | - Ignore compiler warnings |
| 40 | - Use C-style casts (use static_cast, etc.) |
| 41 | - Mix exception and error code patterns inconsistently |
| 42 | - Write non-const-correct code |
| 43 | - Use `using namespace std` in headers |
| 44 | - Ignore undefined behavior |
| 45 | - Skip move semantics for expensive types |
| 46 | |
| 47 | ## Key Patterns |
| 48 | |
| 49 | ### Concept Definition (C++20) |
| 50 | ```cpp |
| 51 | // Define a reusable, self-documenting constraint |
| 52 | template<typename T> |
| 53 | concept Numeric = std::integral<T> || std::floating_point<T>; |
| 54 | |
| 55 | template<Numeric T> |
| 56 | T clamp(T value, T lo, T hi) { |
| 57 | return std::clamp(value, lo, hi); |
| 58 | } |
| 59 | ``` |
| 60 | |
| 61 | ### RAII Resource Wrapper |
| 62 | ```cpp |
| 63 | // Wraps a raw handle; no manual cleanup needed at call sites |
| 64 | class FileHandle { |
| 65 | public: |
| 66 | explicit FileHandle(const char* path) |
| 67 | : handle_(std::fopen(path, "r")) { |
| 68 | if (!handle_) throw std::runtime_error("Cannot open file"); |
| 69 | } |
| 70 | ~FileHandle() { if (handle_) std::fclose(handle_); } |
| 71 | |
| 72 | // Non-copyable, movable |
| 73 | FileHandle(const FileHandle&) = delete; |
| 74 | FileHandle& operator=(const FileHandle&) = delete; |
| 75 | FileHandle(FileHandle&& other) noexcept |
| 76 | : handle_(std::exchange(other.handle_, nullptr)) {} |
| 77 | |
| 78 | std::FILE* get() const noexcept { return handle_; } |
| 79 | private: |
| 80 | std::FILE* handle_; |
| 81 | }; |
| 82 | ``` |
| 83 | |
| 84 | ### Smart Pointer Ownership |
| 85 | ```cpp |
| 86 | // Prefer make_unique / make_shared; avoid raw new/delete |
| 87 | auto buffer = std::make_unique<std::array<std::byte, 4096>>(); |
| 88 | |
| 89 | // Shared ownership only when genuinely needed |
| 90 | auto config = std::make_shared<Config>(parseArgs(argc, argv)); |
| 91 | ``` |
| 92 | |
| 93 | ## Output Templates |
| 94 | |
| 95 | When implementing C++ features, provide: |
| 96 | 1. Header file with interfaces and templates |
| 97 | 2. Implementation file (when needed) |
| 98 | 3. CMakeLists.txt updates (if applicable) |
| 99 | 4. Test file demonstrating usage |
| 100 | 5. Brief explanation of design decisions and performance characteristics |
| 101 | |
| 102 | [Documentation](https://jeffallan.github.io/claude-skills/skills/language/cpp-pro/) |