modern-cpp
БесплатноБез исполняемых скриптовНе проверенGuides C++ code toward modern idioms (C++20/23/26). Use when writing new C++ code, modernizing legacy patterns, or working on security-critical C++. Replaces…
от nodetool-ai★ 674 звезды на GitHubОб этом скилле
Modern C++
Guide for writing modern C++ using C++20, C++23, and C++26 idioms. Focuses on patterns that eliminate vulnerability classes and reduce boilerplate, with a security emphasis from Trail of Bits.
NodeTool Project Rules
These rules take precedence over the rest of this skill when you work in
native/timeline/. The plan in
PLAN-GAPS.md is the source of
truth when the two differ.
- The standard is C++20.
CMAKE_CXX_STANDARDis 20, and the code builds with libc++ (macOS), libstdc++ (Linux) and MSVC (Windows). Do not use C++23 or C++26 features: nostd::expected,std::print, deducingthis,std::flat_map, monadicstd::optional, contracts or reflection. For a fallible function, follow the surrounding code:std::optional, or a result struct with an error string. - Package V owns the compiler flags. Do not add warning, hardening or
sanitizer flags in a package. V adds hardening (
_GLIBCXX_ASSERTIONSfor libstdc++, the libc++ hardening mode,_FORTIFY_SOURCE=3,-fstack-protector-strong,-ftrivial-auto-var-init=zero), thesanitizeandtsanpresets, and clang-tidy. Warnings stay-Wall -Wextra(MSVC/W4). V measures-Werrorand-Wpedanticagainst a baseline. New code adds no warning. - Qt objects follow Qt ownership. A
QObjectwith a parent is owned. Everyconnect()with a lambda passes a context object. A lambda that can outlive an object holds aQPointer. moc andQ_OBJECTstay. - C handles have one owner. Wrap each FFmpeg object, VA surface, Vulkan
handle and file descriptor in a
std::unique_ptrwith a deleter or a move-only class. - Output: the app logs through Qt logging. CLI modes keep the existing
stdout/stderroutput. Do not convert existingfprintfcalls. - Threads: use
std::jthreadfor a new plain thread. UseQThreadwhen Qt objects live in the thread. Do not rewrite threads in files that your package does not own. - Modernize only the code you change. Unrelated modernization in a file you touch is out of scope.
When to Use This Skill
- Writing new C++ functions, classes, or libraries
- Modernizing existing C++ code (pre-C++20 patterns)
- Choosing between legacy and modern approaches
- Working on security-critical or safety-sensitive C++
- Reviewing C++ code for modern idiom adoption
When NOT to Use This Skill
- User explicitly requires older standard: Respect constraints (embedded, legacy ABI)
- Pure C code: This skill is C++-specific
- Build system questions: CMake, Meson, Bazel configuration is out of scope
- Non-C++ projects: Mixed codebases where C++ isn't primary
Anti-Patterns to Avoid
| Avoid | Use Instead | Why |
|---|---|---|
new/delete |
std::make_unique, std::make_shared |
Eliminates leaks, double-free |
| Raw owning pointers | std::unique_ptr, std::shared_ptr |
RAII ownership semantics |
C arrays (int arr[N]) |
std::array<int, N> |
Bounds-aware, value semantics |
| Pointer + length params | std::span<T> |
Non-owning, bounds-checkable |
printf / sprintf |
std::format (std::print is C++23, not in NodeTool) |
Type-safe, no buffer overflow |
C-style casts (int)x |
static_cast<int>(x) |
Explicit intent, auditable |
#define constants |
constexpr variables |
Scoped, typed, debuggable |
SFINAE / enable_if |
Concepts + requires |
Readable constraints and errors |
| Error codes + out params | std::expected<T, E> (C++23; NodeTool uses std::optional or a result struct) |
Composable, type-safe errors |
union |
std::variant |
Type-safe, no silent UB |
Raw mutex.lock()/unlock() |
std::scoped_lock |
Exception-safe, no deadlocks |
std::thread |
std::jthread |
Auto-join, stop token support |
assert() macro |
contract_assert (C++26, not in NodeTool) |
Visible to tooling, configurable |
| Manual CRTP | Deducing this (C++23, not in NodeTool) |
Simpler, no template boilerplate |
| Macro code generation | Reflection (C++26, not in NodeTool; moc stays) | Zero-overhead, composable |
See anti-patterns.md for the full table (30+ patterns).
Decision Tree
What are you doing?
|
+-- Writing new C++ code?
| +-- Use modern idioms by default (C++20/23)
| +-- Choose the newest standard your compiler supports
| | (NodeTool: C++20 only, see NodeTool Project Rules)
| +-- See Feature Tiers below
|
+-- Modernizing existing code?
| +-- Start with Tier 1 (C++20/23) replacements
| +-- Prioritize by security impact (memory > types > style)
| +-- See anti-patterns.md for the migration table
|
+-- Security-critical code?
| +-- Enable compiler hardening flags (see below)
| +-- Enable hardened libc++ mode
| +-- Run sanitizers in CI
| +-- See safe-idioms.md and compiler-hardening.md
|
+-- Using C++26 features?
+-- Reflection: YES, plan for it (GCC 16+)
+-- Contracts: caut
Установить modern-cpp в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл modern-cpp?
Guides C++ code toward modern idioms (C++20/23/26). Use when writing new C++ code, modernizing legacy patterns, or working on security-critical C++. Replaces raw pointers with smart pointers, SFINAE with concepts, printf with std::print, error codes with std::expected.
Как установить скилл modern-cpp?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл modern-cpp запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic