Contracts for C++

Timur Doumler

⏱ 90 minute session
beginner
intermediate
14:00-15:30, Tuesday, 1st April 2025
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.

Timur Doumler

Timur Doumler is the co-host of CppCast and an active member of the ISO C++ standard committee, where he is currently co-chair of SG21, the Contracts study group. Timur started his journey into C++ in computational astrophysics, where he was working on cosmological simulations. After completing his PhD in astrophysics, he moved into the audio and music technology industry, where he has been working for over a decade and co-founded the music tech startup Cradle. In the past, Timur also worked for JetBrains, first as a developer on CLion's C++ parser and later as a Developer Advocate for C++ developer tools. Currently, Timur lives in Finland, where he is organising the monthly C++ Helsinki meetup. Timur is passionate about clean code, good tools, low latency, and the evolution of the C++ language.