Appendix C

Contracts

First of all: What is a contract? A contract specifies, in a precise and checkable way, interfaces for software components. These software components are typically functions and member functions that have to fulfill preconditions, postconditions, and invariants. We may get contracts with C++23.

By default, a violation of a contract terminates the program.

Here are the simplified definitions from the C++ proposal P0380r1.

Preconditions, postconditions, and invariants

precondition

A precondition is a predicate that is supposed to hold upon entry in a function.

postcondition

A postcondition is a predicate that is supposed to hold upon exit from the function.

invariant

An invariant is a predicate that is supposed to hold ...

Get C++ Core Guidelines Explained: Best Practices for Modern C++ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.