By Timur Doumler
In this talk, we present contract assertions, a new language feature recently approved for the upcoming C++26 standard after more than two decades of gestation. This feature provides a superior replacement for assertion macros and, when used correctly, can significantly improve the safety and correctness of your code. Contract assertions are designed to have a wide range of applicability with minimal impediments to their adoption in any C++ codebase of any coding style and any quality, so we expect them to become a widely used feature across the ecosystem once C++26 is adopted.
We will cover precondition and postcondition assertions, assertion statements, selection of evaluation semantics, contract-violation handling, and much more, showing use cases and code examples. Then, we will discuss the theoretical underpinnings and design principles behind contract assertions in C++, and compare them with contract facilities in other programming languages such as Eiffel, D, and Ada. Finally, we will present extensions to contract assertions that are being developed for the post-C++26 timeframe and will make the feature even more powerful and able to cover even more use cases.










