On coding guidelines, class invariants, and special member functions
summary
Covers five concrete C++ guidelines applied to a templated interval type: constructor checks for low<=high, switching to class to enforce a class invariant, and wrestling with the rule of zero versus hand-implemented move/copy to preserve invariants. Demonstrates options: constrain T, implement noexcept moves, or add a valueless-by-move flag; shows copy-and-swap to get strong exception safety. Reproduces a GCC bug where defaulted memberwise copy assignment breaks flat_set invariants, uses clang-tidy checks in practice, and ends on pragmatic teaching choices.
AI-written summary · about
chapters (10)
- 0:00Introduction and context
- 4:30Exceptions and error handling
- 9:44Class invariants with struct vs class
- 12:13Rule of zero and special member functions
- 15:44Move operations and valid states
- 24:54Standard library aside: std::indirect
- 28:08Exception safety guarantees
- 34:33Standard library aside: flat_set
- 40:35Current teaching and trade-offs
- 50:31Q&A session
