Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

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от 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_STANDARD is 20, and the code builds with libc++ (macOS), libstdc++ (Linux) and MSVC (Windows). Do not use C++23 or C++26 features: no std::expected, std::print, deducing this, std::flat_map, monadic std::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_ASSERTIONS for libstdc++, the libc++ hardening mode, _FORTIFY_SOURCE=3, -fstack-protector-strong, -ftrivial-auto-var-init=zero), the sanitize and tsan presets, and clang-tidy. Warnings stay -Wall -Wextra (MSVC /W4). V measures -Werror and -Wpedantic against a baseline. New code adds no warning.
  • Qt objects follow Qt ownership. A QObject with a parent is owned. Every connect() with a lambda passes a context object. A lambda that can outlive an object holds a QPointer. moc and Q_OBJECT stay.
  • C handles have one owner. Wrap each FFmpeg object, VA surface, Vulkan handle and file descriptor in a std::unique_ptr with a deleter or a move-only class.
  • Output: the app logs through Qt logging. CLI modes keep the existing stdout/stderr output. Do not convert existing fprintf calls.
  • Threads: use std::jthread for a new plain thread. Use QThread when 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
Полный SKILL.md на GitHub

Установить modern-cpp в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

references/anti-patterns.mdreferences/compiler-hardening.mdreferences/cpp20-features.mdreferences/cpp23-features.mdreferences/cpp26-features.mdreferences/safe-idioms.md

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), без исполняемых скриптов.

Похожие скиллы

Сравнить modern-cpp с