|
ADS
Algorithms and Data Structures
|
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: More...
#include <concepts>#include <optional>#include <stdexcept>#include <string>Go to the source code of this file.
Classes | |
| class | ADS::contract_violation |
| a contract violated: a bug of the caller (a precondition) or of ADS More... | |
Namespaces | |
| namespace | ADS |
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 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:
The level ADS_CONTRACTS chooses which are checked: 0 none, 1 the preconditions (the default, 0 when NDEBUG is defined, as for assert), 2 also the postconditions, 3 also the invariants and the audits. A violated contract throws ADS::contract_violation, a std::logic_error whose message names the kind of contract, the condition, the function and the place in the source. The conditions are compiled at every level, so that they stay correct C++, but they are not evaluated above the level chosen; hence they must have no side effects.