Cpp Idioms
Cpp Idioms teaches you how to write safe, efficient C++ code using modern language features and proven design patterns. Learn RAII principles, smart pointer ownership models, move semantics, and error handling with std::expected—all grounded in C++17/20/23 standards. The skill covers interfaces, dependency injection, testing strategies, and anti-patterns to avoid, with practical code examples and tooling guidance.
Cpp Idioms teaches modern C++ best practices including RAII, smart pointers, and move semantics for safe, performant code.
AI-generated summary based on this skill's SKILL.md
Install
irahardianto/awesome-agv/cpp-idioms · repository language: JavaScript
git clone https://github.com/irahardianto/awesome-agv
cp -r awesome-agv/.agents/skills/cpp-idioms ~/.claude/skills/cpp-idiomsFrequently asked questions
AI-generated answers based on this skill's SKILL.md and metadata
What are RAII, smart pointers, unique_ptr, and shared_ptr in Cpp Idioms?
Cpp Idioms teaches RAII (Resource Acquisition Is Initialization) as the cornerstone of C++ memory safety. Smart pointers—unique_ptr and shared_ptr—encode ownership semantics directly in the type system. unique_ptr provides exclusive ownership with zero-cost abstraction; shared_ptr enables shared ownership with reference counting. Together they eliminate manual delete calls and prevent leaks, dangling pointers, and use-after-free bugs. Cpp Idioms shows how to choose the right pointer type for each ownership pattern.
How does Cpp Idioms cover modern C++ idioms and best practices?
Cpp Idioms focuses on writing safe, efficient code using C++17/20/23 features and proven design patterns. It teaches move semantics, value semantics, structured bindings, std::optional, and std::variant for expressive type-safe designs. The skill emphasizes zero-cost abstractions, the rule of five and rule of zero, and how to avoid anti-patterns. Practical code examples ground each concept, helping you apply idioms immediately in real projects.
What C++17, C++20, and C++23 features does Cpp Idioms teach?
Cpp Idioms covers structured bindings for elegant tuple unpacking, constexpr for compile-time evaluation, std::optional and std::variant for safe optional and union types, and string_view for zero-copy parameter passing. C++20 concepts and ranges enable type-safe generic programming with clearer error messages. C++23 additions continue this trend toward safer, more expressive abstractions. Each feature is shown in context with real-world use cases.
How does Cpp Idioms approach error handling with std::expected?
Cpp Idioms teaches std::expected as a modern alternative to exceptions for error handling. It represents either a success value or an error, enabling composable, exception-safe code paths. The skill contrasts std::expected with exceptions, showing when each is appropriate. You'll learn how to write exception-safe code, understand strong and weak guarantees, and use std::expected to encode error states in the type system for compile-time safety.
What testing, formatting, and static analysis tools does Cpp Idioms cover?
Cpp Idioms guides you through setting up a modern C++ project with CMake, Google Test for unit testing, Google Mock for mocking, clang-format for consistent code style, and clang-tidy for static analysis. These tools enforce idioms and catch bugs early. The skill shows how to integrate them into your workflow, configure them for your team's standards, and use them to maintain code quality and catch anti-patterns automatically.
How do move semantics and value semantics fit into Cpp Idioms?
Cpp Idioms teaches move semantics as the mechanism for efficient resource transfer without copying. You'll learn when to use move constructors, move assignment, and std::move, and how they interact with copy operations. Value semantics—treating objects as values rather than pointers—is emphasized for safety and clarity. The skill shows how move semantics enable zero-copy abstractions and how to design types that are both efficient and easy to reason about.
SKILL.md
rendered from the published skill — quoted content, verbatim
C++ Idioms and Patterns
Modern C++ (17/20/23) rewards RAII, value semantics, and zero-cost abstractions. Lean into the type system and smart pointers. Idiomatic C++ = safe, deterministic, performant.
> Scope: C++ coding idioms. Test naming: .agents/rules/testing-strategy.md.
Ownership and Memory
- RAII — resources tied to object lifetime. No manual
new/delete. std::unique_ptrfor exclusive ownership,std::shared_ptronly when sharing is necessary.- Move semantics — prefer moving over copying for expensive types.
- Rule of Five/Zero: ```cpp // ✅ Rule of Zero — let compiler-generated defaults work class TaskService { std::unique_ptr<TaskStorage> storage_; std::shared_ptr<Logger> logger_; public: // No destructor, copy/move constructors needed — smart pointers handle it explicit TaskService(std::unique_ptr<TaskStorage> storage, std::shared_ptr<Logger> logger) : storage_(std::move(storage)), logger_(std::move(logger)) {} };
// ✅ Rule of Five — when managing raw resources (rare) class Buffer {
(truncated - see the full file via the links below)
Read as markdown · JSON record · Browse the source repository
File tree — 1 file
.agents/skills/cpp-idioms/SKILL.md