How to Hide C++ Implementation Details
summary
Shows concrete failures and fixes: why public data members like std::pair and struct fields bite generic code, how to let callers mutate map values but not keys via a wrap associative containers pattern, when Concepts help and when a lightweight wrapper is safer, how to hide smart‑pointer use behind value semantics, and a practical private token idiom to keep constructors usable by a factory. Includes a concrete gotcha about vector<bool> proxy behavior and testable recipes that developers can copy.
AI-written summary · about
chapters (27)
- 0:00Introduction
- 0:27Why hide implementation
- 1:28Benefits of information hiding
- 3:44Why hiding is difficult
- 5:52Exposing private details
- 8:11Technical constraints
- 9:39Pair design pitfalls
- 13:14Data members in structs
- 16:08Handling constant members
- 18:58API design philosophy
- 21:04Reducing cognitive load
- 23:03Context specific interfaces
- 25:20Tools for hiding details
- 28:00Concepts in C++20
- 30:56Refining mutable concepts
- 33:28Wrapper class approach
- 36:23Hiding smart pointers
- 38:47Value semantics in expression trees
- 40:32Inheritance vs state pattern
- 42:53Strategy pattern and factories
- 44:46Leaky abstractions
- 47:04Using concepts for return types
- 50:05Hiding sequential dependencies
- 52:11Protected members
- 54:43Testing private behavior
- 57:15Private token idiom
- 59:07Summary and conclusion
related talks
01h 00mThe hidden rules of world-class C++ code
01h 11mPragmatic Simplicity - Actionable Guidelines To Tame Cpp Complexity
51mSimplicity: Not Just for Beginners
56mC++ Code Smells
50mPruning Error Messages From C++ Template Code
01h 05mBetter Code: Contracts in C++
06mLightning Talk: Best Practices Every C++ Programmer Needs to Follow
52mThe Code is Documentation Enough
