lang-cpp
Use when the user asks about modern C++ (C++20, C++23), RAII, smart pointers, move semantics, templates and concepts, std::span, coroutines, CMake or…
от j4flmao★ 47 звёзд на GitHub
Установить lang-cpp в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Modern C++
Purpose
C++ offers zero-overhead abstractions and full control, at the price of undefined behaviour and lifetime bugs when used carelessly. This skill applies the modern subset — RAII everywhere, value semantics, no owning raw pointers, concepts over SFINAE — and the tooling that catches what the type system cannot.
Agent Protocol
Trigger
"C++", "modern C++", "C++20", "C++23", "RAII", "smart pointers", "move semantics", "templates", "concepts", "CMake", "rule of five", "std::span", "coroutines".
Input Context
- Standard level and compilers (GCC, Clang, MSVC) and platforms
- Codebase conventions (exceptions on/off, allocator rules, Core Guidelines adoption)
- Performance/ABI constraints (library boundaries, embedded, real-time)
Output Artifact
C++ code, CMake snippets, or review findings with the rule each one violates. No file unless requested.
Response Format
Std: {C++20} Compiler: {clang 19 / gcc 14 / MSVC 17.x}
Change: {what and why}
Code: {snippet}
Ownership/lifetime: {who owns what}
Verify: {tests + sanitizers + clang-tidy checks}
1. Ownership
| Situation | Use |
|---|---|
| Single owner, heap object | std::unique_ptr<T> via std::make_unique<T>(...) |
| Shared ownership (genuinely shared lifetime) | std::shared_ptr<T> via std::make_shared — costs atomic refcounts |
| Non-owning access | T&, const T&, T* (nullable), std::span<T>, std::string_view |
Break shared_ptr cycles |
std::weak_ptr<T> |
| Value with optional presence | std::optional<T> |
- No
new/deletein application code. A raw pointer means "borrowed, does not own". string_view/spanmust not outlive the data they view — never return one to a local or temporary.
2. Rule of Zero / Five
- Prefer the rule of zero: members that manage themselves (
std::vector,std::unique_ptr,std::string) so the compiler-generated special members are correct. - If you write any of destructor, copy ctor/assignment, move ctor/assignment, consider all five; mark moves
noexceptso containers use them during reallocation.
class FileHandle {
public:
explicit FileHandle(const char* path) : f_(std::fopen(path, "rb")) {
if (!f_) throw std::system_error(errno, std::generic_category(), path);
}
~FileHandle() { if (f_) std::fclose(f_); }
FileHandle(FileHandle&& o) noexcept : f_(std::exchange(o.f_, nullptr)) {}
FileHandle& operator=(FileHandle&& o) noexcept {
if (this != &o) { if (f_) std::fclose(f_); f_ = std::exchange(o.f_, nullptr); }
return *this;
}
FileHandle(const FileHandle&) = delete;
FileHandle& operator=(const FileHandle&) = delete;
std::FILE* get() const noexcept { return f_; }
private:
std::FILE* f_;
};
(Or: std::unique_ptr<std::FILE, decltype(&std::fclose)>.)
3. Value and Move Semantics
- Pass cheap types by value, read-only large types by
const T&, sink parameters by value thenstd::moveinto the member. std::moveis only a cast; the moved-from object must stay valid but unspecified — do not use its value afterwards.- Return by value: copy elision is guaranteed for prvalues (C++17) and NRVO is usual; do not write
return std::move(local);.
4. Templates and Concepts (C++20)
#include <concepts>
#include <ranges>
template <std::ranges::input_range R>
requires std::integral<std::ranges::range_value_t<R>>
auto sum(const R& r) {
std::ranges::range_value_t<R> total{};
for (auto v : r) total += v;
return total;
}
- Concepts give readable errors and replace most SFINAE/
enable_if. - Static polymorphism with CRTP or concepts where virtual dispatch cost matters (see
references/crtp-static-polymorphism.md); otherwise virtual functions are fine. - Keep heavy templates out of widely included headers; consider explicit instantiation to cut build times.
5. Error Handling
- Exceptions for exceptional failures in code that can unwind;
std::expected<T, E>(C++23) orstd::optionalfor expected, local failures; error codes at C/ABI boundaries. - Destructors and move operations must not throw. Mark non-throwing functions
noexcept. - If exceptions are disabled (
-fno-exceptions, common in games/embedded), useexpected-style returns consistently.
6. Concurrency
std::jthread(C++20, joins on destruction, stop tokens),std::mutexwithstd::scoped_lock(deadlock-free multi-lock),std::atomicwith explicit memory orders only when profiled.- Data races are UB. Share immutable data freely; protect mutable shared state; prefer message passing/task systems for complex pipelines.
- Coroutines (C++20) are a language mechanism; use a library (e.g. Asio, cppcoro-style task types,
std::generatorin C++23) rather than hand-writing promise types.
7. Standard Library Picks
std::vector by default (contiguous, cache friendly); std::array for fixed size; std::unordered_map (or a flat/open-addressing map from Abseil/Boost for spee
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- references/cpp-advanced.md
- references/cpp-fundamentals.md
- references/cpp-testing.md
- references/crtp-static-polymorphism.md
FAQ
Что делает скилл lang-cpp?
Use when the user asks about modern C++ (C++20, C++23), RAII, smart pointers, move semantics, templates and concepts, std::span, coroutines, CMake or undefined behavior in C++. Produces idiomatic C++ with ownership rules and sanitizer builds. Not for firmware C++ subsets (use c-cpp-patterns) or plain C (use lang-c).
Как установить скилл lang-cpp?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл lang-cpp запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
AnthropicToolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
access
AnthropicManage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
configure
AnthropicSet up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
access
AnthropicManage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…