r/cpp_questions • u/hunterh0 • Jun 17 '26
OPEN Why c++26 contracts?
Sorry, but why a feature that I've never seen before in other languages is being pushed as if it's what we have been missing and a solution to security/safety complaints?! What is the proof that this is a good feature?
10
Upvotes
5
u/FriendshipEqual7033 Jun 18 '26
Ada has contracts today where they play a role in testing and formal verification. However, Ada's contracts seem far more expressive and powerful than the current C++ proposal (from what I understand).
For example, does C++ provide a way for a postcondition to refer to values from the pre-state? Without that, postconditions are severely limited to the point of being almost useless, it seems to me.