Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

PrevUpHomeNext

Class check

boost::contract::check — RAII object that checks the contracts.

Synopsis

// 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();
};

Description

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++ and they are implicitly declared noexcept since C++11).

  • 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 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 to that, this object can be constructed from a nullary functor when it is used to program implementation checks.

See Also:

Tutorial, Implementation Checks

check public construct/copy/destruct

  1. template<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:

    f

    Nullary functor that asserts implementation checks. f() will be called as soon as this object is constructed at the point it is declared within the implementation code (see Implementation Checks).

  2. 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:

    other

    Copied-from object.

  3. 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 were specified for the given 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:

    contract

    Contract to be checked (usually the return value of boost::contract::function or boost::contract::public_function).

    Template Parameters:

    VirtualResult

    Return type of the enclosing function declaring the contract if that is either a virtual or an overriding public function, otherwise this is always void. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.)

  4. 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 were specified for the given 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:

    VirtualResult

    Return type of the enclosing function declaring the contract if that is either a virtual or an overriding public function, otherwise this is always void. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.)

  5. 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 were specified for the given 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:

    VirtualResult

    Return type of the enclosing function declaring the contract if that is either a virtual or an overriding public function, otherwise this is always void. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.)

  6. 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 also check postconditions in this case (if any of those were specified for the given 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:

  7. 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 also check postconditions and exception guarantees in this case (if any of those were specified for the given 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:

  8. ~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 (if class invariants, postconditions, and exception guarantees respectively were specified for the enclosing class and the contract parameter given 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.)


PrevUpHomeNext