|
ADS
Algorithms and Data Structures
|
Files | |
| file | ADS/Contract.h |
| The contracts of ADS: the preconditions, the postconditions and the invariants of the operations, checked at run time by four macros that mirror the contracts of C++26 (pre, post and contract_assert), so that they can be replaced by them when the compilers support them: | |
Classes | |
| class | ADS::contract_violation |
| a contract violated: a bug of the caller (a precondition) or of ADS More... | |
Macros | |
| #define | ADS_CONTRACTS 1 |
| the level of the contracts checked: 0 none, 1 preconditions, 2 postconditions, 3 invariants and audits; 1 by default, 0 with NDEBUG | |
| #define | ADS_CONTRACT_CHECK(level, kind, cond) |
| the check of the condition cond, a contract of the kind kind, when ADS_CONTRACTS is at least level: contract_violation if it is false | |
| #define | ADS_PRE(cond) |
| [check] | |
| #define | ADS_POST(cond) |
| a postcondition, checked from level 2 | |
| #define | ADS_INVARIANT(cond) |
| an invariant, checked from level 3 | |
| #define | ADS_AUDIT(cond) |
| a precondition or a postcondition dearer than the operation, checked from level 3 | |
The contracts of ADS.
The definitions, the invariants and the costs of the area are in Theory of the foundations.
| #define ADS_AUDIT | ( | cond | ) |
a precondition or a postcondition dearer than the operation, checked from level 3
| #define ADS_CONTRACT_CHECK | ( | level, | |
| kind, | |||
| cond ) |
the check of the condition cond, a contract of the kind kind, when ADS_CONTRACTS is at least level: contract_violation if it is false
In pseudocode, the test of the level made at compile time:
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{check}( \mathit{level} , \mathit{kind} , \mathit{cond} ) \cr 2 & \quad \textbf{if}\ \mathtt{ADS\_CONTRACTS} \ge \mathit{level} \ \textbf{then}\quad \triangleright\ \mathtt{if\ constexpr} \cr 3 & \qquad \textbf{if not}\ \mathit{cond}\ \textbf{then} \ \mathrm{violated}( \mathit{kind} , \text{the text of } \mathit{cond} , \text{the function, the file, the line} ) \end{array}} \]
[check]
| #define ADS_CONTRACTS 1 |
the level of the contracts checked: 0 none, 1 preconditions, 2 postconditions, 3 invariants and audits; 1 by default, 0 with NDEBUG
| #define ADS_INVARIANT | ( | cond | ) |
an invariant, checked from level 3
| #define ADS_POST | ( | cond | ) |
a postcondition, checked from level 2
| #define ADS_PRE | ( | cond | ) |