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 master branch, built from commit 97da996172.
PrevUpHomeNext

Macro BOOST_CONTRACT_OLD_PTR

BOOST_CONTRACT_OLD_PTR — Program old values that can be completely disabled at compile-time for old value types that are required to be copyable.

Synopsis

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

BOOST_CONTRACT_OLD_PTR(...)

Description

This is used to program old value copies for copyable types:

class u {
public:
    void f(...) {
        BOOST_CONTRACT_OLD_PTR(old_type_a)(old_var_a); // Null...
        BOOST_CONTRACT_OLD_PTR(old_type_b)(old_var_b, old_expr_b); // Set.
        BOOST_CONTRACT_PUBLIC_FUNCTION(this)
            ...
            BOOST_CONTRACT_OLD([&] {
                old_var_a = BOOST_CONTRACT_OLDOF(old_expr_a); // ...set.
                ...
            })
            ...
        ;

        ... // Function body.
    }

    virtual void g(..., boost::contract::virtual_* v = 0) {
        BOOST_CONTRACT_OLD_PTR(old_type_a)(old_var_a); // No `v`
        BOOST_CONTRACT_OLD_PTR(old_type_b)(v, old_var_b, old_expr_b); // `v`
        BOOST_CONTRACT_PUBLIC_FUNCTION(v, this)
            ...
            BOOST_CONTRACT_OLD([&] {
                old_var_a = BOOST_CONTRACT_OLDOF(v, old_expr_a); // `v`
                ...
            })
            ...
        ;

        ... // Function body.
    }

    ...
};

This is an overloaded variadic macro and it can be used in the following different ways (note that no code is generated when BOOST_CONTRACT_NO_OLDS is defined).

1. BOOST_CONTRACT_OLD_PTR(old_type)(old_var) expands to code equivalent to the following (this leaves the old value pointer null):

#ifndef BOOST_CONTRACT_NO_OLDS
    // This declaration does not need to use `v`.
    boost::contract::old_ptr<old_type> old_var
#endif

2. BOOST_CONTRACT_OLD_PTR(old_type)(old_var, old_expr) expands to code equivalent to the following (this initializes the pointer to the old value copy, but not to be used for virtual public functions and public function overrides):

#ifndef BOOST_CONTRACT_NO_OLDS
    boost::contract::old_ptr<old_type> old_var =
            BOOST_CONTRACT_OLDOF(old_expr)
#endif

3. BOOST_CONTRACT_OLD_PTR(old_type)(v, old_var, old_expr) expands to code equivalent to the following (this initializes the pointer to the old value copy for virtual public functions and public function overrides):

#ifndef BOOST_CONTRACT_NO_OLDS
    boost::contract::old_ptr<old_type> old_var =
            BOOST_CONTRACT_OLDOF(v, old_expr)
#endif

Where:

  • old_type is the type of the pointed old value. This type must be copyable (i.e., boost::contract::is_old_value_copyable<old_type>::value is true), otherwise this pointer will always be null and this library will generate a compile-time error when the pointer is dereferenced (see BOOST_CONTRACT_OLD_PTR_IF_COPYABLE). (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.) (Rationale: Template parameters like this one are specified to this library macro interface using their own set of parenthesis SOME_MACRO(template_params)(other_params).)

  • v is the extra training parameter of type boost::contract::virtual_* and default value 0 from the enclosing virtual public function or public function override declaring the contract. (This is not a variadic macro parameter but it should never contain commas because it is an identifier.)

  • old_var is the name of the old value pointer variable. (This is not a variadic macro parameter but it should never contain commas because it is an identifier.)

  • old_expr is the expression to be evaluated and copied in the old value pointer. (This is not a variadic macro parameter so any comma it might contain must be protected by round parenthesis and BOOST_CONTRACT_OLD_PTR(old_type)(v, old_var, (old_expr)) will always work.)

See Also:

Disable Contract Compilation, Old Values


PrevUpHomeNext