重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
npx skills add https://github.com/htlin222/dotfiles --skill cpp编写安全、高效的现代 C++ 代码。
// 独占所有权
auto ptr = std::make_unique<Resource>();
process(std::move(ptr));
// 共享所有权
auto shared = std::make_shared<Resource>();
auto copy = shared; // 引用计数: 2
// 弱引用(无所有权)
std::weak_ptr<Resource> weak = shared;
if (auto locked = weak.lock()) {
// 使用 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_); }
// 五法则
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;
}
};
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
std::vector<int> nums = {3, 1, 4, 1, 5};
// 优先使用算法而非原始循环
std::sort(nums.begin(), nums.end());
auto it = std::find_if(nums.begin(), nums.end(),
[](int n) { return n > 3; });
// 基于范围的 for 循环
for (const auto& num : nums) {
std::cout << num << '\n';
}
// 结构化绑定 (C++17)
std::map<std::string, int> scores;
for (const auto& [name, score] : scores) {
std::cout << name << ": " << score << '\n';
}
// 概念 (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 (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 和 constexprstd::string_view-Wall -Wextra -Wpedantic| 问题 | 症状 | 修复方法 |
|---|---|---|
| 内存泄漏 | 内存持续增长 | 使用智能指针 |
| 悬垂指针 | 崩溃/未定义行为 | 检查生命周期 |
| 缓冲区溢出 | 崩溃/安全问题 | 使用 std::vector/span |
| 数据竞争 | 状态不一致 | mutex/atomic |
输入: "修复内存泄漏" 操作: 用智能指针替换原始指针,确保 RAII
输入: "现代化这段 C++ 代码" 操作: 应用 C++17/20 特性,使用 STL,提高安全性
每周安装次数
48
代码仓库
GitHub 星标数
76
首次出现
2026年1月22日
安全审计
安装于
gemini-cli44
codex43
opencode43
claude-code42
cursor42
github-copilot40
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
Weekly Installs
48
Repository
GitHub Stars
76
First Seen
Jan 22, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
gemini-cli44
codex43
opencode43
claude-code42
cursor42
github-copilot40
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
127,000 周安装
教程工程师技能指南:从代码到可学习内容的教学设计、最佳实践与流程
197 周安装
TypeScript项目脚手架搭建指南:Next.js、React、Node.js自动化架构
196 周安装
Magento 2 功能开发专家 | 定制电商功能、集成与架构设计
47 周安装
新闻分析师技能:掌握5W1H、倒金字塔等新闻框架,提升事实核查与信源评估能力
196 周安装
Auth0 Angular 集成指南:为 Angular 13+ 应用快速添加身份验证
196 周安装
Token Optimizer - 开源AI助手OpenClaw令牌优化工具包,降低API成本50-80%
197 周安装