# C++ Code Review Review {{input}} for correctness, modern style, and best practices. ## Resource Management (RAII) - Own resources through RAII types; avoid raw `new`/`delete` - Use `std::unique_ptr` for exclusive ownership, `std::shared_ptr` only when shared ownership is genuinely needed - Prefer stack allocation and value semantics over heap allocation - Rule of Five: if you define any of destructor, copy constructor, copy assignment, move constructor, move assignment — define all five (or `= delete` / `= default` explicitly) ## Correctness - Avoid undefined behaviour: no signed overflow, no out-of-bounds, no null dereference, no use-after-free - Mark functions `noexcept` only when they genuinely cannot throw; broken `noexcept` contracts call `terminate()` - Use `std::optional`, `std::variant`, or exceptions for error states — never sentinel values like `-1` for sizes - Avoid `reinterpret_cast`; prefer `static_cast` with explicit validation ## Modern C++ (C++17/20) - Prefer range-based for loops and standard algorithms over raw index loops - Use structured bindings and `if`-initializers where they improve clarity - Prefer `std::string_view` over `const std::string&` for non-owning string parameters - Replace C-style arrays with `std::array` or `std::vector` ## Concurrency (if applicable) - Protect shared mutable state with `std::mutex`; use `std::lock_guard`/`std::unique_lock` - No data races — review all shared state accessed from multiple threads - Prefer `std::atomic` for simple flags and counters over a mutex ## Code Quality - Compile with `-Wall -Wextra -Wpedantic` and enable sanitizers (`-fsanitize=address,undefined`) - Mark member functions `const` when they do not modify state - No raw owning pointers in public APIs; no C-style casts --- List findings as **Critical** (UB/memory unsafety/data races) -> **Major** (bugs/resource leaks/wrong semantics) -> **Minor** (style/modern idioms). Cite each location and suggest the concrete fix.