关于 cpp
cpp 是一项 C++ 编码指导技能,重点介绍智能指针、RAII 和现代语言模式。它还提供标准库类型的选择指南及构建命令示例。
主要功能
- 01智能指针所有权指导
- 02基于 RAII 的资源管理
- 03现代 C++ 编码模式
- 04标准类型选择指南
- 05g++、clang++ 和 CMake 命令
适用场景
- 01按所有权需求选择指针类型
- 02使用 RAII 管理资源
- 03用所列命令构建 C++ 项目
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ odjaramillo/ custom-rules --skill cpp安装后在 Claude Code 中输入/cpp确认已加载。
README 原文English
来自项目 READMEREADME 暂无中文译文,以下为英文原文;中文介绍见上方。
Critical Patterns
Smart Pointers (REQUIRED)
// ✅ ALWAYS: Use smart pointers
auto user = std::make_unique<User>("John");
auto shared = std::make_shared<Config>();
// ❌ NEVER: Raw new/delete
User* user = new User("John");
delete user;
RAII (REQUIRED)
// ✅ ALWAYS: Resource management through constructors/destructors
class FileHandle {
std::fstream file_;
public:
FileHandle(const std::string& path) : file_(path) {}
~FileHandle() { if (file_.is_open()) file_.close(); }
};
Modern Patterns (REQUIRED)
// ✅ Use auto for type deduction
auto items = std::vector<int>{1, 2, 3};
// ✅ Use range-based for loops
for (const auto& item : items) {
process(item);
}
// ✅ Use structured bindings
auto [name, age] = getPerson();
Decision Tree
Need unique ownership? → std::unique_ptr
Need shared ownership? → std::shared_ptr
Need optional value? → std::optional
Need multiple types? → std::variant
Need string views? → std::string_view
Commands
g++ -std=c++20 -Wall -Wextra main.cpp -o app
clang++ -std=c++20 main.cpp -o app
cmake -B build && cmake --build build
评论
支持 Markdown