C++ Contracts: a Meaningfully Viable Product
summary
C++26 ships a pre/post/contract assert model with concrete rules: pre/post attach to the first declaration, repeated specs must be token-equivalent (no lambdas), post can name the return, and by-value parameters used in post must be const. Contracts run in a defined order (params init, pres, body, result init, post) and choose one of four semantics ignore/observe/enforce/quick_enforce. Violations call a global handle_contract_violation or terminate, and some checks are required at compile time.
AI-written summary · about
chapters (19)
- 0:00Introduction to C++26 contracts
- 2:03Background and controversies
- 3:50Contract types and keywords
- 9:13Bikeshedding and naming history
- 12:34Syntactic restrictions and repetition
- 15:25Constification and side effects
- 26:12Postconditions and return values
- 29:06By-value parameters in postconditions
- 31:18Contract evaluation order
- 33:28Contract semantics overview
- 36:38Semantics selection and compliance
- 39:32Elision and duplication rules
- 43:05Violation handler details
- 47:43Custom violation handlers
- 51:17Prime directive and exceptions
- 53:30Contract assert limitations
- 54:13Future of contracts and thanks
- 55:51Q&A session begins
- 1:07:40Final Q&A and conclusion
