...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::public_function — Program contracts for void public functions overrides (virtual or not).
// In header: <boost/contract/public_function.hpp> template<typename Override, typename F, typename Class, typename... Args> specify_precondition_old_postcondition_except public_function(virtual_ * v, F f, Class * obj, Args &... args);
This is used to specify preconditions, postconditions, exception guarantees, old value copies at body, and check class invariants for public function overrides (virtual or not) that return void:
class u #define BASES private boost::contract::constructor_precondition<u>, \ public b, private w : BASES { friend class boost::contract::access; typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; #undef BASES void invariant() const { // Optional (as for static and volatile). BOOST_CONTRACT_ASSERT(...); ... } BOOST_CONTRACT_OVERRIDES(f) public: // Override from `b::f`. void f(t_1 a_1, ..., t_n a_n, boost::contract::virtual_* v = 0) { boost::contract::old_ptr<old_type> old_var; boost::contract::check c = boost::contract::public_function< override_f>(v, &u::f, this, a_1, ..., a_n) .precondition([&] { // Optional. BOOST_CONTRACT_ASSERT(...); ... }) .old([&] { // Optional. old_var = BOOST_CONTRACT_OLDOF(v, old_expr); ... }) .postcondition([&] { // Optional. BOOST_CONTRACT_ASSERT(...); ... }) .except([&] { // Optional. BOOST_CONTRACT_ASSERT(...); ... }) ; ... // Function body. } ... };
A public function override should always call
otherwise this library will not be able to correctly use it for subcontracting.boost::contract::public_function
See Also:
Parameters: |
|
||||||||
Template Parameters: |
|
||||||||
Returns: |
The result of this function must be explicitly assigned to a variable of type |