...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::contract::check — RAII object that checks the contracts.
// In header: <boost/contract/check.hpp> class check { public: // construct/copy/destruct template<typename F> check(F const &); check(check const &); template<typename VirtualResult> check(specify_precondition_old_postcondition_except< VirtualResult > const &); template<typename VirtualResult> check(specify_old_postcondition_except< VirtualResult > const &); template<typename VirtualResult> check(specify_postcondition_except< VirtualResult > const &); check(specify_except const &); check(specify_nothing const &); ~check(); };
In general, when this object is constructed it checks class invariants at entry, preconditions, and makes old value copies at body. When it is destructed, it checks class invariants at exist, postconditions, and exception guarantees. This object enforces the following (see Contract Programming Overview):
Postconditions are checked only if the body does not throw an exception.
Exceptions guarantees are checked only if the body throws an exception.
Constructor entry never checks class invariants.
Destructor exit checks class invariants only if the body throws an exception (even if destructors should usually not be programmed to throw exceptions in C++).
Static invariants are always checked at entry and exit (and regardless of the body throwing exceptions or not).
When used this way, this object is usually constructed and initialized to the return value of one of the contract functions boost::contract::function
, boost::contract::constructor
, boost::contract::destructor
, or boost::contract::public_function
. In addition, this object can be constructed from a nullary functor that is used to program implementation checks.
See Also:
Tutorial, Implementation Checks
check
public
construct/copy/destructtemplate<typename F> check(F const & f);Construct this object for implementation checks.
This can be used to program checks within implementation code (body, etc.). This constructor is not declared explicit
so initializations can use assignment syntax =
.
Throws: This can throw in case programmers specify contract failure handlers that throw exceptions instead of terminating the program (see Throw on Failure).
Parameters: |
|
check(check const & other);Construct this object copying it from the specified one.
This object will check the contract, the copied-from object will not (i.e., contract check ownership is transferred from the copied object to the new object being created by this constructor).
Parameters: |
|
template<typename VirtualResult> check(specify_precondition_old_postcondition_except< VirtualResult > const & contract);Construct this object to check the specified contract.
This checks class invariants at entry (if those apply to the specified contract). This constructor is not declared explicit
so initializations can use assignment syntax =
.
Throws: This can throw in case programmers specify contract failure handlers that throw exceptions instead of terminating the program (see Throw on Failure).
Parameters: |
|
||
Template Parameters: |
|
template<typename VirtualResult> check(specify_old_postcondition_except< VirtualResult > const & contract);Construct this object to check the specified contract.
This checks class invariants at entry and preconditions (if any of those apply to the specified contract). This constructor is not declared explicit
so initializations can use assignment syntax =
.
Throws: This can throw in case programmers specify contract failure handlers that throw exceptions instead of terminating the program (see Throw on Failure).
Parameters: |
|
||
Template Parameters: |
|
template<typename VirtualResult> check(specify_postcondition_except< VirtualResult > const & contract);Construct this object to check the specified contract.
This checks class invariants at entry and preconditions then it makes old value copies at body (if any of those apply to the specified contract). This constructor is not declared explicit
so initializations can use assignment syntax =
.
Throws: This can throw in case programmers specify contract failure handlers that throw exceptions instead of terminating te program (see Throw on Failure).
Parameters: |
|
||
Template Parameters: |
|
check(specify_except const & contract);Construct this object to check the specified contract.
This checks class invariants at entry and preconditions then it makes old value copies at body, plus the destructor of this object will check postconditions in this case (if any of those apply to the specified contract). This constructor is not declared explicit
so initializations can use assignment syntax =
.
Throws: This can throw in case programmers specify contract failure handlers that throw exceptions instead of terminating the program (see Throw on Failure).
Parameters: |
|
check(specify_nothing const & contract);Construct this object to check the specified contract.
This checks class invariants at entry and preconditions then it makes old value copies at body, plus the destructor of this object will check postconditions and exception guarantees in this case (if any of those apply to the specified contract). This constructor is not declared explicit
so initializations can use assignment syntax =
.
Throws: This can throw in case programmers specify contract failure handlers that throw exceptions instead of terminating the program (see Throw on Failure).
Parameters: |
|
~check();Destruct this object.
This checks class invariants at exit and either postconditions when the enclosing function body did not throw an exception, or exception guarantees when the function body threw an exception (that is if class invariants, postconditions, and exception guarantees respectively apply to the contract parameter specified when constructing this object).
Throws: This can throw in case programmers specify contract failure handlers that throw exceptions instead of terminating the program (see
Throw on Failure). (This is declared noexcept(false)
since C++11.)