Building C++ Interfaces That Are Hard to Use Incorrectly
summary
Collection of concrete techniques that push precondition checks from run-time to compile-time using the C++ type system: use scoped enums and tag‑typed opaque handles to prevent mixing unrelated integers, wrap pointer+size as span or a small struct with C++20 designated initialization to avoid swapped args, prefer declarative formats over fiddly offsets for vertex/graphics data, use std::visit with an overload wrapper to force exhaustive variant handling, encode nullable or NUL‑terminated strings with GSL types, enforce contexts with access/execution tokens, and adopt std::expected (C++23) for clearer error paths.
AI-written summary · about
chapters (16)
- 0:00Introduction
- 1:04Robust library interface design
- 6:29Precondition violations
- 17:37Incorrect usage patterns
- 25:24Preventing misuse with types
- 30:01OpenGL API with scoped enums
- 37:58Opaque types with scoped enums
- 41:58Advanced opaque type patterns
- 48:19Function arguments clarity
- 55:48Structured data with std::variant
- 1:04:26Null safety and strings
- 1:08:46Privileged access tokens
- 1:13:00Declarative API design
- 1:20:12Two-phase initialization
- 1:25:10Execution tokens
- 1:30:30Summary








