Mastering C++ Ownership: Move Semantics, RAII, and Reference Safety. Triggers: std::move, use-after-free, double-free, dangling pointer, copy elision, RVO, reference qualifiers.
Who owns this resource, and does it need to move?
In C++, ownership is a discipline, not just a compiler check. You must decide:
std::unique_ptr.std::shared_ptr.T* or T& (non-owning).| Compiler/Sanitizer Error | Design Question |
| ------------------------ | ---------------------------------------------------------- |
| Double Free | Who owns this? Did you copy a raw pointer? |
| Use After Free | Did a reference outlive its owner? |
| Memory Leak | Where is the destructor called? (Did you use new?) |
| Object slicing | Why are you passing by value instead of pointer/reference? |
| Moved-from usage | Why are you touching a variable after std::move? |
Does it need a heap allocation?
std::unique_ptr (Rule of Zero).Is it a Transfer or a Copy?
std::move.clone() pattern if polymorphic).Is this a View?
std::string_view, std::span, or const T&.std::shared_ptr unless transferring shared ownership.Trace Up (Diagnosing):
T*) managing a resource?unique_ptr or vector.Trace Down (Implementing):
void consume(BigThing t); called with consume(std::move(thing));| Pattern | Cost | Use When |
| ----------------- | -------------- | -------------------------------------- |
| Value (Stack) | Zero | Default choice. Small/Medium objects. |
| unique_ptr | Zero | Heap needed. Exclusive ownership. |
| shared_ptr | Atomic Inc/Dec | Cyclic graph or true shared ownership. |
| T& (Ref) | Zero | Parameter passing (non-null). |
| T* (Ptr) | Zero | Parameter passing (nullable). |
| std::move | Zero | Transferring ownership. |
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer