m03-mutability/SKILL.md
Mastering C++ Const Correctness and Mutability. Triggers: const, mutable, logically const, bitwise const, data race, mutex, shared_mutex, thread safety.
npx skillsauth add 13eholder/modern-cpp-skills m03-mutabilityInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Who is allowed to change this state?
C++ defaults to Mutable. You must opt-in to safety with const.
const methods promise not to change visible state.mutable to change hidden state (like caches) inside const methods.| 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? |
Should this be const?
const or constexpr.const T* (ptr to const) vs T* const (const ptr).Is internal state 'invariant' or 'cache'?
mutable + std::mutex.Is it thread-safe?
const methods implies safe for concurrent readers.mutable members MUST be protected by synchronization in const methods.Trace Up:
const method modified a mutable cache without a lock, assuming const meant safe.std::mutex to the class, lock it in the const method.Trace Down:
std::shared_mutex allowing multiple readers (shared_lock) and one writer (unique_lock).| 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. |
tools
Common C++ Anti-Patterns. Triggers: global variables, new/delete, C-style cast, macros, void*.
data-ai
C++ Mental Models: Pointer vs Reference, Initialization, Undefined Behavior.
data-ai
Mastering C++ Domain Errors: Exception Hierarchies, System Errors, and Expected.
data-ai
Mastering C++ Lifecycle: RAII, Destructors, Static Initialization, Rule of 5.