Boost C++ Libraries 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 an old version of boost. Click here for the latest Boost documentation.


BOOST_CONTRACT_POSTCONDITION — Program postconditions that can be completely disabled at compile-time.


// In header: <boost/contract_macro.hpp>



BOOST_CONTRACT_POSTCONDITION(f) expands to code equivalent to the following (note that no code is generated when BOOST_CONTRACT_NO_POSTCONDITIONS is defined):



  • f is the functor called by this library to check postconditions f() or f(result). Assertions within this functor are usually programmed using BOOST_CONTRACT_ASSERT, but any exception thrown by a call to this functor indicates a contract assertion failure (and will result in this library calling boost::contract::postcondition_failure). This functor should capture variables by (constant) references (to access the values they will have at function exit). This functor takes the return value (preferably by const&) result as its one single parameter f(result) but only for virtual public functions and public functions overrides, otherwise it takes no parameter f(). (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.)

See Also:

Disable Contract Compilation, Postconditions