13eholder/modern-cpp-skills/m03-mutability
Claude Code and agent skill by 13eholder/modern-cpp-skills
Trust tier 3
- community
Source check pending
Checking that the SKILL.md file is still in the repository.
Mastering C++ Const Correctness and Mutability. Triggers: const, mutable, logically const, bitwise const, data race, mutex, shared_mutex, thread safety.
Install
npx vskill@latest install 13eholder/modern-cpp-skills/m03-mutabilitySKILL.md
C++ Mutability & Const Correctness
Core Question
Who is allowed to change this state?
C++ defaults to Mutable. You must opt-in to safety with const.
- API Contract:
constmethods promise not to change visible state. - Physical Constness: The compiler ensures bits don't change.
- Logical Constness: You use
mutableto change hidden state (like caches) insideconstmethods.
Error → Design Question
| Issue | Design Question | |
|---|---|---|
| Discarded qualifiers | Are you trying to modify member data in a const function? | |
| Data Race | Did you modify a mutable field from multiple threads without locking? | |
| Iterator Invalidation | Are you modifying a container while reading it? |
Thinking Prompt
- Should this be `const`?
- Variables: Yes, default to
constorconstexpr. - Methods: Yes, unless it must modify state.
- Pointers:
const T*(ptr to const) vsT* const(const ptr).
- Is internal state 'invariant' or 'cache'?
- Cache/Memoization? → Use
mutable+std::mutex. - Actual state? → Non-const method.
- Is it thread-safe?
constmethods implies safe for concurrent readers.mutablemembers MUST be protected by synchronization inconstmethods.
Trace Up / Down
- Trace Up:
- Issue: "Undefined behavior in multithreaded app."
- Cause: A
constmethod modified amutablecache without a lock, assumingconstmeant safe. - Fix: Add
std::mutexto the class, lock it in theconstmethod.
- Trace Down:
- Intent: "I want a thread-safe lookup table."
- Code:
std::shared_mutexallowing multiple readers (shared_lock) and one writer (unique_lock).
Quick Reference
| Keyword | Meaning | Use When | |
|---|---|---|---|
| `const` | Read-only access | Parameters, local vars, getters. | |
| `constexpr` | Compile-time constant | Constants, array sizes. | |
| `mutable` | Modifiable in const | Caches, Mutexes within a class. | |
| `std::mutex` | Exclusive Lock | Protecting mutable state. | |
| `std::shared_mutex` | Read/Write Lock | Rare updates, frequent reads. |
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingm03-mutability/SKILL.md
Popularity
- Repository stars
- 12
- Repository forks
- 1
- 7-day trend score
- 13
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 20 Mar 2026, 8 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/13eholder/modern-cpp-skills/m03-mutability)