---
description: Modern C++ with CMake conventions
globs: ["**/*.{cpp,hpp,h,cc,cxx}","**/CMakeLists.txt","CMakePresets.json"]
alwaysApply: false
---

# Modern C++ (C++20/23) + CMake

- Configure/build with presets: `cmake --preset dev && cmake --build --preset dev`; test with `ctest --preset dev`. Sanitizer preset (`-fsanitize=address,undefined`) for debugging.
- Targets, not globals: `target_link_libraries`, `target_include_directories`, `target_compile_features(x PUBLIC cxx_std_20)`. No `include_directories` or `link_libraries` at directory scope.
- Dependencies via the project's manager (vcpkg manifest, Conan, or `FetchContent` with pinned tags).
- Warnings on and treated as errors in CI (`-Wall -Wextra -Wpedantic -Werror` / `/W4 /WX`).

## Code
- RAII for every resource; no naked `new`/`delete`. Ownership via `std::unique_ptr` (default) or `std::shared_ptr` (only when sharing is real); non-owning access via references, `std::span`, `std::string_view`.
- Rule of zero: let members manage resources; if you write one special member, think about all five.
- `const` and `constexpr` by default; `[[nodiscard]]` on functions whose results matter.
- Use `std::optional`, `std::variant`, `std::expected` (C++23) for absent values and errors when the codebase doesn't use exceptions.
- Prefer algorithms and ranges (`std::ranges::sort`) over hand-written loops when clearer.
- No C-style casts, no `using namespace std;` in headers, `#pragma once` or include guards in every header.
- Format with `clang-format`, lint with `clang-tidy` using the repo's config.

## Done when
Build with zero warnings, `ctest` passes, and the sanitizer build is clean for the changed code.
