C++26 Contracts: Introduction to Preconditions and Postconditions

In the article about Standard Library hardening, we looked at checks for invalid Standard Library container access and other broken preconditions. I mentioned that those requirements are expressed in terms of "contracts". But what about our code?
In this post, we’ll explore contracts from C++26. We’ll start with a simple cassert, move the requirement into the function itself, and see how to check results.
127 points by ibobev 6 days ago www.cppstories.com 115 comments

Summary

Learn how C++26 introduces contracts that help enforce preconditions and postconditions within your code. The article breaks down the concept with practical examples, showing how to implement these checks directly in your functions.

Comments (115 of ) ⌛

Loading more comments... ⌛
Scroll down to load more comments
No comments available.
Type to search HN and engineering blog articles
Press Escape to close  |  ↑↓ to navigate  |  Enter to open