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

This is the documentation for a snapshot of the develop branch, built from commit c5994560ca.
PrevUpHomeNext

Macro BOOST_CONTRACT_ASSERT

BOOST_CONTRACT_ASSERT — Preferred way to assert contract conditions.

Synopsis

// In header: <boost/contract/assert.hpp>

BOOST_CONTRACT_ASSERT(cond)

Description

Any exception thrown from within a contract (preconditions, postconditions, exception guarantees, old value copies at body, class invariants, etc.) is interpreted by this library as a contract failure. Therefore, users can program contract assertions manually throwing an exception when an asserted condition is checked to be false (this library will then call the appropriate contract failure handler boost::contract::precondition_failure, etc.). However, it is preferred to use this macro because it expands to code that throws boost::contract::assertion_failure with the correct assertion file name (using __FILE__), line number (using __LINE__), and asserted condition code so to produce informative error messages (C++11 __func__ is not used here because in most cases it will simply expand to the internal compiler name of the lambda function used to program the contract conditions adding no specificity to the error message).

BOOST_CONTRACT_ASSERT, BOOST_CONTRACT_ASSERT_AUDIT, and BOOST_CONTRACT_ASSERT_AXIOM are the three assertion levels predefined by this library.

See Also:

Preconditions, Postconditions, Exceptions Guarantees, Class Invariants, No Macros

Parameters:

cond

Boolean contract condition to check. (This is not a variadic macro parameter so any comma it might contain must be protected by round parenthesis and BOOST_CONTRACT_ASSERT((cond)) will always work.)


PrevUpHomeNext