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: GEMINI.md § Testing Strategy.
Ownership and Memory
RAII — resources tied to object lifetime. No manual new/delete.
std::unique_ptr for exclusive ownership, std::shared_ptr only when sharing is necessary.
Move semantics — prefer moving over copying for expensive types.
Error Handling
std::expected (C++23) or Result types for expected failures.
Exceptions for exceptional conditions only. Never for control flow.
noexcept on move constructors and destructors.
Modern Features
std::string_view for read-only string parameters (no allocation).
constexpr for compile-time evaluation.
Structured bindings: auto [id, title] = getTask();
std::optional for nullable values.
Naming
PascalCase for types. camelCase or snake_case for functions (project-consistent).
_ suffix for private members: storage_, logger_.
No Hungarian notation.
Testing
Google Test or Catch2. Google Mock for interface mocking.
Formatting and Static Analysis
Tool
Purpose
Command
clang-format
Formatting
clang-format -i src/**/*.cpp
clang-tidy
Static analysis
clang-tidy src/*.cpp --
cppcheck
Bug detection
cppcheck --enable=all src/
AddressSanitizer
Memory errors
-fsanitize=address
ThreadSanitizer
Race conditions
-fsanitize=thread
Related
Code Idioms and Conventions GEMINI.md § Code Idioms and Conventions
Resources and Memory Management @.gemini/skills/resources-and-memory-management/SKILL.md
Concurrency and Threading Principles @.gemini/skills/concurrency-and-threading-principles/SKILL.md
1---2name: cpp-idioms3description: C++ Idioms and Patterns4---56## C++ Idioms and Patterns78Modern 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.910> Scope: C++ coding idioms. Test naming: GEMINI.md § Testing Strategy.1112### Ownership and Memory13141. **RAII — resources tied to object lifetime. No manual `new`/`delete`.**152. **`std::unique_ptr` for exclusive ownership, `std::shared_ptr` only when sharing is necessary.**163. **Move semantics — prefer moving over copying for expensive types.**1718### Error Handling19201. **`std::expected` (C++23) or Result types for expected failures.**212. **Exceptions for exceptional conditions only.** Never for control flow.223. **`noexcept` on move constructors and destructors.**2324### Modern Features25261. **`std::string_view`** for read-only string parameters (no allocation).272. **`constexpr`** for compile-time evaluation.283. **Structured bindings**: `auto [id, title] = getTask();`294. **`std::optional`** for nullable values.3031### Naming32331. **PascalCase** for types. **camelCase** or **snake_case** for functions (project-consistent).342. **`_` suffix** for private members: `storage_`, `logger_`.353. No Hungarian notation.3637### Testing3839Google Test or Catch2. Google Mock for interface mocking.4041### Formatting and Static Analysis4243| Tool | Purpose | Command |44|---|---|---|45| `clang-format` | Formatting | `clang-format -i src/**/*.cpp` |46| `clang-tidy` | Static analysis | `clang-tidy src/*.cpp --` |47| `cppcheck` | Bug detection | `cppcheck --enable=all src/` |48| AddressSanitizer | Memory errors | `-fsanitize=address` |49| ThreadSanitizer | Race conditions | `-fsanitize=thread` |5051### Related52- Code Idioms and Conventions GEMINI.md § Code Idioms and Conventions53- Resources and Memory Management @.gemini/skills/resources-and-memory-management/SKILL.md54- Concurrency and Threading Principles @.gemini/skills/concurrency-and-threading-principles/SKILL.md
Run npx skillmds@latest add irahardianto/cpp-idioms in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
C++ Idioms and Patterns It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
irahardianto (@irahardianto) published this skill. Their other Agent Skills are listed on their SkillMD profile.