ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
Contract.h

The contracts of ADS. More...

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

Detailed description

The contracts of ADS.

The definitions, the invariants and the costs of the area are in Theory of the foundations.

Macro definition documentation

◆ ADS_AUDIT

#define ADS_AUDIT ( cond)
Value:
ADS_CONTRACT_CHECK( 3, "audit", cond )
#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: c...
Definition Contract.h:112

a precondition or a postcondition dearer than the operation, checked from level 3

◆ ADS_CONTRACT_CHECK

#define ADS_CONTRACT_CHECK ( level,
kind,
cond )
Value:
do { \
if constexpr( ADS_CONTRACTS >= ( level ) ) \
if( ! ( cond ) ) \
::ADS::detail::violated( kind, #cond, __func__, __FILE__, __LINE__ ); \
} while( false )
#define ADS_CONTRACTS
the level of the contracts checked: 0 none, 1 preconditions, 2 postconditions, 3 invariants and audit...
Definition Contract.h:71

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]

◆ ADS_CONTRACTS

#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

◆ ADS_INVARIANT

#define ADS_INVARIANT ( cond)
Value:
ADS_CONTRACT_CHECK( 3, "invariant", cond )

an invariant, checked from level 3

◆ ADS_POST

#define ADS_POST ( cond)
Value:
ADS_CONTRACT_CHECK( 2, "postcondition", cond )

a postcondition, checked from level 2

◆ ADS_PRE

#define ADS_PRE ( cond)
Value:
ADS_CONTRACT_CHECK( 1, "precondition", cond )

[check]

a precondition, checked from level 1