cpp

Designs and reviews modern C++ APIs with explicit ownership and type-safe state modeling.

172|8|Updated Apr 13, 2026
One-click install
npx skills add https://github.com/margelo/react-native-skills --skill cpp-margelo
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cpp
Source: https://github.com/margelo/react-native-skills/tree/main/skills/cpp
Command: npx skills add https://github.com/margelo/react-native-skills --skill cpp-margelo

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? C++ codebases often suffer from unclear ownership, bloated files mixing unrelated responsibilities, stringly-typed state, and ad-hoc threading that causes races and latency. This Skill provides concrete design rules for building maintainable C++ APIs and native implementations, including React Native Nitro Modules. ## Core Features & Use Cases - Type-Safe API Design: Model state variants with std::variant and strong structs instead of structs full of std::optional fields. - File Organization Rules: Enforce one cohesive responsibility per file, keep headers small, and split converters, delegates, and platform adapters into named files. - Ownership and Async Guidance: Apply RAII, avoid raw owning pointers, keep work off main/UI threads, and treat mutexes as a last resort with strict callback rules. - Nitro Module Support: Implement generated HybridObject specs correctly with std::shared_ptr<Promise<T>> and focused spec files. - Use Case: When implementing a C++-backed Nitro Module for barcode scanning, use this Skill to model ScannedBarcode as a variant type, keep HybridDataScanner.cpp focused, and route camera callbacks through a single owned executor. ## Quick Start Use the cpp skill to review my HybridDataScanner.cpp implementation and suggest how to restructure its ownership and file boundaries.

Frequently Asked Questions about cpp

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I design a type-safe C++ API with variant states?

Model state variants with std::variant, inheritance, or separate concrete types instead of one struct with many std::optional fields. Keep related values nonoptional on the variant where they are valid, and reserve std::optional for genuine domain absence within a single state.

How should I organize large C++ implementation files?

Keep one primary class or cohesive algorithm per file and split delegates, converters, and platform adapters into named files. Files above roughly 300 lines need a clear single-responsibility justification, and bulky helpers belong in separate files under a detail namespace.

How do I implement async methods in a Nitro Module HybridObject?

C++ HybridObjects must inherit from the generated Hybrid*Spec class and copy its signatures exactly. Use std::shared_ptr<Promise<T>> for generated async methods, and keep conversion helpers and platform glue in separate files from the spec implementation.

When should I use std::mutex in C++ callback code?

Treat std::mutex as a last resort after ruling out a single owner thread, immutable snapshots, or message passing. Never hold a mutex while invoking callbacks, crossing into JS/Nitro, or calling platform APIs; snapshot the data, unlock, then call out.

Why is my C++ async workflow bouncing between threads a problem?

Repeated executor, queue, and callback hops are an architecture smell that hides latency and complicates ordering. A component should own its executor or cross into that owner once at the public async boundary; redesign the lifecycle instead of adding hops or sleeps.