Home | Libraries | People | FAQ | More |
BOOST_CONTRACT_INVARIANT — Program (constant) class invariants that can be completely disabled at compile-time.
// In header: <boost/contract_macro.hpp>
BOOST_CONTRACT_INVARIANT(...)
BOOST_CONTRACT_INVARIANT
({ ... }) expands to code equivalent to the following (note that no code is generated when BOOST_CONTRACT_NO_INVARIANTS
is defined):
#ifndef BOOST_CONTRACT_NO_INVARIANTS void BOOST_CONTRACT_INVARIANT_FUNC() const { ... } #endif
Where:
{ ... } is the definition of the function that checks class invariants for public functions that are not static and not volatile (see BOOST_CONTRACT_STATIC_INVARIANT
and BOOST_CONTRACT_INVARIANT_VOLATILE
). The curly parenthesis are mandatory (rationale: this is so the syntax of this macro resembles mote the syntax of the lambda functions usually used to specify preconditions, etc.). Assertions within this function are usually programmed using BOOST_CONTRACT_ASSERT
, but any exception thrown by a call to this function indicates a contract assertion failure (and will result in this library calling either boost::contract::entry_invariant_failure
or boost::contract::exit_invariant_failure
). (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.)
See Also:
Disable Contract Compilation, Class Invariants