claude.symlink/skills/cpp/SKILL.md
Write modern C++ with RAII, smart pointers, and STL. Use for C++ development, memory safety, or performance optimization.
npx skillsauth add htlin222/dotfiles cppInstall 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.
Write safe, performant modern C++ code.
// Unique ownership
auto ptr = std::make_unique<Resource>();
process(std::move(ptr));
// Shared ownership
auto shared = std::make_shared<Resource>();
auto copy = shared; // Reference count: 2
// Weak reference (no ownership)
std::weak_ptr<Resource> weak = shared;
if (auto locked = weak.lock()) {
// Use locked
}
class FileHandle {
FILE* handle_;
public:
explicit FileHandle(const char* path)
: handle_(fopen(path, "r")) {
if (!handle_) throw std::runtime_error("Failed to open");
}
~FileHandle() { if (handle_) fclose(handle_); }
// Rule of 5
FileHandle(const FileHandle&) = delete;
FileHandle& operator=(const FileHandle&) = delete;
FileHandle(FileHandle&& other) noexcept
: handle_(std::exchange(other.handle_, nullptr)) {}
FileHandle& operator=(FileHandle&& other) noexcept {
std::swap(handle_, other.handle_);
return *this;
}
};
std::vector<int> nums = {3, 1, 4, 1, 5};
// Prefer algorithms over raw loops
std::sort(nums.begin(), nums.end());
auto it = std::find_if(nums.begin(), nums.end(),
[](int n) { return n > 3; });
// Range-based for
for (const auto& num : nums) {
std::cout << num << '\n';
}
// Structured bindings (C++17)
std::map<std::string, int> scores;
for (const auto& [name, score] : scores) {
std::cout << name << ": " << score << '\n';
}
// Concepts (C++20)
template<typename T>
concept Numeric = std::integral<T> || std::floating_point<T>;
template<Numeric T>
T sum(const std::vector<T>& values) {
return std::accumulate(values.begin(), values.end(), T{});
}
// SFINAE (pre-C++20)
template<typename T,
typename = std::enable_if_t<std::is_arithmetic_v<T>>>
T multiply(T a, T b) { return a * b; }
const and constexprstd::string_view for read-only strings-Wall -Wextra -Wpedantic| Issue | Symptom | Fix | | --------------- | ------------------ | -------------------- | | Memory leak | Growing memory | Use smart pointers | | Dangling ptr | Crash/UB | Check lifetime | | Buffer overflow | Crash/security | Use std::vector/span | | Data race | Inconsistent state | mutex/atomic |
Input: "Fix memory leak" Action: Replace raw pointers with smart pointers, ensure RAII
Input: "Modernize this C++ code" Action: Apply C++17/20 features, use STL, improve safety
testing
Converts narrative medical text into Pocket Medicine bullet-style notes with proper abbreviations, then modularizes sections exceeding 20 lines into linked standalone files.
devops
Use when deploying Docker services on the local VM (hostname: vm, Pop!_OS) with Traefik reverse proxy and Homepage dashboard. Covers crane image workflow, Traefik file-provider registration, Homepage services.yaml entries, and compose templates on the traefik-proxy network.
development
Use when reviewing a data visualization or figure for clarity, checking if a graph communicates its message without additional context, or iterating on R/Python plot scripts until a naive reader can fully understand the figure.
development
Runs Vale prose linter on markdown/text files and auto-fixes issues. Use when the user asks to lint, proofread, or improve writing quality of markdown or text files.