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-mutability

SKILL.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: const methods promise not to change visible state.
  • Physical Constness: The compiler ensures bits don't change.
  • Logical Constness: You use mutable to change hidden state (like caches) inside const methods.

Error → Design Question

IssueDesign Question
Discarded qualifiersAre you trying to modify member data in a const function?
Data RaceDid you modify a mutable field from multiple threads without locking?
Iterator InvalidationAre you modifying a container while reading it?

Thinking Prompt

  1. Should this be `const`?
  • Variables: Yes, default to const or constexpr.
  • Methods: Yes, unless it must modify state.
  • Pointers: const T* (ptr to const) vs T* const (const ptr).
  1. Is internal state 'invariant' or 'cache'?
  • Cache/Memoization? → Use mutable + std::mutex.
  • Actual state? → Non-const method.
  1. Is it thread-safe?
  • const methods implies safe for concurrent readers.
  • mutable members MUST be protected by synchronization in const methods.

Trace Up / Down

  • Trace Up:
  • Issue: "Undefined behavior in multithreaded app."
  • Cause: A const method modified a mutable cache without a lock, assuming const meant safe.
  • Fix: Add std::mutex to the class, lock it in the const method.
  • Trace Down:
  • Intent: "I want a thread-safe lookup table."
  • Code: std::shared_mutex allowing multiple readers (shared_lock) and one writer (unique_lock).

Quick Reference

KeywordMeaningUse When
`const`Read-only accessParameters, local vars, getters.
`constexpr`Compile-time constantConstants, array sizes.
`mutable`Modifiable in constCaches, Mutexes within a class.
`std::mutex`Exclusive LockProtecting mutable state.
`std::shared_mutex`Read/Write LockRare 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

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
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/13eholder/modern-cpp-skills/m03-mutability/badge)](https://verified-skill.com/skills/13eholder/modern-cpp-skills/m03-mutability)

Something wrong with this skill or its page? Tell us.