dot_claude/skills/cpp-expert/SKILL.md
Use when needing idiomatic, high-performance C++ (C++23 baseline, C++17/20 compatibility notes) guidance. Covers the modern "safe subset", RAII, error handling, tooling, and cross-language interop.
npx skillsauth add nijaru/dotfiles cpp-expertInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
| Prohibited | Use Instead |
| :--------------------------- | :--------------------------------------------- |
| Raw owning pointers (T*) | std::unique_ptr<T>, std::shared_ptr<T> |
| new / delete | Smart pointers, containers, std::make_unique |
| C-style casts (T)x | static_cast, dynamic_cast, bit_cast |
| C-style arrays T arr[N] | std::array<T, N>, std::vector<T> |
| NULL | nullptr |
| printf / sprintf | std::format (C++20), std::print (C++23) |
| Manual loops over containers | std::ranges algorithms |
| void* for generics | Templates with concepts |
| #define constants | constexpr / inline constexpr |
| #define macros for code | constexpr functions / templates |
new/delete outside of custom allocators.reinterpret_cast requires a comment.using namespace std; in headers — pollutes every includer.throw in destructors — wrap with noexcept.std::endl in hot paths — use '\n' (endl flushes; '\n' does not).std::shared_ptr by reflex — prefer unique_ptr; shared_ptr only when ownership is genuinely shared.std::optional, or std::expected.static_assert(false) in template else-branches — ill-formed; use static_assert(!sizeof(T)) or a requires constraint.std::expected<T, E> — monadic error handling without exceptions. Use .and_then(), .or_else(), .transform().
std::expected<Config, ParseError> load(std::string_view path);
auto result = load(path).and_then(validate).transform(normalize);
std::print / std::println — type-safe, locale-aware output. Replaces printf.std::mdspan — non-owning multidimensional array view. Use for matrices, audio buffers, image data.std::flat_map / std::flat_set — sorted-vector backed associative containers; better cache performance for small-to-medium sizes.this (explicit object parameter) — enables CRTP-free mixin patterns and unified const/non-const overloads.
struct Widget {
auto& name(this auto& self) { return self.name_; }
};
std::generator<T> — stackful coroutine for lazy sequences. Use with co_yield.operator[] — matrix[row, col] valid syntax.std::stacktrace — capture call stacks at runtime for diagnostics.requires expressions.
template<std::ranges::input_range R>
void process(R&& range);
std::views pipelines over index loops. Compose with |.
auto evens = data | std::views::filter([](int x){ return x % 2 == 0; })
| std::views::transform([](int x){ return x * 2; });
std::format — type-safe string formatting. Custom types via std::formatter<T> specialization.std::span<T> — non-owning view of contiguous data. Use for function parameters accepting any buffer.<=> spaceship operator — define once, get all six comparisons.consteval — force compile-time evaluation. Stronger than constexpr.constinit — guarantee static variable is constant-initialized (no dynamic init order issues).std::jthread — RAII thread with built-in stop token. Prefer over std::thread.Point{.x = 1, .y = 2} for readable aggregate init.co_await, co_yield, co_return. Use libraries (e.g., cppcoro, asio) for infrastructure.std::expected<T, E> (C++23) or std::optional<T>.enum class over string codes. Carry context.
enum class IoError { NotFound, PermissionDenied, Eof };
std::expected<Data, IoError> read(std::filesystem::path);
unique_ptr → shared_ptr → raw non-owning T* / T&.std::string_view / std::span at API boundaries — avoid copies for read-only access.std::pmr (polymorphic memory resources) for arena/pool allocation without changing types.std::array for fixed-size buffers.constexpr, inline, templates — all resolved at compile time.[[likely]] / [[unlikely]] on branch conditions in hot paths.[[nodiscard]] on all functions returning error codes or resource handles.std::assume (C++23) — hint to optimizer that a condition is always true.std::variant + std::visit.perf, valgrind --callgrind, or Tracy before optimizing.-Wall -Wextra -Wpedantic -Wshadow -Wconversion-fsanitize=address,undefined (ASan + UBSan) for debug builds.-fsanitize=thread (TSan). Run separately from ASan.std::to_integer / std::narrow_cast — explicit narrowing conversions that trap on overflow.[[assume(expr)]] (C++23) only for proven invariants, never as wishful thinking.With C:
extern "C" for exported symbols.With Zig:
extern "C", POD types only, no exceptions across boundary).zig c++ compiles C++ via Clang — the Zig build system can link against C++ static libs.@cImport of the C header. Exceptions must not cross the boundary.With Mojo:
external_call in Mojo).extern "C" shims; expose as a shared library.| Tool | Purpose | Command |
| :------------------- | :-------------------------------------- | :---------------------------------------------------------------- |
| clang-tidy | Static analysis + enforces subset rules | clang-tidy -checks='cppcoreguidelines-*,modernize-*,bugprone-*' |
| clang-format | Formatting | clang-format -i --style=file |
| AddressSanitizer | Memory errors | -fsanitize=address |
| UBSanitizer | Undefined behavior | -fsanitize=undefined |
| ThreadSanitizer | Data races | -fsanitize=thread |
| Valgrind | Leak detection on Linux | valgrind --leak-check=full |
| vcpkg / Conan | Package management | vcpkg install / conan install |
| ccache | Compiler cache | Set CMAKE_C_COMPILER_LAUNCHER=ccache |
snake_case for variables/functions, PascalCase for types, UPPER_SNAKE for macros only..hpp for C++ headers, .h for C-compatible headers.#pragma once (universally supported, no double-include bugs)..cpp.development
Use after completing a bug fix, feature, refactor, or tk task when the first implementation taught enough context to replace it with a simpler, cleaner, or more coherent version before finalizing.
development
Use when writing, migrating, or reviewing Zig code across recent stable versions (0.14-0.16), especially to correct stale syntax or stdlib, build.zig, allocator, formatting, or runtime API knowledge.
documentation
Use when reviewing or revising text (prose, docs, commits) to remove AI patterns and improve voice/clarity.
content-media
Use when fetching X/Twitter post content by URL, or searching for recent X posts.