...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::function — Program contracts for non-member, private and protected functions.
// In header: <boost/contract/function.hpp> specify_precondition_old_postcondition_except function();
This is used to specify preconditions, postconditions, exception guarantees, and old value copies at body for non-member, private and protected functions (these functions never check class invariants, see Function Calls):
void f(...) { boost::contract::old_ptr<old_type> old_var; boost::contract::check c = boost::contract::function() .precondition([&] { // Optional. BOOST_CONTRACT_ASSERT(...); ... }) .old([&] { // Optional. old_var = BOOST_CONTRACT_OLDOF(old_expr); ... }) .postcondition([&] { // Optional. BOOST_CONTRACT_ASSERT(...); ... }) .except([&] { // Optional. BOOST_CONTRACT_ASSERT(...); ... }) ; ... // Function body. }
This can be used also to program contracts in implementation code for lambda functions, loops, and arbitrary blocks of code. For optimization, this can be omitted for code that does not have preconditions, postconditions, and exception guarantees.
See Also:
Non-Member Functions, Private and Protected Functions, Lambdas, Loops, Code Blocks
Returns: |
The result of this function must be explicitly assigned to a variable of type |