# Reference

Include all header files required by this library at once (for convenience).

All header files `boost/contract/*.hpp` are independent from one another and can be included one-by-one to reduce the amount of code to compile from this library in user code (but this was measured to not make an appreciable difference in compile-time so `boost/contract.hpp` can be included directly in most cases). Instead the headers `boost/contract/core/*.hpp` are not independent from other library headers and they are automatically included by the `boost/contract/*.hpp` headers (so the `boost/contract/core/*.hpp` headers are usually not directly included by programmers).

All files under the `boost/contract/detail/` directory, names within the `boost::contract::detail` namespace, names prefixed by `boost_contract_detail`... and `BOOST_CONTRACT_DETAIL`... (in any namesapce, including user's code) are reserved for internal use of this library and should never be used directly by programmers.

# See Also:

Getting Started

Assert contract conditions.

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.)

Preferred way to assert contract conditions.

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

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_AUDIT((cond))` will always work.)

Preferred way to assert contract conditions that are computationally expensive, at least compared to the computational cost of executing the function body.

The asserted condition will always be compiled and validated syntactically, but it will not be checked at run-time unless `BOOST_CONTRACT_AUDITS` is defined (undefined by default). This macro is defined by code equivalent to:

    #ifdef BOOST_CONTRACT_AUDITS
        #define BOOST_CONTRACT_ASSERT_AUDIT(cond) \
            BOOST_CONTRACT_ASSERT(cond)
    #else
        #define BOOST_CONTRACT_ASSERT_AUDIT(cond) \
            BOOST_CONTRACT_ASSERT(true || cond)
    #endif

`BOOST_CONTRACT_ASSERT`, `BOOST_CONTRACT_ASSERT_AUDIT`, and `BOOST_CONTRACT_ASSERT_AXIOM` are the three assertion levels predefined by this library. If there is a need, programmers are free to implement their own assertion levels defining macros similar to the one above.

# See Also:

Assertion Levels, No Macros

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_AXIOM((cond))` will always work.)

Preferred way to document in the code contract conditions that are computationally prohibitive, at least compared to the computational cost of executing the function body.

The asserted condition will always be compiled and validated syntactically, but it will never be checked at run-time. This macro is defined by code equivalent to:

    #define BOOST_CONTRACT_ASSERT_AXIOM(cond) \
        BOOST_CONTRACT_ASSERT(true || cond)

`BOOST_CONTRACT_ASSERT`, `BOOST_CONTRACT_ASSERT_AUDIT`, and `BOOST_CONTRACT_ASSERT_AXIOM` are the three assertion levels predefined by this library. If there is a need, programmers are free to implement their own assertion levels defining macros similar to the one above.

# See Also:

Assertion Levels, No Macros

Specify inheritance form base classes (for subcontracting).

Comma separated list of base classes. Each base must explicitly specify its access specifier `public`, `protected`, or `private`, and also `virtual` when present (this not always required in C++ instead). There is a limit of about 20 maximum bases that can be listed (because of similar limits in Boost.MPL internally used by this library). This is a variadic macro parameter, on compilers that do not support variadic macros, the `typedef` for base classes can be programmed manually without using this macro (see No Macros).

Used to program the `typedef` that lists the bases of a derived class.

In order to support subcontracting, a derived class that specifies contracts for one or more overriding public functions must declare a `typedef` named `base_types` (or `BOOST_CONTRACT_BASES_TYPEDEF`) using this macro: @code class u #define BASES public b, protected virtual w1, private w2 : BASES { friend class boost::contract:access;

typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; #undef BASES

... }; @endcode This `typedef` must be `public` unless ``boost::contract::access`` is used.

# See Also:

Base Classes

Statically disable compilation and execution of functor calls.

These facilities allow to emulate C++17 `if constexpr` statements when used together with functor templates (and C++14 generic lambdas). Therefore, they are not useful on C++17 compilers where `if constexpr` can be directly used instead.

bool

Static boolean predicate that selects which functor template call to compile and execute.

Type of the functor template to call if the static predicate `Pred` is `true`.

internal_type

Return type of then-branch functor template call (this is usually automatically deduced by this library so it is never explicitly specified by the user, and that is why it is often marked as `internal_type` in this documentation).

Select compilation and execution of functor template calls using a static boolean predicate (not needed on C++17 compilers, use `if constexpr` instead).

This class template has no members because it is never used directly, it is only used via its specializations. Usually this class template is instantiated only via the return value of `boost::contract::call_if` and `boost::contract::call_if_c`.

# See Also:

Assertion Requirements

Type of functor template to call when the static predicate is `true` (never the case for this template specialization).

false
Then
internal_type
Template specialization to handle static predicates that are `false` (not needed on C++17 compilers, use `if constexpr` instead).

This template specialization handles all else-branch functor template calls (whether they return void or not). Usually this class template is instantiated only via the return value of `boost::contract::call_if` and `boost::contract::call_if_c`.

# See Also:

Assertion Requirements

Then const &

Then-branch nullary functor template. The functor template call `f()` is never compiled or executed for this template specialization (because the if-statement static predicate is `false`). The return type of `f()` must be the same as (or implicitly convertible to) the return type of all other functor template calls specified for this call-if object.

Construct this object with the then-branch functor template.

result_of< Else()>::type `Else

Else-branch nullary functor template. The functor template call `f()` is actually compiled and executed for this template specialization (because the if-statement static predicate is `false`). The return type of `f()` must be the same as (or implicitly convertible to) the return type of all other functor template calls specified for this call-if object.

` Specify the else-branch functor template.

The `result_of<Else()>::type` expression needs be evaluated only when the static predicate is already checked to be `false` (because `Else()` is required to compile only in that case). Thus, this result-of expression is evaluated lazily and only in instantiations of this template specialization.

A copy of the value returned by the call to the else-branch functor template `f()`.

`call_if_statement`< ElseIfPred, ElseIfThen > bool

Static boolean predicate selecting which functor template call to compile and execute.

ElseIfThen

Else-if-branch nullary functor template. The functor template call `f()` is actually compiled and executed if and only if `ElseIfPred` is `true` (because the if-statement static predicate is already `false` for this template specialization). The return type of `f()` must be the same as (or implicitly convertible to) the return type of all other functor template calls specified for this call-if object.

Specify an else-if-branch functor template (using a static boolean predicate).

A call-if statement so the else statement and additional else-if statements can be specified if needed. Eventually, this will be the return value of the one functor template call being compiled and executed.

`call_if_statement`< ElseIfPred::value, ElseIfThen >

Nullary boolean meta-function selecting which functor template call to compile and execute.

ElseIfThen

Else-if-branch nullary functor template. The functor template call `f()` is actually compiled and executed if and only if `ElseIfPred::value` is `true` (because the if-statement static predicate is already `false` for this template specialization). The return type of `f()` must be the same as (or implicitly convertible to) the return type of all other functor template calls specified for this call-if object.

Specify an else-if-branch functor template (using a nullary boolen meta-function).

A call-if statement so the else statement and additional else-if statements can be specified if needed. Eventually, this will be the return value of the one functor template call being compiled and executed.

Type of functor template to call when the static predicate is `true` (as it is for this template specialization).

true
Then
internal_type
boost::contract::call_if_statement< true, Then, result_of< Then()>::type >
Template specialization to dispatch between then-branch functor template calls that return void and the ones that return non-void (not needed on C++17 compilers, use `if constexpr` instead).

The base class is a call-if statement so the else and else-if statements can be specified if needed. Usually this class template is instantiated only via the return value of `boost::contract::call_if` and `boost::contract::call_if_c`.

The `result_of<Then()>::type` expression needs be evaluated only when the static predicate is already checked to be `true` (because `Then()` is required to compile only in that case). Thus, this template specialization introduces an extra level of indirection necessary for proper lazy evaluation of this result-of expression.

# See Also:

Assertion Requirements

Then

Then-branch nullary functor template. The functor template call `f()` is compiled and called for this template specialization (because the if-statement static predicate is `true`). The return type of `f()` must be the same as (or implicitly convertible to) the return type of all other functor template calls specified for this call-if object.

Construct this object with the then-branch functor template.

Type of functor template to call when the static predicate is `true` (as it is for this template specialization).

Non-void return type of the then-branch functor template call.

true
Then
ThenResult
Template specialization to handle static predicates that are `true` for then-branch functor template calls that do not return void (not needed on C++17 compilers, use `if constexpr` instead).

Usually this class template is instantiated only via the return value of `boost::contract::call_if` and `boost::contract::call_if_c`.

# See Also:

Assertion Requirements

Then

Then-branch nullary functor template. The functor template call `f()` is actually compiled and executed for this template specialization (because the if-statement static predicate is `true`). The return type of `f()` must be the same as (or implicitly convertible to) the `ThenResult` type.

Construct this object with the then-branch functor template.

ThenResult This implicit type conversion returns a copy of the value returned by the call to the then-branch functor template.
ThenResult `Else const &

Else-branch nullary functor template. The functor template call `f()` is never compiled or executed for this template specialization (because the if-statement static predicate is `true`). The return type of `f()` must be the same as (or implicitly convertible to) the `ThenResult` type.

` Specify the else-branch functor template.

A copy of the value returned by the call to the then-branch functor template (because the else-branch functor template call is not executed).

`call_if_statement`< true, Then, ThenResult > bool

Static boolean predicate selecting which functor template call to compile and execute.

ElseIfThen const &

Else-if-branch nullary functor template. The functor template call `f()` is never compiled or executed for this template specialization (because the if-statement static predicate is `true`). The return type of `f()` must be the same as (or implicitly convertible to) the `ThenResult` type.

Specify an else-if-branch functor template (using a static boolean predicate).

A call-if statement so the else statement and additional else-if statements can be specified if needed. Eventually, it will be the return value of the then-branch functor template call for this template specialization (because the if-statement static predicate is `true`).

`call_if_statement`< true, Then, ThenResult >

Nullary boolean meta-function selecting which functor template call to compile and execute.

ElseIfThen const &

Else-if-branch nullary functor template. The functor template call `f()` is never compiled or executed for this template specialization (because the if-statement static predicate is `true`). The return type of `f()` must be the same as (or implicitly convertible to) the `ThenResult` type.

Specify an else-if-branch functor template (using a nullary boolean meta-function).

A call-if statement so the else statement and additional else-if statements can be specified if needed. Eventually, it will be the return value of the then-branch functor template call for this template specialization (because the if-statement static predicate is `true`).

Type of functor template to call when the static predicate if `true` (as it is for this template specialization).

true
Then
void
Template specialization to handle static predicates that are `true` for then-branch functor template calls that return void (not needed on C++17 compilers, use `if constexpr` instead).

Usually this class template is instantiated only via the return value of `boost::contract::call_if` and `boost::contract::call_if_c`.

# See Also:

Assertion Requirements

Then

Then-branch nullary functor template. The functor template call `f()` is actually compiled and executed for this template specialization (because the if-statement static predicate is `true`). The return type of `f()` must be `void` for this template specialization (because the then-branch functor template calls return void).

Construct this object with the then-branch functor template.

void `Else const &

Else-branch nullary functor template. The functor template call `f()` is never compiled or executed for this template specialization (because the if-statement static predicate is `true`). The return type of `f()` must be `void` for this template specialization (because the then-branch functor template calls return void).

` Specify the else-branch functor template.

`call_if_statement`< true, Then, void > bool

Static boolean predicate selecting which functor template call to compile and execute.

ElseIfThen const &

Else-if-branch nullary functor template. The functor template call `f()` is never compiled or executed for this template specialization (because the if-statement static predicate is `true`). The return type of `f()` must be `void` for this template specialization (because the then-branch functor template calls return void).

Specify an else-if-branch functor template (using a static boolean predicate).

A call-if statement so the else statement and additional else-if statements can be specified if needed. Eventually, it will return void for this template specialization (because the then-branch functor template calls return void).

`call_if_statement`< true, Then, void >

Nullary boolean meta-function selecting which functor template call to compile and execute.

ElseIfThen const &

Else-if-branch nullary functor template. The functor template call `f()` is never compiled or executed for this template specialization (because the if-statement static predicate is `true`). The return type of `f()` must be `void` for this template specialization (because the then-branch functor template calls return void).

Specify an else-if-branch functor template (using a nullary boolean meta-function).

A call-if statement so the else statement and additional else-if statements can be specified if needed. Eventually, it will return void for this template specialization (because the then-branch functor template calls return void).

`call_if_statement`< Pred, Then > bool

Static boolean predicate selecting which functor template call to compile and execute.

Then

Then-branch nullary functor template. The functor template call `f()` is compiled and executed if and only if `Pred` is `true`. The return type of other functor template calls specified for this call-if statement (else-branch, else-if-branches, etc.) must be the same as (or implicitly convertible to) the return type of then-branch functor call `f()`.

Select compilation and execution of functor template calls using a static boolean predicate (not needed on C++17 compilers, use `if constexpr` instead).

Create a call-if object with the specified then-branch functor template:

    boost::contract::call_if_c<Pred1>(
        then_functor_template1
    ).template else_if_c<Pred2>(            // Optional.
        then_functor_template2
    )                                       // Optionally, other `else_if_c` or
    ...                                     // `else_if`.
    .else_(                                 // Optional for `void` functors,
        else_functor_template               // but required for non `void`.
    )

Optional functor templates for else-if-branches and the else-branch can be specified as needed (the else-branch function template is required if `f` returns non-void).

# See Also:

Assertion Requirements

A call-if statement so else and else-if statements can be specified if needed. Eventually, this will be the return value of the one functor template call being compiled and executed (which could also be `void`).

`call_if_statement`< Pred::value, Then >

Nullary boolean meta-function selecting which functor template call to compile and execute.

Then

Then-branch nullary functor template. The functor template call `f()` is compiled and executed if and only if `Pred::value` is `true`. The return type of other functor template calls specified for this call-if statement (else-branch, else-if-branches, etc.) must be the same as (or implicitly convertible to) the return type of then-branch functor template call `f()`.

Select compilation and execution of functor template calls using a nullary boolean meta-function (not needed on C++17 compilers, use `if constexpr` instead).

This is equivalent to `boost::contract::call_if_c<Pred::value>(f)`. Create a call-if object with the specified then-branch functor template:

    boost::contract::call_if<Pred1>(
        then_functor_template1
    ).template else_if<Pred2>(              // Optional.
        then_functor_template2
    )                                       // Optionally, other `else_if` or
    ...                                     // `else_if_c`.
    .else_(                                 // Optional for `void` functors,
        else_functor_template               // but required for non `void`.
    )

Optional functor templates for else-if-branches and the else-branch can be specified as needed (the else-branch functor template is required if `f` returns non-void).

# See Also:

Assertion Requirements

A call-if statement so else and else-if statements can be specified if needed. Eventually, this will be the return value of the one functor template call being compiled and executed (which could also be `void`).

bool bool

Static boolean predicate selecting when the functor template call `f()` should be compiled and executed.

Then

Nullary boolean functor template. The functor template call `f()` is compiled and executed if and only if `Pred` is `true`.

bool
true

Boolean value to return when `Pred` is `false` (instead of compiling and executing the functor template call `f()`).

Select compilation and execution of a boolean functor template condition using a static boolean predicate (not needed on C++17 compilers, use `if constexpr` instead).

Compile and execute the nullary boolean functor template call `f()` if and only if the specified static boolean predicate `Pred` is `true`, otherwise trivially return `else_` (`true` by default) at run-time.

A call to `boost::contract::condition_if_c<Pred>(f, else_)` is logically equivalent to `boost::contract::call_if_c<Pred>(f, [] { return else_; })` (but its internal implementation is optimized and it does not actually use `call_if_c`).

# See Also:

Assertion Requirements

Boolean value returned by `f()` if the static predicate `Pred` is `true`. Otherwise, trivially return `else_`.

bool

Nullary boolean meta-function selecting when the functor template call `f()` should be compiled and executed.

Then

Nullary boolean functor template. The functor template call `f()` is compiled and executed if and only if `Pred::value` is `true`.

bool
true

Boolean value to return when `Pred::value` is `false` (instead of compiling and executing the functor template call `f()`).

Select compilation and execution of a boolean functor template condition using a nullary boolean meta-function (not needed on C++17 compilers, use `if constexpr` instead).

This is equivalent to `boost::contract::condition_if_c<Pred::value>(f, else_)`. Compile and execute the nullary boolean functor template call `f()` if and only if the specified nullary boolean meta-function `Pred::value` is `true`, otherwise trivially return `else_` (`true` by default) at run-time.

# See Also:

Assertion Requirements

Boolean value returned by `f()` if the static predicate `Pred::value` is `true`. Otherwise, trivially return `else_`.

RAII object that checks contracts.

RAII object that checks the contracts.

In general, when this object is constructed it checks class invariants at entry, preconditions, and makes old value copies at body. When it is destructed, it checks class invariants at exist, postconditions, and exception guarantees. This object enforces the following (see Contract Programming Overview):

- Postconditions are checked only if the body does not throw an exception.

- Exceptions guarantees are checked only if the body throws an exception.

- Constructor entry never checks class invariants.

- Destructor exit checks class invariants only if the body throws an exception (even if destructors should usually not be programmed to throw exceptions in C++ and they are implicitly declared `noexcept` since C++11).

- Static invariants are always checked at entry and exit (and regardless of the body throwing exceptions or not).

When used this way, this object is constructed and initialized to the return value of one of the contract functions `boost::contract::function`, `boost::contract::constructor`, `boost::contract::destructor`, or `boost::contract::public_function`. In addition to that, this object can be constructed from a nullary functor when it is used to program implementation checks.

# See Also:

Tutorial, Implementation Checks

F const &

Nullary functor that asserts implementation checks. `f()` will be called as soon as this object is constructed at the point it is declared within the implementation code (see Implementation Checks).

Construct this object for implementation checks.

This can be used to program checks within implementation code (body, etc.). This constructor is not declared `explicit` so initializations can use assignment syntax `=`.

Throws: This can throw in case programmers specify contract failure handlers that throw exceptions instead of terminating the program (see Throw on Failure).

check
const &

Copied-from object.

Construct this object copying it from the specified one.

This object will check the contract, the copied-from object will not (i.e., contract check ownership is transferred from the copied object to the new object being created by this constructor).

Return type of the enclosing function declaring the contract if that is either a virtual or an overriding public function, otherwise this is always `void`. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.)

specify_precondition_old_postcondition_except
< VirtualResult > const &

Contract to be checked (usually the return value of `boost::contract::function` or `boost::contract::public_function`).

Construct this object to check the specified contract.

This checks class invariants at entry (if those were specified for the given contract). This constructor is not declared `explicit` so initializations can use assignment syntax `=`.

Throws: This can throw in case programmers specify contract failure handlers that throw exceptions instead of terminating the program (see Throw on Failure).

Return type of the enclosing function declaring the contract if that is either a virtual or an overriding public function, otherwise this is always `void`. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.)

specify_old_postcondition_except
< VirtualResult > const &

Contract to be checked (usually the return value of `boost::contract::function`, `boost::contract::constructor`, `boost::contract::destructor`, or `boost::contract::public_function`).

Construct this object to check the specified contract.

This checks class invariants at entry and preconditions (if any of those were specified for the given contract). This constructor is not declared `explicit` so initializations can use assignment syntax `=`.

Throws: This can throw in case programmers specify contract failure handlers that throw exceptions instead of terminating the program (see Throw on Failure).

Return type of the enclosing function declaring the contract if that is either a virtual or an overriding public function, otherwise this is always `void`. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.)

specify_postcondition_except
< VirtualResult > const &

Contract to be checked (usually the return value of `boost::contract::function`, `boost::contract::constructor`, `boost::contract::destructor`, or `boost::contract::public_function`).

Construct this object to check the specified contract.

This checks class invariants at entry and preconditions then it makes old value copies at body (if any of those were specified for the given contract). This constructor is not declared `explicit` so initializations can use assignment syntax `=`.

Throws: This can throw in case programmers specify contract failure handlers that throw exceptions instead of terminating te program (see Throw on Failure).

specify_except
const &

Contract to be checked (usually the return value of `boost::contract::function`, `boost::contract::constructor`, `boost::contract::destructor`, or `boost::contract::public_function`).

Construct this object to check the specified contract.

This checks class invariants at entry and preconditions then it makes old value copies at body, plus the destructor of this object will also check postconditions in this case (if any of those were specified for the given contract). This constructor is not declared `explicit` so initializations can use assignment syntax `=`.

Throws: This can throw in case programmers specify contract failure handlers that throw exceptions instead of terminating the program (see Throw on Failure).

specify_nothing
const &

Contract to be checked (usually the return value of `boost::contract::function`, `boost::contract::constructor`, `boost::contract::destructor`, or `boost::contract::public_function`).

Construct this object to check the specified contract.

This checks class invariants at entry and preconditions then it makes old value copies at body, plus the destructor of this object will also check postconditions and exception guarantees in this case (if any of those were specified for the given contract). This constructor is not declared `explicit` so initializations can use assignment syntax `=`.

Throws: This can throw in case programmers specify contract failure handlers that throw exceptions instead of terminating the program (see Throw on Failure).

Destruct this object.

This checks class invariants at exit and either postconditions when the enclosing function body did not throw an exception, or exception guarantees when the function body threw an exception (if class invariants, postconditions, and exception guarantees respectively were specified for the enclosing class and the contract parameter given when constructing this object).

Throws: This can throw in case programmers specify contract failure handlers that throw exceptions instead of terminating the program (see Throw on Failure). (This is declared `noexcept(false)` since C++11.)

Program contracts for constructors.

`specify_old_postcondition_except`

The type of the class containing the constructor declaring the contract. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.)

Class *

The object `this` from the scope of the enclosing constructor declaring the contract. (Constructors check all class invariants, including static and volatile invariants, see Class Invariants and Volatile Public Functions).

Program contracts for constructors.

This is used to specify postconditions, exception guarantees, old value copies at body, and check class invariants for constructors (see ``boost::contract::constructor_precondition`` to specify preconditions for constructors):

    class u {
        friend class boost::contract:access;

        void invariant() const { // Optional (as for static and volatile).
            BOOST_CONTRACT_ASSERT(...);
            ...
        }

    public:
        u(...) {
            boost::contract::old_ptr<old_type> old_var;
            boost::contract::check c = boost::contract::constructor(this)
                // No `.precondition` (use `constructor_precondition` instead).
                .old([&] { // Optional.
                    old_var = BOOST_CONTRACT_OLDOF(old_expr);
                    ...
                })
                .postcondition([&] { // Optional.
                    BOOST_CONTRACT_ASSERT(...);
                    ...
                })
                .except([&] { // Optional.
                    BOOST_CONTRACT_ASSERT(...);
                    ...
                })
            ;

            ... // Constructor body.
        }

        ...
    };

For optimization, this can be omitted for constructors that do not have postconditions and exception guarantees, within classes that have no invariants.

# See Also:

Constructors

The result of this function must be assigned to a variable of type ``boost::contract::check`` declared explicitly (i.e., without using C++11 `auto` declarations) and locally just before the code of the constructor body (otherwise this library will generate a run-time error, see `BOOST_CONTRACT_ON_MISSING_CHECK_DECL`).

Allow to declare invariants, base types, etc all as private members.

Declare this class as friend to program invariants and base types as private members.

Declare this class a friend of the user-defined class specifying the contracts and then invariant functions and the base types `typedef` can be declared as non-public members:

    class u
        #define BASES public b, private w
        : BASES
    {
        friend class boost::contract::access;

        typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; // Private.
        #undef BASES

        void invariant() const { ... } // Private (same for static and volatile).

    public:
        ...
    };

In real code, programmers will likely chose to declare this class as friend so to fully control public interfaces of their user-defined classes (this is not extensively done in the examples of this documentation only for brevity). This class is not intended to be directly used by programmers a part from being declared as `friend` (and that is why this class does not have any public member and it is not copyable).

Not declaring this class friend of user-defined classes will cause compiler errors on some compilers (e.g., MSVC) because the private members needed to check the contracts will not be accessible. On other compilers (e.g., GCC and CLang), the private access will instead fail SFINAE and no compiler error will be reported while invariants and subcontracting will be silently skipped at run-time. Therefore, programmers must make sure to either declare this class as friend or to always declare invariant functions and base types `typedef` as public members.

# See Also:

Access Specifiers

Macros for implementation checks.

Boolean condition to check within implementation code (function body, etc.). (This is not a variadic macro parameter so any comma it might contain must be protected by round parenthesis and `BOOST_CONTRACT_CHECK((cond))` will always work.)

Preferred way to assert implementation check conditions.

It is preferred to use this macro instead of programming implementation checks in a nullary functor passed to ``boost::contract::check`` constructor because this macro will completely remove implementation checks from the code when `BOOST_CONTRACT_NO_CHECKS` is defined:

    void f() {
        ...
        BOOST_CONTRACT_CHECK(cond);
        ...
    }

`BOOST_CONTRACT_CHECK`, `BOOST_CONTRACT_CHECK_AUDIT`, and `BOOST_CONTRACT_CHECK_AXIOM` are the three assertion levels predefined by this library for implementation checks.

# See Also:

Implementation Checks

Boolean condition to check within implementation code (function body, etc.). (This is not a variadic macro parameter so any comma it might contain must be protected by round parenthesis and `BOOST_CONTRACT_CHECK_AUDIT((cond))` will always work.)

Preferred way to assert implementation check conditions that are computationally expensive, at least compared to the computational cost of executing the function body.

The specified condition will always be compiled and validated syntactically, but it will not be checked at run-time unless `BOOST_CONTRACT_AUDITS` is defined (undefined by default). This macro is defined by code equivalent to:

    #ifdef BOOST_CONTRACT_AUDITS
        #define BOOST_CONTRACT_CHECK_AUDIT(cond) \
            BOOST_CONTRACT_CHECK(cond)
    #else
        #define BOOST_CONTRACT_CHECK_AUDIT(cond) \
            BOOST_CONTRACT_CHECK(true || cond)
    #endif

`BOOST_CONTRACT_CHECK`, `BOOST_CONTRACT_CHECK_AUDIT`, and `BOOST_CONTRACT_CHECK_AXIOM` are the three assertion levels predefined by this library for implementation checks. If there is a need, programmers are free to implement their own assertion levels defining macros similar to the one above.

# See Also:

Assertion Levels

Boolean condition to check within implementation code (function body, etc.). (This is not a variadic macro parameter so any comma it might contain must be protected by round parenthesis and `BOOST_CONTRACT_CHECK_AXIOM((cond))` will always work.)

Preferred way to document in the code implementation check conditions that are computationally prohibitive, at least compared to the computational cost of executing the function body.

The specified condition will always be compiled and validated syntactically, but it will never be checked at run-time. This macro is defined by code equivalent to:

    #define BOOST_CONTRACT_CHECK_AXIOM(cond) \
        BOOST_CONTRACT_CHECK(true || cond)

`BOOST_CONTRACT_CHECK`, `BOOST_CONTRACT_CHECK_AUDIT`, and `BOOST_CONTRACT_CHECK_AXIOM` are the three assertion levels predefined by this library for implementation checks. If there is a need, programmers are free to implement their own assertion levels defining macros similar to the one above.

# See Also:

Assertion Levels

Configure this library compile-time and run-time behaviours.

Define this macro to compile this library as a shared library (recommended).

If this macro is defined, this library is compiled so it can be linked as a shared library (a.k.a., Dynamically Linked Library or DLL) to user code. This library will automatically define this macro when Boost libraries are built as shared libraries (e.g., defining `BOOST_ALL_DYN_LINK` or using `bjam link=shared ...`).

In general this library will correctly check contracts at run-time only when compiled as a shared library, unless user code checks contracts in a single program unit (e.g., a single program with only statically linked libraries). Therefore, it is recommended to build and use this library as a shared library by defining this macro (or equivalently by building all Boost libraries as shared libraries).

# See Also:

Getting Started

Define this macro to compile this library as a static library (not recommended).

If this macro is defined, this library is compiled so it can be linked statically to user code. This library will automatically define this macro when Boost libraries are built as static libraries.

This library is not guaranteed to always work correctly at run-time when this macro is defined (define `BOOST_CONTRACT_DYN_LINK` or `BOOST_ALL_DYN_LINK` instead). However, this macro can be defined and this library can be safely used as a static library for user code that checks contracts in a single program unit (e.g., a single program with only statically linked libraries).

# See Also:

Getting Started

Automatically defined by this library when it is being used as a header-only library (not recommended).

This macro is not a configuration macro and this library will generate a compile-time error if users try to define it directly. This library will automatically define this macro when users do not define `BOOST_CONTRACT_DYN_LINK` (or `BOOST_ALL_DYN_LINK`) and `BOOST_CONTRACT_STATIC_LINK`. When used as a header-only library, this library code does not have to be compiled separately from user code, this library headers are simply included and compiled as part of the user program.

This library is not guaranteed to always work correctly at run-time when this macro is defined (define `BOOST_CONTRACT_DYN_LINK` or `BOOST_ALL_DYN_LINK` instead). However, this macro can be defined and this library can be safely used as a header-only library for user code that checks contracts in a single program unit (e.g., a single program with only statically linked libraries).

# See Also:

Getting Started

Define this macro to not lock internal library data for thread safety (undefined by default).

Defining this macro will make the library implementation code not thread safe so this macro should not be defined unless the library is being used by single-threaded applications only. This library will automatically define this macro when Boost libraries are built without threads (e.g., defining `BOOST_DISABLE_THREADS`).

When this macro is left undefined this library needs to internally use some sort of global lock (to ensure contract checking is globally disabled when other contracts are being checked and also to safely access failure handler functors). That could introduce an undesired amount of synchronization in some multi-threaded applications.

# See Also:

Assertions

Maximum number of arguments for public function overrides on compilers that do not support variadic templates (default to `10`).

On compilers that do not support C++11 variadic templates, this macro is defined to the maximum number of arguments that public function overrides can have and pass to `boost::contract::public_function` (users can redefine this macro to a different value). On compilers that support variadic templates, this macro has no effect.

Regardless of the value of this macro and of compiler support for variadic templates, there might be an intrinsic limit of about 18 arguments for public function overrides (because of similar limits in Boost.MPL and Boost.FunctionTypes internally used by this library).

# See Also:

No Macros

Define the name of the base type `typedef` (`base_types` by default).

This macro expands to the name of the `typedef` that lists the base classes for subcontracting via `BOOST_CONTRACT_BASE_TYPES`:

    class u
        #define BASES public b, private w
        : BASES
    {
        friend class boost::contract:access;

        typedef BOOST_CONTRACT_BASE_TYPES(BASES) BOOST_CONTRACT_TYPEDEF;
        #undef BASES

        ...
    };

When used this way, users can redefine this macro if the `typedef` must have a name different from `base_types` (because of name clashes in user code, etc.).

# See Also:

Base Classes

Define the name of the class invariant member function (`invariant` by default).

This macro expands to the name of the `const` and `const volatile` member functions that check class invariants and volatile class invariants respectively:

    class u {
        friend class boost::contract::access;

        void BOOST_CONTRACT_INVARIANT_FUNC() const {
            BOOST_CONTRACT_ASSERT(...);
            ...
        }

        void BOOST_CONTRACT_INVARIANT_FUNC() const volatile {
            BOOST_CONTRACT_ASSERT(...);
            ...
        }

        ...
    };

When used this way, users can redefine this macro if the invariant functions must have a name different from `invariant` (because of name clashes in user code, etc.).

C++ does not allow to overload member functions based on the `static` classifier, so this macro must always be defined to be different than the function name defined for `BOOST_CONTRACT_STATIC_INVARIANT_FUNC`.

# See Also:

Class Invariants, Volatile Public Functions

Define the name of the static invariant member function (`static_invariant` by default).

This macro expands to the name of the `static` member function that checks static class invariants:

    class u {
        friend class boost::contract::access;

        static void BOOST_CONTRACT_STATIC_INVARIANT_FUNC() {
            BOOST_CONTRACT_ASSERT(...);
            ...
        }

        ...
    };

When used this way, users can redefine this macro if the static invariant function must have a name different from `static_invariant` (because of name clashes in user code, etc.).

C++ does not allow to overload member functions based on the `static` classifier, so this macro must always be defined to be different than the function name defined for `BOOST_CONTRACT_INVARIANT_FUNC`.

# See Also:

Class Invariants

Disable some compile-time errors generated by this library (undefined by default).

Defining this macro disables a number of static checks and related compile-time errors generated by this library, for example:

- The static invariant member function named as `BOOST_CONTRACT_STATIC_INVARIANT_FUNC` must be declared `static`.

- Non-static invariant member functions named as `BOOST_CONTRACT_INVARIANT_FUNC` must be declared either `const`, `const volatile`, or `volatile const`.

- Derived classes that program contracts for one or more public function overrides via `boost::contract::public_function` must also define the `BOOST_CONTRACT_BASE_TYPES` `typedef`.

In general, it is not recommended to define this macro because these compile-time checks can guard against misuses of this library.

# See Also:

Class Invariants, Base Classes

Code block to execute if contracts are not assigned to a ``boost::contract::check`` variable (undefined and executes `BOOST_ASSERT(false)` by default).

In general, there is a logic error in the program when contracts are not explicitly assigned to a local variable of type ``boost::contract::check`` and without using C++11 `auto` declarations (because that is a misuse of this library). Therefore, by default (i.e., when this macro is not defined) this library calls `BOOST_ASSERT(false)` in those cases. If this macro is defined, this library will execute the code expanded by this macro instead of calling `BOOST_ASSERT(false)` (if programmers prefer to throw an exception, etc.).

This macro can also be defined to be any block of code (and use empty curly brackets `{}` to generate no error, not recommended), for example (on GCC):

    gcc -DBOOST_CONTRACT_ON_MISSING_CHECK_DECL='{ throw std::logic_error("missing contract check declaration"); }' ...

# See Also:

Tutorial

Define this macro to not disable other assertions while checking preconditions (undefined by default).

Not disabling other assertions while checking preconditions can lead to infinite recursion in user code so by default this macro is not defined.

However, the [N1962] proposal does not disable assertions while checking preconditions because arguments can reach the function body unchecked if assertions are disabled while checking preconditions (e.g., when these same functions bodies are called to check the preconditions in question). This macro can be defined to obtain the behaviour specified in [N1962] (at the risk of infinite recursion).

# See Also:

Feature Summary

Define this macro to not disable any assertion while checking other assertions (undefined by default).

Not disabling assertions while checking other assertions can lead to infinite recursion in user code so by default this macro is not defined. (Defining this macro automatically implies that other assertion checking is disabled while checking preconditions as if `BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION` was also defined.)

# See Also:

Feature Summary

Define this macro to evaluate and check audit assertions at run-time (undefined by default).

Audit assertions and implementation checks programmed via `BOOST_CONTRACT_ASSERT_AUDIT` and `BOOST_CONTRACT_CHECK_AUDIT` are always compiled and validated syntactically. However, they are not evaluated and checked at run-time unless this macro is defined (because these conditions can be computationally expensive, at least compared to the computational cost of executing the function body).

# See Also:

Assertion Levels

If defined, this library disables implementation checks (undefined by default).

If this macro is defined, this library internal code is also optimized to reduce compile-time (not just run-time) overhead associated with implementation checks. In addition, users can manually program `#ifndef` statements in their code using this macro to completely disable compilation of implementation checks or use `BOOST_CONTRACT_CHECK` (recommended).

# See Also:

Implementation Checks, Disable Contract Checking, Disable Contract Compilation

If defined, this library does not check preconditions (undefined by default).

If this macro is defined, this library internal code is also optimized to reduce compile-time (not just run-time) overhead associated with checking preconditions. In addition, users can manually program `#ifndef` statements in their code using this macro to completely disable compilation of preconditions or use the macros defined in `boost/contract_macro.hpp` (recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).

# See Also:

Preconditions, Disable Contract Checking, Disable Contract Compilation

If defined, this library does not check postconditions (undefined by default).

If this macro is defined, this library internal code is also optimized to reduce compile-time (not just run-time) overhead associated with checking postconditions. In addition, users can manually program `#ifndef` statements in their code using this macro to completely disable compilation of postconditions or use the macros defined in `boost/contract_macro.hpp` (recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).

It is necessary to disable both postconditions and exception guarantees defining `BOOST_CONTRACT_NO_POSTCONDITIONS` and `BOOST_CONTRACT_NO_EXCEPTS` in order to disable old value copies (see `BOOST_CONTRACT_NO_OLDS`).

# See Also:

Postconditions, Disable Contract Checking, Disable Contract Compilation

If defined, this library does not check exception guarantees (undefined by default).

If this macro is defined, this library internal code is also optimized to reduce compile-time (not just run-time) overhead associated with checking exception guarantees. In addition, users can manually program `#ifndef` statements in their code using this macro to completely disable compilation of exception guarantees or use the macros defined in `boost/contract_macro.hpp` (recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).

It is necessary to disable both postconditions and exception guarantees defining `BOOST_CONTRACT_NO_POSTCONDITIONS` and `BOOST_CONTRACT_NO_EXCEPTS` in order to disable old value copies (see `BOOST_CONTRACT_NO_OLDS`).

# See Also:

Exception Guarantees, Disable Contract Checking, Disable Contract Compilation

If defined, this library does not check class invariants at entry (undefined by default).

If this macro is defined, this library internal code is also optimized to reduce compile-time (not just run-time) overhead associated with checking class invariants at entry. In addition, users can manually program `#ifndef` statements in their code using this macro to completely disable compilation of entry class invariants or use the macros defined in `boost/contract_macro.hpp` (recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).

This macro is automatically defined when `BOOST_CONTRACT_NO_INVARIANTS` is defined.

# See Also:

Class Invariants, Disable Contract Checking, Disable Contract Compilation

If defined, this library does not check class invariants at exit (undefined by default).

If this macro is defined, this library internal code is also optimized to reduce compile-time (not just run-time) overhead associated with checking class invariants at exit. In addition, users can manually program `#ifndef` statements in their code using this macro to completely disable compilation of exit class invariants or use the macros defined in `boost/contract_macro.hpp` (recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).

This macro is automatically defined when `BOOST_CONTRACT_NO_INVARIANTS` is defined.

# See Also:

Class Invariants, Disable Contract Checking, Disable Contract Compilation

If defined, this library does not check class invariants (undefined by default).

If this macro is defined, this library internal code is also optimized to reduce compile-time (not just run-time) overhead associated with checking class invariants. In addition, users can manually program `#ifndef` statements in their code using this macro to completely disable compilation of class invariants or use the macros defined in `boost/contract_macro.hpp` (recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).

Defining this macro is equivalent to defining both `BOOST_CONTRACT_NO_ENTRY_INVARIANTS` and `BOOST_CONTRACT_NO_EXIT_INVARIANTS`.

# See Also:

Class Invariants, Disable Contract Checking, Disable Contract Compilation

Automatically defined by this library when old value copies are not to be performed.

This macro is not a configuration macro and this library will generate a compile-time error if users try to define it directly. This library will automatically define this macro when users define both `BOOST_CONTRACT_NO_POSTCONDITIONS` and `BOOST_CONTRACT_NO_EXCEPTS`. Users can manually program `#ifndef` statements in their code using this macro to completely disable compilation of old value copies or use the macros defined in `boost/contract_macro.hpp` (recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).

# See Also:

Old Values, Old Values Copied at Body, Disable Contract Compilation

Automatically defined by this library when contracts are not checked for constructors.

This macro is not a configuration macro and this library will generate a compile-time error if users try to define it directly. This library will automatically define this macro when users define all `BOOST_CONTRACT_NO_INVARIANTS`, `BOOST_CONTRACT_NO_POSTCONDITIONS`, and `BOOST_CONTRACT_NO_EXCEPTS`. Users can manually program `#ifndef` statements in their code using this macro to completely disable compilation of contracts for constructors or use the macros defined in `boost/contract_macro.hpp` (recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).

Constructor preconditions are checked separately by ``boost::contract::constructor_precondition`` so they are disabled by `BOOST_CONTRACT_NO_PRECONDITIONS` instead.

# See Also:

Constructors, Disable Contract Compilation

Automatically defined by this library when contracts are not checked for destructors.

This macro is not a configuration macro and this library will generate a compile-time error if users try to define it directly. This library will automatically define this macro when users define all `BOOST_CONTRACT_NO_INVARIANTS`, `BOOST_CONTRACT_NO_POSTCONDITIONS`, and `BOOST_CONTRACT_NO_EXCEPTS`. Users can manually program `#ifndef` statements in their code using this macro to completely disable compilation of contracts for destructors or use the macros defined in `boost/contract_macro.hpp` (recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).

# See Also:

Destructors, Disable Contract Compilation

Automatically defined by this library when contracts are not checked for public functions.

This macro is not a configuration macro and this library will generate a compile-time error if users try to define it directly. This library will automatically define this macro when users define all `BOOST_CONTRACT_NO_INVARIANTS`, `BOOST_CONTRACT_NO_PRECONDITIONS`, `BOOST_CONTRACT_NO_POSTCONDITIONS`, and `BOOST_CONTRACT_NO_EXCEPTS`. Users can manually program `#ifndef` statements in their code using this macro to completely disable compilation of contracts for public functions or use the macros defined in `boost/contract_macro.hpp` (recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).

# See Also:

Public Functions, Disable Contract Compilation

Automatically defined by this library when contracts are not checked for non-member, private, or protected functions.

This macro is not a configuration macro and this library will generate a compile-time error if users try to define it directly. This library will automatically define this macro when users define all `BOOST_CONTRACT_NO_PRECONDITIONS`, `BOOST_CONTRACT_NO_POSTCONDITIONS`, and `BOOST_CONTRACT_NO_EXCEPTS`. Users can manually program `#ifndef` statements in their code using this macro to completely disable compilation of contracts for non-member, private and protected functions, or use the macros defined in `boost/contract_macro.hpp` (recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).

This macro is also used when contracts are not checked for private or protected functions, lambda functions, code blocks, loops, etc.

# See Also:

Non-Member Functions, Private and Protected Functions, Lambdas, Loops, Code Blocks, Disable Contract Compilation

Automatically defined by this library when contracts are not checked for preconditions, postconditions, exceptions guarantees, and class invariants (excluding implementation checks).

This macro is not a configuration macro and this library will generate a compile-time error if users try to define it directly. This library will automatically define this macro when users define all `BOOST_CONTRACT_NO_PRECONDITIONS`, `BOOST_CONTRACT_NO_POSTCONDITIONS`, `BOOST_CONTRACT_NO_EXCEPTS`, and `BOOST_CONTRACT_NO_INVARIANTS`. Users can manually program `#ifndef` statements in their code using this macro to completely disable compilation of contracts within specifications (so excluding implementation checks which are contracts within implementations instead), or use the macros defined in `boost/contract_macro.hpp` (recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).

# See Also:

Disable Contract Compilation

Automatically defined by this library when contracts are not checked at all (neither for specifications nor for implementations).

This macro is not a configuration macro and this library will generate a compile-time error if users try to define it directly. This library will automatically define this macro when users define all `BOOST_CONTRACT_NO_INVARIANTS`, `BOOST_CONTRACT_NO_PRECONDITIONS`, `BOOST_CONTRACT_NO_POSTCONDITIONS`, `BOOST_CONTRACT_NO_EXCEPTS`, and `BOOST_CONTRACT_NO_CHECKS`. For example, users can manually program `#ifndef` statements in their code using this macro to avoid including the `boost/contract.hpp` header all together:

    #include <boost/contract/core/config.hpp>
    #ifndef BOOST_CONTRACT_NO_ALL
        #include <boost/contract.hpp>
    #endif

Or, use the `boost/contract_macro.hpp` header and related macros instead (because the `boost/contract_macro.hpp` header is already optimized to not include other headers from this library when contracts are not checked, but recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).

# See Also:

Disable Contract Compilation

Program preconditions for constructors.

The class type of the constructor for which preconditions are being programmed.

Program preconditions for constructors.

This class must be the very first base of the class declaring the constructor for which preconditions are programmed (that way constructor arguments can be checked by preconditions even before they are used to initialize other base classes):

    class u
        #define BASES private boost::contract::constructor_precondition<u>, \
                public b
        : BASES
    {
        friend class boost::contract::access;

        typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types;
        #undef BASES

    public:
        explicit u(unsigned x) :
            boost::contract::constructor_precondition<u>([&] {
                BOOST_CONTRACT_ASSERT(x != 0);
                ...
            }),
            b(1.0 / float(x))
        {
            ...
        }

        ...
    };

User-defined classes should inherit privately from this class (to not alter the public interface of user-defined classes). In addition, this class should never be declared as a virtual base (because virtual bases are initialized only once across the entire inheritance hierarchy preventing preconditions of other base classes from being checked).

This class cannot be used this way in a `union` because unions cannot have base classes in C++. Instead, this class is used in a `union` to declare a local object within the constructor definition just before `boost::contract::constructor` is used (see Unions).

# See Also:

Constructors

Construct this object without specifying constructor preconditions.

This is implicitly called for those constructors of the contracted class that do not specify preconditions.

The implementation of this library is optimized so that calling this default constructor should amount to negligible compile-time and run-time overheads (likely to be optimized away completely by most compilers).

F const &

Nullary functor called by this library to check constructor preconditions `f()`. Assertions within this functor call are usually programmed using `BOOST_CONTRACT_ASSERT`, but any exception thrown by a call to this functor indicates a contract failure (and will result in this library calling `boost::contract::precondition_failure`). This functor should capture variables by (constant) value, or better by (constant) reference to avoid extra copies.

Construct this object specifying constructor preconditions.

Handle contract assertion failures.

std::exception
boost::contract::exception
Exception typically used to report a contract assertion failure.

This exception is thrown by code expanded by `BOOST_CONTRACT_ASSERT` (but it can also be thrown by user code programmed manually without that macro). This exception is typically used to report contract assertion failures because it contains detailed information about the file name, line number, and source code of the asserted condition (so it can be used by this library to provide detailed error messages when handling contract assertion failures).

However, any other exception can be used to report a contract assertion failure (including user-defined exceptions). This library will call the appropriate contract failure handler function ( `boost::contract::precondition_failure`, etc.) when this or any other exception is thrown while checking contracts (by default, these failure handler functions print an error message to `std::cerr` and terminate the program, but they can be customized to take any other action).

# See Also:

Throw on Failure, No Macros

char const *
""

Name of the file containing the assertion (usually set using `FILE`).

unsigned long
0

Number of the line containing the assertion (usually set using `LINE`).

char const *
""

Text listing the source code of the assertion condition.

Construct this object with file name, line number, and source code text of an assertion condition (all optional).

This constructor can also be used to specify no information (default constructor), or to specify only file name and line number but not source code text (because of the parameter default values).

char const *

Text listing the source code of the assertion condition.

Construct this object only with the source code text of the assertion condition.

Destruct this object.

Throws: This is declared `noexcept` (or `throw()` before C++11).

char const * String describing the failed assertion.

Throws: This is declared `noexcept` (or `throw()` before C++11).

A string formatted similarly to the following: `assertion "`code()`" failed: file "`file()`", line `line()`` (where `` indicate execution quotes). File, line, and code will be omitted from this string if they were not specified when constructing this object.

char const * Name of the file containing the assertion.

File name as specified at construction (or `""` if no file was specified).

unsigned long Number of the line containing the assertion.

Line number as specified at construction (or `0` if no line number was specified).

char const * Text listing the source code of the assertion condition.

Assertion condition source code as specified at construction (or `""` if no source code text was specified).

std::bad_cast
boost::contract::exception
Exception thrown when inconsistent return values are passed to overridden virtual public functions.

This exception is thrown when programmers pass to this library return value parameters for public function overrides in derived classes that are not consistent with the return type parameter passed for the virtual public function being overridden from the base classes. This allows this library to give more descriptive error messages in such cases of misuse.

This exception is internally thrown by this library and programmers should not need to throw it from user code.

# See Also:

Public Function Overrides

char const *

Name of the from-type (source of the cast).

char const *

Name of the to-type (destination of the cast).

Construct this object with the name of the from- and to- result types.

Destruct this object.

Throws: This is declared `noexcept` (or `throw()` before C++11).

char const * Description for this error (containing both from- and to- type names).

Throws: This is declared `noexcept` (or `throw()` before C++11).

Public base class for all exceptions directly thrown by this library.

This class does not inherit from `std::exception` because exceptions deriving from this class will do that (inheriting from `std::exception`, `std::bad_cast`, etc.).

# See Also:

``boost::contract::assertion_failure``, ``boost::contract::bad_virtual_result_cast``, etc.

Destruct this object.

Throws: This is declared `noexcept` (or `throw()` before C++11).

Assertion failed when checking contracts for constructors.
Assertion failed when checking contracts for destructors .
Assertion failed when checking contracts for functions (members or not, public or not).
Indicate the kind of operation where the contract assertion failed.

This is passed as a parameter to the assertion failure handler functions. For example, it might be necessary to know in which operation an assertion failed to make sure exceptions are never thrown from destructors, not even when contract failure handlers are programmed by users to throw exceptions instead of terminating the program.

# See Also:

Throw on Failure

Type of assertion failure handler functions (with `from` parameter).

Assertion failure handler functions specified by this type must be functors returning `void` and taking a single parameter of type `boost::contract::from`. For example, this is used to specify contract failure handlers for class invariants, preconditions, postconditions, and exception guarantees.

# See Also:

Throw on Failure

boost::function< void(from)>
Type of assertion failure handler functions (without `from` parameter).

Assertion failure handler functions specified by this type must be nullary functors returning `void`. For example, this is used to specify contract failure handlers for implementation checks.

# See Also:

Throw on Failure

boost::function< void()>
failure_handler const & `failure_handler const &

New failure handler functor to set.

` Set failure handler for implementation checks.

Set a new failure handler and returns it.

Throws: This is declared `noexcept` (or `throw()` before C++11).

# See Also:

Throw on Failure, Implementation Checks

Same failure handler functor `f` passed as parameter (e.g., for concatenating function calls).

failure_handler Return failure handler currently set for implementation checks.

This is often called only internally by this library.

Throws: This is declared `noexcept` (or `throw()` before C++11).

# See Also:

Throw on Failure, Implementation Checks

A copy of the failure handler currently set.

void Call failure handler for implementation checks.

This is often called only internally by this library.

Throws: This can throw in case programmers specify a failure handler that throws exceptions on implementation check failures (not the default).

# See Also:

Throw on Failure, Implementation Checks

from_failure_handler const & `from_failure_handler const &

New failure handler functor to set.

` Set failure handler for preconditions.

Set a new failure handler and returns it.

Throws: This is declared `noexcept` (or `throw()` before C++11).

# See Also:

Throw on Failure, Preconditions

Same failure handler functor `f` passed as parameter (e.g., for concatenating function calls).

from_failure_handler Return failure handler currently set for preconditions.

This is often called only internally by this library.

Throws: This is declared `noexcept` (or `throw()` before C++11).

# See Also:

Throw on Failure, Preconditions

A copy of the failure handler currently set.

void `from

Operation that failed the contract assertion (when this function is called by this library, this parameter will never be `from_destructor` because destructors do not have preconditions).

` Call failure handler for preconditions.

This is often called only internally by this library.

Throws: This can throw in case programmers specify a failure handler that throws exceptions on contract assertion failures (not the default).

# See Also:

Throw on Failure, Preconditions

from_failure_handler const & `from_failure_handler const &

New failure handler functor to set.

` Set failure handler for postconditions.

Set a new failure handler and returns it.

Throws: This is declared `noexcept` (or `throw()` before C++11).

# See Also:

Throw on Failure, Postconditions

Same failure handler functor `f` passed as parameter (e.g., for concatenating function calls).

from_failure_handler Return failure handler currently set for postconditions.

This is often called only internally by this library.

Throws: This is declared `noexcept` (or `throw()` before C++11).

# See Also:

Throw on Failure, Postconditions

A copy of the failure handler currently set.

void `from

Operation that failed the contract assertion (e.g., this might be useful to program failure handler functors that never throw from destructors, not even when they are programmed by users to throw exceptions instead of terminating the program).

` Call failure handler for postconditions.

This is often called only internally by this library.

Throws: This can throw in case programmers specify a failure handler that throws exceptions on contract assertion failures (not the default).

# See Also:

Throw on Failure, Postconditions

from_failure_handler const & `from_failure_handler const &

New failure handler functor to set.

` Set failure handler for exception guarantees.

Set a new failure handler and returns it.

Throws: This is declared `noexcept` (or `throw()` before C++11).

# See Also:

Throw on Failure, Exception Guarantees

Same failure handler functor `f` passed as parameter (e.g., for concatenating function calls).

from_failure_handler Return failure handler currently set for exception guarantees.

This is often called only internally by this library.

Throws: This is declared `noexcept` (or `throw()` before C++11).

# See Also:

Throw on Failure, Exception Guarantees

A copy of the failure handler currently set.

void `from

Operation that failed the contract assertion.

` Call failure handler for exception guarantees.

This is often called only internally by this library.

Throws: This can throw in case programmers specify a failure handler that throws exceptions on contract assertion failures (not the default), however:

When this failure handler is called there is already an active exception (the one that caused the exception guarantees to be checked in the first place). Therefore, programming this failure handler to throw yet another exception will force C++ to automatically terminate the program.

# See Also:

Throw on Failure, Exception Guarantees

from_failure_handler const & `from_failure_handler const &

New failure handler functor to set.

` Set failure handler for old values copied at body.

Set a new failure handler and returns it.

Throws: This is declared `noexcept` (or `throw()` before C++11).

# See Also:

Throw on Failure, Old Values Copied at Body

Same failure handler functor `f` passed as parameter (e.g., for concatenating function calls).

from_failure_handler Return failure handler currently set for old values copied at body.

This is often called only internally by this library.

Throws: This is declared `noexcept` (or `throw()` before C++11).

# See Also:

Throw on Failure, Old Values Copied at Body

A copy of the failure handler currently set.

void `from

Operation that failed the old value copy (e.g., this might be useful to program failure handler functors that never throw from destructors, not even when they are programmed by users to throw exceptions instead of terminating the program).

` Call failure handler for old values copied at body.

This is often called only internally by this library.

Throws: This can throw in case programmers specify a failure handler that throws exceptions on contract assertion failures (not the default).

# See Also:

Throw on Failure, Old Values Copied at Body

from_failure_handler const & `from_failure_handler const &

New failure handler functor to set.

` Set failure handler for class invariants at entry.

Set a new failure handler and returns it.

Throws: This is declared `noexcept` (or `throw()` before C++11).

# See Also:

Throw on Failure, Class Invariants, Volatile Public Functions

Same failure handler functor `f` passed as parameter (e.g., for concatenating function calls).

from_failure_handler Return failure handler currently set for class invariants at entry.

This is often called only internally by this library.

Throws: This is declared `noexcept` (or `throw()` before C++11).

# See Also:

Throw on Failure, Class Invariants, Volatile Public Functions

A copy of the failure handler currently set.

void `from

Operation that failed the contract assertion (e.g., this might be useful to program failure handler functors that never throw from destructors, not even when they are programmed by users to throw exceptions instead of terminating the program).

` Call failure handler for class invariants at entry.

This is often called only internally by this library.

Throws: This can throw in case programmers specify a failure handler that throws exceptions on contract assertion failures (not the default).

# See Also:

Throw on Failure, Class Invariants, Volatile Public Functions

from_failure_handler const & `from_failure_handler const &

New failure handler functor to set.

` Set failure handler for class invariants at exit.

Set a new failure handler and returns it.

Throws: This is declared `noexcept` (or `throw()` before C++11).

# See Also:

Throw on Failure, Class Invariants, Volatile Public Functions

Same failure handler functor `f` passed as parameter (e.g., for concatenating function calls).

from_failure_handler Return failure handler currently set for class invariants at exit.

This is often called only internally by this library.

Throws: This is declared `noexcept` (or `throw()` before C++11).

# See Also:

Throw on Failure, Class Invariants, Volatile Public Functions

A copy of the failure handler currently set.

void `from

Operation that failed the contract assertion (e.g., this might be useful to program failure handler functors that never throw from destructors, not even when they are programmed by users to throw exceptions instead of terminating the program).

` Call failure handler for class invariants at exit.

This is often called only internally by this library.

Throws: This can throw in case programmers specify a failure handler that throws exceptions on contract assertion failures (not the default).

# See Also:

Throw on Failure, Class Invariants, Volatile Public Functions

from_failure_handler const & `from_failure_handler const &

New failure handler functor to set for both entry and exit invariants.

` Set failure handler for class invariants (at both entry and exit).

This is provided for convenience and it is equivalent to call both `boost::contract::set_entry_invariant_failure` and `boost::contract::set_exit_invariant_failure` with the same functor parameter `f`.

Throws: This is declared `noexcept` (or `throw()` before C++11).

# See Also:

Throw on Failure, Class Invariants, Volatile Public Functions

Same failure handler functor `f` passed as parameter (e.g., for concatenating function calls).

Specify preconditions, old values copied at body, postconditions, and exception guarantees.

Preconditions, old values copied at body, postconditions, and exception guarantees are all optionals but, when they are specified, they need to be specified in that order.

Allow to specify exception guarantees.

Allow to specify the functor this library will call to check exception guarantees. This object is internally constructed by the library when users specify contracts calling `boost::contract::function` and similar functions (that is why this class does not have a public constructor).

# See Also:

Exception Guarantees

Destruct this object.

Throws: This is declared `noexcept(false)` since C++11 to allow users to program failure handlers that throw exceptions on contract assertion failures (not the default, see Throw on Failure).

`specify_nothing` `F const &

Nullary functor called by this library to check exception guarantees `f()`. 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::except_failure`). This functor should capture variables by (constant) references (to access the values they will have at function exit).

` Allow to specify exception guarantees.

After exception guarantees have been specified, the object returned by this function does not allow to specify any additional contract.

Used to prevent setting other contract conditions after exception guarantees.

This class has no member function so it is used to prevent specifying additional functors to check any other contract. This object is internally constructed by the library when users specify contracts calling `boost::contract::function` and similar functions (that is why this class does not have a public constructor).

# See Also:

Tutorial

Destruct this object.

Throws: This is declared `noexcept(false)` since C++11 to allow users to program failure handlers that throw exceptions on contract assertion failures (not the default, see Throw on Failure).

void

Return type of the enclosing function declaring the contract if that is either a virtual or an overriding public function, otherwise this is always `void`. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.)

Allow to specify old values copied at body, postconditions, and exception guarantees.

Allow to specify functors this library will call to copy old values at body, check postconditions, and check exception guarantees. This object is internally constructed by the library when users specify contracts calling `boost::contract::function` and similar functions (that is why this class does not have a public constructor).

# See Also:

Old Values Copied at Body, Postconditions, Exception Guarantees

Destruct this object.

Throws: This is declared `noexcept(false)` since C++11 to allow users to program failure handlers that throw exceptions on contract assertion failures (not the default, see Throw on Failure).

`specify_postcondition_except`< VirtualResult > `F const &

Nullary functor called by this library `f()` to assign old value copies just before the body is executed but after entry invariants (when they apply) and preconditions are checked. Old value pointers within this functor call are usually assigned using `BOOST_CONTRACT_OLDOF`. Any exception thrown by a call to this functor will result in this library calling `boost::contract::old_failure` (because old values could not be copied to check postconditions and exception guarantees). This functor should capture old value pointers by references so they can be assigned (all other variables needed to evaluate old value expressions can be captured by (constant) value, or better by (constant) reference to avoid extra copies).

` Allow to specify old values copied at body.

It should often be sufficient to initialize old value pointers as soon as they are declared, without using this function (see Old Values Copied at Body).

After old values copied at body have been specified, the object returned by this function allows to optionally specify postconditions and exception guarantees.

`specify_except` `F const &

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 must be a nullary functor `f()` if `VirtualResult` is `void`, otherwise it must be a unary functor `f(result)` accepting the return value `result` as a parameter of type `VirtualResult const&` (to avoid extra copies of the return value, or of type `VirtualResult` or `VirtualResult const` if extra copies of the return value are irrelevant).

` Allow to specify postconditions.

After postconditions have been specified, the object returned by this function allows to optionally specify exception guarantees.

`specify_nothing` `F const &

Nullary functor called by this library to check exception guarantees `f()`. 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::except_failure`). This functor should capture variables by (constant) references (to access the values they will have at function exit).

` Allow to specify exception guarantees.

After exception guarantees have been specified, the object returned by this function does not allow to specify any additional contract.

void

Return type of the enclosing function declaring the contract if that is either a virtual or an overriding public function, otherwise this is always `void`. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.)

Allow to specify postconditions or exception guarantees.

Allow to specify functors this library will call to check postconditions or exception guarantees. This object is internally constructed by the library when users specify contracts calling `boost::contract::function` and similar functions (that is why this class does not have a public constructor).

# See Also:

Postconditions, Exception Guarantees

Destruct this object.

Throws: This is declared `noexcept(false)` since C++11 to allow users to program failure handlers that throw exceptions on contract assertion failures (not the default, see Throw on Failure).

`specify_except` `F const &

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 must be a nullary functor `f()` if `VirtualResult` is `void`, otherwise it must be a unary functor `f(result)` accepting the return value `result` as a parameter of type `VirtualResult const&` (to avoid extra copies of the return value, or of type `VirtualResult` or `VirtualResult const` if extra copies of the return value are irrelevant).

` Allow to specify postconditions.

After postconditions have been specified, the object returned by this function allows to optionally specify exception guarantees.

`specify_nothing` `F const &

Nullary functor called by this library to check exception guarantees `f()`. 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::except_failure`). This functor should capture variables by (constant) references (to access the values they will have at function exit).

` Allow to specify exception guarantees.

After exception guarantees have been specified, the object returned by this function does not allow to specify any additional contract.

void

Return type of the enclosing function declaring the contract if that is either a virtual or an overriding public function, otherwise this is always `void`. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.)

Allow to specify preconditions, old values copied at body, postconditions, and exception guarantees.

Allow to specify functors this library will call to check preconditions, copy old values at body, check postconditions, and check exception guarantees. This object is internally constructed by the library when users specify contracts calling `boost::contract::function` and similar functions (that is why this class does not have a public constructor).

# See Also:

Preconditions, Old Values Copied at Body, Postconditions, Exception Guarantees

Destruct this object.

Throws: This is declared `noexcept(false)` since C++11 to allow users to program failure handlers that throw exceptions on contract assertion failures (not the default, see Throw on Failure).

`specify_old_postcondition_except`< VirtualResult > `F const &

Nullary functor called by this library to check preconditions `f()`. 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::precondition_failure`). This functor should capture variables by (constant) value, or better by (constant) reference (to avoid extra copies).

` Allow to specify preconditions.

After preconditions have been specified, the object returned by this function allows to optionally specify old values copied at body, postconditions, and exception guarantees.

`specify_postcondition_except`< VirtualResult > `F const &

Nullary functor called by this library `f()` to assign old value copies just before the body is executed but after entry invariants (when they apply) and preconditions are checked. Old value pointers within this functor call are usually assigned using `BOOST_CONTRACT_OLDOF`. Any exception thrown by a call to this functor will result in this library calling `boost::contract::old_failure` (because old values could not be copied to check postconditions and exception guarantees). This functor should capture old value pointers by references so they can be assigned (all other variables needed to evaluate old value expressions can be captured by (constant) value, or better by (constant) reference to avoid extra copies).

` Allow to specify old values copied at body.

It should often be sufficient to initialize old value pointers as soon as they are declared, without using this function (see Old Values Copied at Body).

After old values copied at body have been specified, the object returned by this functions allows to optionally specify postconditions and exception guarantees.

`specify_except` `F const &

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 must be a nullary functor `f()` if `VirtualResult` is `void`, otherwise it must be a unary functor `f(result)` accepting the return value `result` as a parameter of type `VirtualResult const&` (to avoid extra copies of the return value, or of type `VirtualResult` or `VirtualResult const` if extra copies of the return value are irrelevant).

` Allow to specify postconditions.

After postconditions have been specified, the object returned by this function allows to optionally specify exception guarantees.

`specify_nothing` `F const &

Nullary functor called by this library to check exception guarantees `f()`. 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::except_failure`). This functor should capture variables by (constant) references (to access the values they will have at function exit).

` Allow to specify exception guarantees.

After exception guarantees have been specified, the object returned by this function does not allow to specify any additional contract.

Handle virtual public functions with contracts (for subcontracting).

Type of extra function parameter to handle contracts for virtual public functions (for subcontracting).

Virtual public functions (and therefore also public function overrides) declaring contracts using this library must specify an extra function parameter at the very end of their parameter list. This parameter must be a pointer to this class and it must have default value `0` or `nullptr` (this extra parameter is often named `v` in this documentation, but any name can be used):

    class u {
    public:
        virtual void f(int x, boost::contract::virtual_* v = 0) { // Declare `v`.
            ... // Contract declaration (which will use `v`) and function body.
        }

        ...
    };

In practice this extra parameter does not alter the calling interface of the enclosing function declaring the contract because it is always the very last parameter and it has a default value (so it can always be omitted when users call the function). This extra parameter must be passed to `boost::contract::public_function`, `BOOST_CONTRACT_OLDOF`, and all other operations of this library that accept a pointer to ``boost::contract::virtual_``. A part from that, this class is not intended to be directly used by programmers (and that is why this class does not have any public member and it is not copyable).

# See Also:

Virtual Public Functions, Public Function Overrides

Program contracts for destructors.

`specify_old_postcondition_except`

The type of the class containing the destructor declaring the contract. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.)

Class *

The object `this` from the scope of the enclosing destructor declaring the contract. (Destructors check all class invariants, including static and volatile invariants, see Class Invariants and Volatile Public Functions).

Program contracts for destructors.

This is used to specify postconditions, exception guarantees, old value copies at body, and check class invariants for destructors (destructors cannot have preconditions, see Destructor Calls):

    class u {
        friend class boost::contract::access;

        void invariant() const { // Optional (as for static and volatile).
            BOOST_CONTRACT_ASSERT(...);
            ...
        }

    public:
        ~u() {
            boost::contract::old_ptr<old_type> old_var;
            boost::contract::check c = boost::contract::destructor(this)
                // No `.precondition` (destructors have no preconditions).
                .old([&] { // Optional.
                    old_var = BOOST_CONTRACT_OLDOF(old_expr);
                    ...
                })
                .postcondition([&] { // Optional.
                    BOOST_CONTRACT_ASSERT(...);
                    ...
                })
                .except([&] { // Optional.
                    BOOST_CONTRACT_ASSERT(...);
                    ...
                })
            ;

            ... // Destructor body.
        }

        ...
    };

For optimization, this can be omitted for destructors that do not have postconditions and exception guarantees, within classes that have no invariants.

# See Also:

Destructors

The result of this function must be assigned to a variable of type ``boost::contract::check`` declared explicitly (i.e., without using C++11 `auto` declarations) and locally just before the code of the destructor body (otherwise this library will generate a run-time error, see `BOOST_CONTRACT_ON_MISSING_CHECK_DECL`).

Program contracts for (non-public) functions.

`specify_precondition_old_postcondition_except` Program contracts for non-member, private and protected functions.

This is used to specify preconditions, postconditions, exception guarantees, and old value copies at body for non-member, private and protected functions (these functions never check class invariants, see Function Calls):

    void f(...) {
        boost::contract::old_ptr<old_type> old_var;
        boost::contract::check c = boost::contract::function()
            .precondition([&] { // Optional.
                BOOST_CONTRACT_ASSERT(...);
                ...
            })
            .old([&] { // Optional.
                old_var = BOOST_CONTRACT_OLDOF(old_expr);
                ...
            })
            .postcondition([&] { // Optional.
                BOOST_CONTRACT_ASSERT(...);
                ...
            })
            .except([&] { // Optional.
                BOOST_CONTRACT_ASSERT(...);
                ...
            })
        ;

        ... // Function body.
    }

This can be used also to program contracts in implementation code for lambda functions, loops, and arbitrary blocks of code. For optimization, this can be omitted for code that does not have preconditions, postconditions, and exception guarantees.

# See Also:

Non-Member Functions, Private and Protected Functions, Lambdas, Loops, Code Blocks

The result of this function must be assigned to a variable of type ``boost::contract::check`` declared explicitly (i.e., without using C++11 `auto` declarations) and locally just before the code of the function body (otherwise this library will generate a run-time error, see `BOOST_CONTRACT_ON_MISSING_CHECK_DECL`).

Handle old values.

boost::is_copy_constructible< T >
Trait to check if an old value type can be copied or not.

By default, this unary boolean meta-function is equivalent to `boost::is_copy_constructible<T>` but programmers can chose to specialize it for user-defined types (in general some kind of specialization is also needed on compilers that do not support C++11, see `boost::is_copy_constructible`):

    class u; // Some user-defined type for which old values shall not be copied.

    namespace boost { namespace contract {
        template<> // Specialization to not copy old values of type `u`.
        struct is_old_value_copyable<u> : boost::false_type {};
    } } // namespace

A given old value type `T` is copied only if `boost::contract::is_old_value_copyable<T>::value` is `true`. A copyable old value type `V` is always copied using `boost::contract::old_value_copy<V>`. A non-copyable old value type `W` generates a compile-time error when `boost::contract::old_ptr<W>` is dereferenced, but instead leaves `boost::contract::old_ptr_if_copyable<W>` always null (without generating compile-time errors).

# See Also:

Old Value Requirements

Convert old value copies into old value pointers.

This class is usually only implicitly used by this library and it does not explicitly appear in user code (that is why this class does not have public constructors, etc.).

old_ptr_if_copyable< T >

Type of the pointed old value. The old value pointer will always be null if this type is not copyable (see `boost::contract::is_old_value_copyable`), but this library will not generate a compile-time error.

Convert this object to an actual old value pointer for which the old value type `T` might or not be copyable.

For example, this is implicitly called when assigning or initializing old value pointers of type `boost::contract::old_ptr_if_copyable`.

old_ptr< T >

Type of the pointed old value. This type must be copyable (see `boost::contract::is_old_value_copyable`), otherwise this library will generate a compile-time error when the old value pointer is dereferenced.

Convert this object to an actual old value pointer for which the old value type `T` must be copyable.

For example, this is implicitly called when assigning or initializing old value pointers of type `boost::contract::old_ptr`.

Type of the pointed old value. This type must be copyable (i.e., `boost::contract::is_old_value_copyable<T>::value` must be `true`), otherwise this pointer will always be null and this library will generate a compile-time error when the pointer is dereferenced.

Old value pointer that requires the pointed old value type to be copyable.

This pointer can be set to point an actual old value copy using either `BOOST_CONTRACT_OLDOF` or `boost::contract::make_old` (that is why this class does not have public non-default constructors):

    class u {
    public:
        virtual void f(..., boost::contract::virtual_* v = 0) {
            boost::contract::old_ptr<old_type> old_var = // For copyable `old_type`.
                    BOOST_CONTRACT_OLDOF(v, old_expr);
            ...
        }

        ...
    };

# See Also:

Old Values

Pointed old value type.
T
Construct this old value pointer as null.
T const & Dereference this old value pointer.

This will generate a run-time error if this pointer is null and a compile-time error if the pointed type `T` is not copyable (i.e., if `boost::contract::is_old_value_copyable<T>::value` is `false`).

The pointed old value. Contract assertions should not change the state of the program so this member function is `const` and it returns the old value as a reference to a constant object (see Constant Correctness).

T const * Structure-dereference this old value pointer.

This will generate a compile-time error if the pointed type `T` is not copyable (i.e., if `boost::contract::is_old_value_copyable<T>::value` is `false`).

A pointer to the old value (null if this old value pointer is null). Contract assertions should not change the state of the program so this member function is `const` and it returns the old value as a pointer to a constant object (see Constant Correctness).

bool Query if this old value pointer is null or not (safe-bool operator).

(This is implemented using safe-bool emulation on compilers that do not support C++11 explicit type conversion operators.)

True if this pointer is not null, false otherwise.

Type of the pointed old value. If this type is not copyable (i.e., `boost::contract::is_old_value_copyable<T>::value` is `false`), this pointer will always be null (but this library will not generate a compile-time error when this pointer is dereferenced).

Old value pointer that does not require the pointed old value type to be copyable.

This pointer can be set to point to an actual old value copy using either `BOOST_CONTRACT_OLDOF` or `boost::contract::make_old`:

    template<typename T> // Type `T` might or not be copyable.
    class u {
    public:
        virtual void f(..., boost::contract::virtual_* v = 0) {
            boost::contract::old_ptr_if_copyable<T> old_var =
                    BOOST_CONTRACT_OLDOF(v, old_expr);
            ...
                if(old_var) ... // Always null for non-copyable types.
            ...
        }

        ...
    };

# See Also:

Old Value Requirements

Pointed old value type.
T
Construct this old value pointer as null.
old_ptr
< T > const &

Old value pointer that requires the old value type to be copyable.

Construct this old value pointer from an old value pointer that requires the old value type to be copyable.

Ownership of the pointed value object is transferred to this pointer. This constructor is implicitly called by this library when assigning an object of this type using `BOOST_CONTRACT_OLDOF` (this constructor is usually not explicitly called by user code).

T const & Dereference this old value pointer.

This will generate a run-time error if this pointer is null, but no compile-time error is generated if the pointed type `T` is not copyable (i.e., if `boost::contract::is_old_value_copyable<T>::value` is `false`).

The pointed old value. Contract assertions should not change the state of the program so this member function is `const` and it returns the old value as a reference to a constant object (see Constant Correctness).

T const * Structure-dereference this old value pointer.

This will return null but will not generate a compile-time error if the pointed type `T` is not copyable (i.e., if `boost::contract::is_old_value_copyable<T>::value` is `false`).

A pointer to the old value (null if this old value pointer is null). Contract assertions should not change the state of the program so this member function is `const` and it returns the old value as a pointer to a constant object (see Constant Correctness).

bool Query if this old value pointer is null or not (safe-bool operator).

(This is implemented using safe-bool emulation on compilers that do not support C++11 explicit type conversion operators.)

True if this pointer is not null, false otherwise.

Convert user-specified expressions to old values.

This class is usually only implicitly used by this library and it does not explicitly appear in user code.

On older compilers that cannot correctly deduce the `boost::contract::is_old_value_copyable` trait used in the declaration of this class, programmers can manually specialize that trait to make sure that only old value types that are copyable are actually copied.

# See Also:

Old Value Requirements

Old value type.

T const &

Old value to be copied.

typename boost::enable_if< `boost::contract::is_old_value_copyable`< T > >::type *
0
Construct this object from the specified old value when the old value type is copy constructible.

The specified old value `old` is copied (one time only) using `boost::contract::old_value_copy`, in which case the related old value pointer will not be null (but no copy is made if postconditions and exception guarantees are not being checked, see `BOOST_CONTRACT_NO_OLDS`).

Old value type.

T const &

Old value (that will not be copied in this case).

typename boost::disable_if< `boost::contract::is_old_value_copyable`< T > >::type *
0
Construct this object from the specified old value when the old value type is not copyable.

The specified old value `old` cannot be copied in this case so it is not copied and the related old value pointer will always be null (thus calls to this constructor have no effect and they will likely be optimized away by most compilers).

Trait to copy an old value.

By default, the implementation of this trait uses `T's` copy constructor to make one single copy of the specified value. However, programmers can specialize this trait to copy old values using user-specific operations different from `T's` copy constructor. The default implementation of this trait is equivalent to:

    template<typename T>
    class old_value_copy {
    public:
        explicit old_value_copy(T const& old) :
            old_(old) // One single copy of value using T's copy constructor.
        {}

        T const& old() const { return old_; }

    private:
        T const old_; // The old value copy.
    };

This library will instantiate and use this trait only on old value types `T` that are copyable (i.e., for which `boost::contract::is_old_value_copyable<T>::value` is `true`).

# See Also:

Old Value Requirements

T const &

The old value to copy.

Construct this object by making one single copy of the specified old value.

This is the only operation within this library that actually copies old values. This ensures this library makes one and only one copy of an old value (if they actually need to be copied, see `BOOST_CONTRACT_NO_OLDS`).

T const & Return a (constant) reference to the old value that was copied.

Contract assertions should not change the state of the program so the old value copy is returned as `const` (see Constant Correctness).

`old_value` Return a "null" old value.

The related old value pointer will also be null. This function is usually only called by the code expanded by `BOOST_CONTRACT_OLDOF`.

# See Also:

No Macros

Null old value.

`old_pointer` ``old_value` const &

Old value which is usually implicitly constructed from the user old value expression to be copied (use the ternary operator `?:` to completely avoid to evaluate the old value expression when `boost::contract::copy_old()` is `false`).

` Make an old value pointer (but not for virtual public functions and public functions overrides).

The related old value pointer will not be null if the specified old value was actually copied. This function is usually only called by code expanded by `BOOST_CONTRACT_OLDOF(old_expr)` as in:

    boost::contract::make_old(boost::contract::copy_old() ? old_expr :
            boost::contract::null_old())

# See Also:

No Macros

Old value pointer (usually implicitly converted to either ``boost::contract::old_ptr`` or ``boost::contract::old_ptr_if_copyable`` in user code).

`old_pointer` ``virtual_` *

The trailing parameter of type ``boost::contract::virtual_```*` and default value `0` from the enclosing virtual or overriding public function declaring the contract.

` ``old_value` const &

Old value which is usually implicitly constructed from the user old value expression to be copied (use the ternary operator `?:` to completely avoid to evaluate the old value expression when `boost::contract::copy_old(v)` is `false`).

` Make an old value pointer (for virtual public functions and public functions overrides).

The related old value pointer will not be null if the specified old value was actually copied. This function is usually only called by code expanded by `BOOST_CONTRACT_OLDOF(v, old_expr)` as in:

    boost::contract::make_old(v, boost::contract::copy_old(v) ? old_expr :
            boost::contract::null_old())

# See Also:

No Macros

Old value pointer (usually implicitly converted to either ``boost::contract::old_ptr`` or ``boost::contract::old_ptr_if_copyable`` in user code).

bool Query if old values need to be copied (but not for virtual public functions and public function overrides).

For example, this function always returns false when both postconditions and exception guarantees are not being checked (see `BOOST_CONTRACT_NO_OLDS`). This function is usually only called by the code expanded by `BOOST_CONTRACT_OLDOF`.

# See Also:

No Macros

True if old values need to be copied, false otherwise.

bool ``virtual_` *

The trailing parameter of type ``boost::contract::virtual_```*` and default value `0` from the enclosing virtual or overriding public function declaring the contract.

` Query if old values need to be copied (for virtual public functions and public function overrides).

For example, this function always returns false when both postconditions and exception guarantees are not being checked (see `BOOST_CONTRACT_NO_OLDS`). In addition, this function returns false when overridden functions are being called subsequent times by this library to support subcontracting. This function is usually only called by the code expanded by `BOOST_CONTRACT_OLDOF`.

# See Also:

No Macros

True if old values need to be copied, false otherwise.

Macro typically used to copy an old value expression and assign it to an old value pointer.

The expression expanded by this macro should be assigned to an old value pointer of type ``boost::contract::old_ptr`` or ``boost::contract::old_ptr_if_copyable``. This is an overloaded variadic macro and it can be used in the following different ways.

1. From within virtual public functions and public functions overrides:

    BOOST_CONTRACT_OLDOF(v, old_expr)

2. From all other operations:

    BOOST_CONTRACT_OLDOF(old_expr)

Where:

- `v` is the extra parameter of type ``boost::contract::virtual_```*` and default value `0` from the enclosing virtual public function or public function overrides declaring the contract.

- `old_expr` is the expression to be evaluated and copied into 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_OLDOF(v, (old_expr))` will always work.)

On compilers that do not support variadic macros, programmers can manually copy old value expressions without using this macro (see No Macros).

# See Also:

Old Values

Handle public function overrides (for subcontracting).

Name of the override type trait this macro will declare. (This is not a variadic macro parameter but it should never contain commas because it is an identifier.)

Function name of the public function override. This macro is called just once even if the function name is overloaded (the same override type trait is used for all overloaded functions with the same name, see Function Overloads). (This is not a variadic macro parameter but it should never contain commas because it is an identifier.)

Declare an override type trait with an arbitrary name.

Declare the override type trait named `type_name` to pass as an explicit template parameter to `boost::contract::public_function` for public function overrides.

# See Also:

Named Overrides

Function name of the public function override. This macro is called just once even if the function name is overloaded (the same override type trait is used for all overloaded functions with the same name, see Function Overloads). (This is not a variadic macro parameter but it should never contain any comma because it is an identifier.)

Declare an override type trait named `override_func_name`.

Declare the override type trait named `override_func_name` to pass as an explicit template parameter to `boost::contract::public_function` for public function overrides. Use `BOOST_CONTRACT_NAMED_OVERRIDE` to generate an override type trait with a name different than `override_func_name` (usually not needed).

# See Also:

Public Function Overrides

A comma separated list of one or more function names of public function overrides. (Each function name should never contain commas because it is an identifier.)

Declare multiple override type traits at once naming them `override_...` (for convenience).

This variadic macro is provided for convenience as `BOOST_CONTRACT_OVERRIDES(f_1, f_2, ..., f_n)` expands to code equivalent to:

    BOOST_CONTRACT_OVERRIDE(f_1)
    BOOST_CONTRACT_OVERRIDE(f_2)
    ...
    BOOST_CONTRACT_OVERRIDE(f_n)

On compilers that do not support variadic macros, the override type traits can be equivalently programmed one-by-one calling `BOOST_CONTRACT_OVERRIDE` for each function name as shown above.

# See Also:

Public Function Overrides

Program contracts for public functions (including subcontracting).

The different overloads handle public functions that are static, virtual void, virtual non-void, overriding void, and overriding non-void.

`specify_precondition_old_postcondition_except`

The type of the class containing the static public function declaring the contract. This template parameter must be explicitly specified for static public functions (because they have no object `this` so there is no function argument from which this type template parameter can be automatically deduced by C++).

Program contracts for static public functions.

This is used to specify preconditions, postconditions, exception guarantees, old value copies at body, and check static class invariants for static public functions:

    class u {
        friend class boost::contract::access;

        static void static_invariant() { // Optional (as for non-static).
            BOOST_CONTRACT_ASSERT(...);
            ...
        }

    public:
        static void f(...) {
            boost::contract::old_ptr<old_type> old_var;
            boost::contract::check c = boost::contract::public_function<u>()
                .precondition([&] { // Optional.
                    BOOST_CONTRACT_ASSERT(...);
                    ...
                })
                .old([&] { // Optional.
                    old_var = BOOST_CONTRACT_OLDOF(old_expr);
                    ...
                })
                .postcondition([&] { // Optional.
                    BOOST_CONTRACT_ASSERT(...);
                    ...
                })
                .except([&] { // Optional.
                    BOOST_CONTRACT_ASSERT(...);
                    ...
                })
            ;

            ... // Function body.
        }

        ...
    };

For optimization, this can be omitted for static public functions that do not have preconditions, postconditions and exception guarantees, within classes that have no static invariants.

# See Also:

Static Public Functions

The result of this function must be assigned to a variable of type ``boost::contract::check`` declared explicitly (i.e., without using C++11 `auto` declarations) and locally just before the code of the static public function body (otherwise this library will generate a run-time error, see `BOOST_CONTRACT_ON_MISSING_CHECK_DECL`).

`specify_precondition_old_postcondition_except`

The type of the class containing the public function declaring the contract. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.)

Class *

The object `this` from the scope of the enclosing public function declaring the contract. This object might be mutable, `const`, `volatile`, or `const volatile` depending on the cv-qualifier of the enclosing function (volatile public functions will check volatile class invariants, see Volatile Public Functions).

Program contracts for public functions that are not static, not virtual, and do not not override.

This is used to specify preconditions, postconditions, exception guarantees, old value copies at body, and check class invariants for public functions that are not static, not virtual, and do not override:

    class u {
        friend class boost::contract::access;

        void invariant() const { // Optional (as for static and volatile).
            BOOST_CONTRACT_ASSERT(...);
            ...
        }

    public:
        void f(...) {
            boost::contract::old_ptr<old_type> old_var;
            boost::contract::check c = boost::contract::public_function(this)
                .precondition([&] { // Optional.
                    BOOST_CONTRACT_ASSERT(...);
                    ...
                })
                .old([&] { // Optional.
                    old_var = BOOST_CONTRACT_OLDOF(old_expr);
                    ...
                })
                .postcondition([&] { // Optional.
                    BOOST_CONTRACT_ASSERT(...);
                    ...
                })
                .except([&] { // Optional.
                    BOOST_CONTRACT_ASSERT(...);
                    ...
                })
            ;

            ... // Function body.
        }

        ...
    };

For optimization, this can be omitted for public functions that do not have preconditions, postconditions and exception guarantees, within classes that have no invariants.

# See Also:

Public Functions

The result of this function must be assigned to a variable of type ``boost::contract::check`` declared explicitly (i.e., without using C++11 `auto` declarations) and locally just before the code of the public function body (otherwise this library will generate a run-time error, see `BOOST_CONTRACT_ON_MISSING_CHECK_DECL`).

`specify_precondition_old_postcondition_except`

The type of the class containing the virtual public function declaring the contract. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.)

virtual_
*

The trailing parameter of type ``boost::contract::virtual_```*` and default value `0` from the enclosing virtual public function.

Class *

The object `this` from the scope of the enclosing virtual public function declaring the contract. This object might be mutable, `const`, `volatile`, or `const volatile` depending on the cv-qualifier of the enclosing function (volatile public functions will check volatile class invariants, see Volatile Public Functions).

Program contracts for void virtual public functions that do not override.

This is used to specify preconditions, postconditions, exception guarantees, old value copies at body, and check class invariants for public functions that are virtual, do not override, and return `void:`

    class u {
        friend class boost::contract::access;

        void invariant() const { // Optional (as for static and volatile).
            BOOST_CONTRACT_ASSERT(...);
            ...
        }

    public:
        void f(..., boost::contract::virtual_* v = 0) {
            boost::contract::old_ptr<old_type> old_var;
            boost::contract::check c = boost::contract::public_function(v, this)
                .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 virtual public function should always call `boost::contract::public_function` otherwise this library will not be able to correctly use it for subcontracting.

# See Also:

Virtual Public Functions

The result of this function must be assigned to a variable of type ``boost::contract::check`` declared explicitly (i.e., without using C++11 `auto` declarations) and locally just before the code of the public function body (otherwise this library will generate a run-time error, see `BOOST_CONTRACT_ON_MISSING_CHECK_DECL`).

`specify_precondition_old_postcondition_except`< VirtualResult >

This type must be the same as, or compatible with, the return type of the enclosing virtual public function declaring the contract (this library might not be able to generate a compile-time error if these types mismatch, but in general that will cause run-time errors or undefined behaviour). Alternatively, `boost::optional<return-type>` can also be used (see Optional Return Values). (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.)

The type of the class containing the virtual public function declaring the contract. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.)

virtual_
*

The trailing parameter of type ``boost::contract::virtual_```*` and default value `0` from the enclosing virtual public function.

VirtualResult &

A reference to the return value of the enclosing virtual public function declaring the contract. This is usually a local variable declared by the enclosing virtual public function just before the contract, but programmers must set it to the actual value being returned by the function at each `return` statement.

Class *

The object `this` from the scope of the enclosing virtual public function declaring the contract. This object might be mutable, `const`, `volatile`, or `const volatile` depending on the cv-qualifier of the enclosing function (volatile public functions will check volatile class invariants, see Volatile Public Functions).

Program contracts for non-void virtual public functions that do not override.

This is used to specify preconditions, postconditions, exception guarantees, old value copies at body, and check class invariants for public functions that are virtual, do not override, and do not return `void:`

    class u {
        friend class boost::contract::access;

        void invariant() const { // Optional (as for static and volatile).
            BOOST_CONTRACT_ASSERT(...);
            ...
        }

    public:
        t f(..., boost::contract::virtual_* v = 0) {
            t result;
            boost::contract::old_ptr<old_type> old_var;
            boost::contract::check c = boost::contract::public_function(
                    v, result, this)
                .precondition([&] { // Optional.
                    BOOST_CONTRACT_ASSERT(...);
                    ...
                })
                .old([&] { // Optional.
                    old_var = BOOST_CONTRACT_OLDOF(v, old_expr);
                    ...
                })
                .postcondition([&] (t const& result) { // Optional.
                    BOOST_CONTRACT_ASSERT(...);
                    ...
                })
                .except([&] { // Optional.
                    BOOST_CONTRACT_ASSERT(...);
                    ...
                })
            ;

            ... // Function body (use `return result = return_expr`).
        }

        ...
    };

A virtual public function should always call `boost::contract::public_function` otherwise this library will not be able to correctly use it for subcontracting.

# See Also:

Virtual Public Functions

The result of this function must be assigned to a variable of type ``boost::contract::check`` declared explicitly (i.e., without using C++11 `auto` declarations) and locally just before the code of the public function body (otherwise this library will generate a run-time error, see `BOOST_CONTRACT_ON_MISSING_CHECK_DECL`).

`specify_precondition_old_postcondition_except`

The type trait `override_function-name` declared using the `BOOST_CONTRACT_OVERRIDE` or related macros. This template parameter must be explicitly specified (because there is no function argument from which it can be automatically deduced by C++).

The function pointer type of the enclosing public function override declaring the contract. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.)

The type of the class containing the virtual public function declaring the contract. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.)

typename...

The types of all parameters passed to the enclosing public function override declaring the contract, but excluding the trailing parameter type `boost::contract::virtual_*`. On compilers that do not support variadic templates, this library internally implements this function using preprocessor meta-programming (in this case, the maximum number of supported arguments is defined by `BOOST_CONTRACT_MAX_ARGS`). (Usually these template parameters are automatically deduced by C++ and they do not need to be explicitly specified by programmers.)

virtual_
*

The trailing parameter of type ``boost::contract::virtual_```*` and default value `0` from the enclosing public function override.

F

A pointer to the enclosing public function override declaring the contract (but see Function Overloads).

Class *

The object `this` from the scope of the enclosing public function override declaring the contract. This object might be mutable, `const`, `volatile`, or `const volatile` depending on the cv-qualifier of the enclosing function (volatile public functions will check volatile class invariants, see Volatile Public Functions).

Args &...

All arguments passed to the enclosing public function override declaring the contract (by reference and in the order they appear in the enclosing function declaration), but excluding the trailing argument `v`.

Program contracts for void public functions overrides (virtual or not).

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 `boost::contract::public_function` otherwise this library will not be able to correctly use it for subcontracting.

# See Also:

Public Function Overrides

The result of this function must be assigned to a variable of type ``boost::contract::check`` declared explicitly (i.e., without using C++11 `auto` declarations) and locally just before the code of the public function body (otherwise this library will generate a run-time error, see `BOOST_CONTRACT_ON_MISSING_CHECK_DECL`).

`specify_precondition_old_postcondition_except`< VirtualResult >

The type trait `override_function-name` declared using the `BOOST_CONTRACT_OVERRIDE` or related macros. This template parameter must be explicitly specified (because there is no function argument from which it can be automatically deduced by C++).

This type must be the same as, or compatible with, the return type of the enclosing public function override declaring the contract (this library might not be able to generate a compile-time error if these types mismatch, but in general that will cause run-time errors or undefined behaviour). Alternatively, `boost::optional<return-type>` can also be used (see Optional Return Values). (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.)

The function pointer type of the enclosing public function override declaring the contract. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.)

The type of the class containing the virtual public function declaring the contract. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.)

typename...

The types of all parameters passed to the enclosing public function override declaring the contract, but excluding the trailing parameter type `boost::contract::virtual_*`. On compilers that do not support variadic templates, this library internally implements this function using preprocessor meta-programming (in this case, the maximum number of supported arguments is defined by `BOOST_CONTRACT_MAX_ARGS`). (Usually these template parameters are automatically deduced by C++ and they do not need to be explicitly specified by programmers.)

virtual_
*

The trailing parameter of type ``boost::contract::virtual_```*` and default value `0` from the enclosing public function override.

VirtualResult &

A reference to the return value of the enclosing public function override declaring the contract. This is usually a local variable declared by the enclosing public function override just before the contract, but programmers must set it to the actual value being returned by the function at each `return` statement.

F

A pointer to the enclosing public function override declaring the contract (but see Function Overloads).

Class *

The object `this` from the scope of the enclosing public function override declaring the contract. This object might be mutable, `const`, `volatile`, or `const volatile` depending on the cv-qualifier of the enclosing function (volatile public functions will check volatile class invariants, see Volatile Public Functions).

Args &...

All arguments passed to the enclosing public function override declaring the contract (by reference and in the order they appear in the enclosing function declaration), but excluding the trailing argument `v`.

Program contracts for non-void public functions overrides (virtual or not).

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 do not 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`.
        t f(t_1 a_1, ..., t_n a_n, boost::contract::virtual_* v = 0) {
            t result;
            boost::contract::old_ptr<old_type> old_var;
            boost::contract::check c = boost::contract::public_function<
                    override_f>(v, result, &u::f, this, a_1, ..., a_n)
                .precondition([&] { // Optional.
                    BOOST_CONTRACT_ASSERT(...);
                    ...
                })
                .old([&] { // Optional.
                    old_var = BOOST_CONTRACT_OLDOF(v, old_expr);
                    ...
                })
                .postcondition([&] (t const& result) { // Optional.
                    BOOST_CONTRACT_ASSERT(...);
                    ...
                })
                .except([&] { // Optional.
                    BOOST_CONTRACT_ASSERT(...);
                    ...
                })
            ;

            ... // Function body (use `return result = return_expr`).
        }

        ...
    };

A public function override should always call `boost::contract::public_function` otherwise this library will not be able to correctly use it for subcontracting.

# See Also:

Public Function Overrides

The result of this function must be assigned to a variable of type ``boost::contract::check`` declared explicitly (i.e., without using C++11 `auto` declarations) and locally just before the code of the public function body (otherwise this library will generate a run-time error, see `BOOST_CONTRACT_ON_MISSING_CHECK_DECL`).

Allow to disable contracts to completely remove their compile-time and run-time overhead.

This header automatically includes all header files `boost/contract/*.hpp` necessary to use its macros.

Almost all the macros defined in this header file are variadic macros. On compilers that do not support variadic macros, programmers can manually code `#ifndef BOOST_CONTRACT_NO_...` statements instead (see Disable Contract Compilation).

Program preconditions that can be completely disabled at compile-time.

`BOOST_CONTRACT_PRECONDITION(f)` expands to code equivalent to the following (note that no code is generated when `BOOST_CONTRACT_NO_PRECONDITIONS` is defined):

    #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
        .precondition(f)
    #endif

Where:

- `f` is the nullay functor called by this library to check preconditions `f()`. 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::precondition_failure`). This functor should capture variables by (constant) value, or better by (constant) reference (to avoid extra copies). (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.)

# See Also:

Disable Contract Compilation, Preconditions

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

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

    #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
        .postcondition(f)
    #endif

Where:

- `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

Program exception guarantees that can be completely disabled at compile-time.

`BOOST_CONTRACT_EXCEPT(f)` expands to code equivalent to the following (note that no code is generated when `BOOST_CONTRACT_NO_EXCEPTS` is defined):

    #ifndef BOOST_CONTRACT_NO_EXCEPTS
        .except(f)
    #endif

Where:

- `f` is the nullary functor called by this library to check exception guarantees `f()`. 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::except_failure`). This functor should capture variables by (constant) references (to access the values they will have at function exit). (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.)

# See Also:

Disable Contract Compilation, Exception Guarantees

Program old value copies at body that can be completely disabled at compile-time.

`BOOST_CONTRACT_OLD(f)` expands to code equivalent to the following (note that no code is generated when `BOOST_CONTRACT_NO_OLDS` is defined):

    #ifndef BOOST_CONTRACT_NO_OLDS
        .old(f)
    #endif

Where:

- `f` is the nullary functor called by this library `f()` to assign old value copies just before the body is execute but after entry invariants (when they apply) and preconditions are checked. Old value pointers within this functor call are usually assigned using `BOOST_CONTRACT_OLDOF`. Any exception thrown by a call to this functor will result in this library calling `boost::contract::old_failure` (because old values could not be copied to check postconditions and exception guarantees). This functor should capture old value pointers by references so they can be assigned (all other variables needed to evaluate old value expressions can be captured by (constant) value, or better by (constant) reference to avoid extra copies). (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.)

# See Also:

Disable Contract Compilation, Old Values Copied at Body

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

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

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

This is used to program old value copies for types that might or might not be copyable:

    template<typename T> // Type `T` might or not be copyable.
    class u {
    public:
        void f(...) {
            BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(old_type_a)(old_var_a);
            BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(old_type_b)(old_var_b,
                    old_expr_b);
            BOOST_CONTRACT_PUBLIC_FUNCTION(this)
                ...
                BOOST_CONTRACT_OLD([&] {
                    old_var_a = BOOST_CONTRACT_OLDOF(old_expr_a);
                    ...
                })
                ... // In postconditions or exception guarantees:
                    if(old_var_a) ... // Always null for non-copyable types.
                    if(old_var_b) ... // Always null for non-copyable types.
                ...
            ;

            ... // Function body.
        }

        virtual void g(..., boost::contract::virtual_* v = 0) {
            BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(old_type_a)(old_var_a);
            BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(old_type_b)(v, old_var_b,
                    old_expr_b);
            BOOST_CONTRACT_PUBLIC_FUNCTION(v, this)
                ...
                BOOST_CONTRACT_OLD([&] {
                    old_var_a = BOOST_CONTRACT_OLDOF(v, old_expr_a);
                    ...
                })
                ... // In postconditions or exception guarantees:
                    if(old_var_a) ... // Always null for non-copyable types.
                    if(old_var_b) ... // Always null for non-copyable types.
                ...
            ;

            ... // 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_IF_COPYABLE(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_if_copyable<old_type> old_var
    #endif

2. `BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(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_if_copyable<old_type> old_var =
                BOOST_CONTRACT_OLDOF(old_expr)
    #endif

3. `BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(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_if_copyable<old_type> old_var =
                BOOST_CONTRACT_OLDOF(v, old_expr)
    #endif

Where:

- `old_type` is the type of the pointed old value. If this type is not copyable (i.e., `boost::contract::is_old_value_copyable<old_type>::value` is `false`), this pointer will always be null, but this library will not generate a compile-time error when this pointer is dereferenced (see `BOOST_CONTRACT_OLD_PTR`). (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.)

- `v` is the extra trailing 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_IF_COPYABLE(old_type)(v, old_var, (old_expr))` will always work.)

# See Also:

Disable Contract Compilation, Old Value Requirements

Program (constant) class invariants that can be completely disabled at compile-time.

`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

Program volatile class invariants that can be completely disabled at compile-time.

`BOOST_CONTRACT_INVARIANT_VOLATILE`({ ... }) 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 volatile {
            ...
        }
    #endif

Where:

- { ... } is the definition of the function that checks class invariants for volatile public functions (see `BOOST_CONTRACT_INVARIANT` and `BOOST_CONTRACT_STATIC_INVARIANT`). The curly parenthesis are mandatory. 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, Volatile Public Functions

Program static class invariants that can be completely disabled at compile-time.

`BOOST_CONTRACT_STATIC_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
        static void BOOST_CONTRACT_STATIC_INVARIANT_FUNC() {
            ...
        }
    #endif

Where:

- { ... } is the definition of the function that checks class invariants for static public functions (see `BOOST_CONTRACT_INVARIANT` and `BOOST_CONTRACT_INVARIANT_VOLATILE`). The curly parenthesis are mandatory. 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

Program contracts that can be completely disabled at compile-time for constructors.

This is used together with `BOOST_CONTRACT_POSTCONDITION`, `BOOST_CONTRACT_EXCEPT`, and `BOOST_CONTRACT_OLD` to specify postconditions, exception guarantees, and old value copies at body that can be completely disabled at compile-time for constructors (see `BOOST_CONTRACT_CONSTRUCTOR_PRECONDITION` to specify preconditions for constructors):

    class u {
        friend class boost::contract::access;

        BOOST_CONTRACT_INVARIANT({ // Optional (as for static and volatile).
            BOOST_CONTRACT_ASSERT(...);
            ...
        })

    public:
        u(...) {
            BOOST_CONTRACT_OLD_PTR(old_type)(old_var);
            BOOST_CONTRACT_CONSTRUCTOR(this)
                // No `PRECONDITION` (use `CONSTRUCTOR_PRECONDITION` if needed).
                BOOST_CONTRACT_OLD([&] { // Optional.
                    old_var = BOOST_CONTRACT_OLDOF(old_epxr);
                    ...
                })
                BOOST_CONTRACT_POSTCONDITION([&] { // Optional.
                    BOOST_CONTRACT_ASSERT(...);
                    ...
                })
                BOOST_CONTRACT_EXCEPT([&] { // Optional.
                    BOOST_CONTRACT_ASSERT(...);
                    ...
                })
            ; // Trailing `;` is required.

            ... // Constructor body.
        }

        ...
    };

For optimization, this can be omitted for constructors that do not have postconditions and exception guarantees, within classes that have no invariants.

`BOOST_CONTRACT_CONSTRUCTOR(obj)` expands to code equivalent to the following (note that no code is generated when `BOOST_CONTRACT_NO_CONSTRUCTORS` is defined):

    #ifndef BOOST_CONTRACT_NO_CONSTRUCTORS
        boost::contract::check internal_var =
                boost::contract::constructor(obj)
    #endif

Where:

- `obj` is the object `this` from the scope of the enclosing constructor declaring the contract. Constructors check all class invariants, including static and volatile invariants (see `BOOST_CONTRACT_INVARIANT`, `BOOST_CONTRACT_STATIC_INVARIANT`, and `BOOST_CONTRACT_INVARIANT_VOLATILE`). (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.)

- `internal_var` is a variable name internally generated by this library (this name is unique but only on different line numbers so this macro cannot be expanded multiple times on the same line).

# See Also:

Disable Contract Compilation, Constructors

Program preconditions that can be disabled at compile-time for constructors.

This is used together with `BOOST_CONTRACT_CONSTRUCTOR` to specify contracts for constructors. Constructors that do not have preconditions do not use this macro. When at least one of the class constructors uses this macro, ``boost::contract::constructor_precondition`` must be the first and private base of the class declaring the constructor for which preconditions are programmed:

    class u
        #define BASES private boost::contract::constructor_precondition<u>, \
                public b
        : BASES
    {
        friend class boost::contract::access;

        typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types;
        #undef BASES

        ...

    public:
        explicit u(unsigned x) :
            BOOST_CONTRACT_CONSTRUCTOR_PRECONDITION(u)([&] {
                BOOST_CONTRACT_ASSERT(x != 0);
            }),
            b(1 / x)
        {
            ...
        }

        ...
    };

`BOOST_CONTRACT_CONSTRUCTOR_PRECONDITION(class_type)(f)` expands to code equivalent to the following (note that when `BOOST_CONTRACT_NO_PRECONDITIONS` is defined, this macro trivially expands to a default constructor call that is internally implemented to do nothing so this should have minimal to no overhead):

    // Guarded only by NO_PRECONDITIONS (and not also by NO_CONSTRUCTORS)
    // because for constructor's preconditions (not for postconditions, etc.).
    #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
        boost::contract::constructor_precondition<class_type>(f)
    #else // No-op call (likely optimized away, minimal to no overhead).
        boost::contract::constructor_precondition<class_type>()
    #endif

Where:

- `class_type` is the type of the class containing the constructor for which preconditions are being programmed. (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.)

- `f` is the nullary functor called by this library to check constructor preconditions `f()`. Assertions within this functor call are usually programmed using `BOOST_CONTRACT_ASSERT`, but any exception thrown by a call to this functor indicates a contract failure (and will result in this library calling `boost::contract::precondition_failure`). This functor should capture variables by (constant) value, or better by (constant) reference to avoid extra copies. (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.)

# See Also:

Disable Contract Compilation, Constructors

Program contracts that can be completely disabled at compile-time for destructors.

This is used together with `BOOST_CONTRACT_POSTCONDITION`, `BOOST_CONTRACT_EXCEPT`, and `BOOST_CONTRACT_OLD` to specify postconditions, exception guarantees, and old value copies at body that can be completely disabled at compile-time for destructors (destructors cannot have preconditions, see Destructor Calls):

    class u {
        friend class boost::contract::access;

        BOOST_CONTRACT_INVARIANT({ // Optional (as for static and volatile).
            BOOST_CONTRACT_ASSERT(...);
            ...
        })

    public:
        ~u() {
            BOOST_CONTRACT_OLD_PTR(old_type)(old_var);
            BOOST_CONTRACT_DESTRUCTOR(this)
                // No `PRECONDITION` (destructors have no preconditions).
                BOOST_CONTRACT_OLD([&] { // Optional.
                    old_var = BOOST_CONTRACT_OLDOF(old_expr);
                    ...
                })
                BOOST_CONTRACT_POSTCONDITION([&] { // Optional.
                    BOOST_CONTRACT_ASSERT(...);
                    ...
                })
                BOOST_CONTRACT_EXCEPT([&] { // Optional.
                    BOOST_CONTRACT_ASSERT(...);
                    ...
                })
            ; // Trailing `;` is required.

            ... // Destructor body.
        }

        ...
    };

For optimization, this can be omitted for destructors that do not have postconditions and exception guarantees, within classes that have no invariants.

`BOOST_CONTRACT_DESTRUCTOR(obj)` expands to code equivalent to the following (note that no code is generated when `BOOST_CONTRACT_NO_DESTRUCTORS` is defined):

    #ifndef BOOST_CONTRACT_NO_DESTRUCTORS
        boost::contract::check internal_var =
                boost::contract::destructor(obj)
    #endif

Where:

- `obj` is the object `this` from the scope of the enclosing destructor declaring the contract. Destructors check all class invariants, including static and volatile invariants (see Class Invariants and Volatile Public Functions). (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.)

- `internal_var` is a variable name internally generated by this library (this name is unique but only on different line numbers so this macro cannot be expanded multiple times on the same line).

# See Also:

Disable Contract Compilation, Destructors

Program contracts that can be completely disabled at compile-time for (non-public) functions.

This is used together with `BOOST_CONTRACT_PRECONDITION`, `BOOST_CONTRACT_POSTCONDITION`, `BOOST_CONTRACT_EXCEPT`, and `BOOST_CONTRACT_OLD` to specify preconditions, postconditions, exception guarantees, and old value copies at body that can be completely disabled at compile-time for (non-public) functions:

    void f(...) {
        BOOST_CONTRACT_OLD_PTR(old_type)(old_var);
        BOOST_CONTRACT_FUNCTION()
            BOOST_CONTRACT_PRECONDITION([&] { // Optional.
                BOOST_CONTRACT_ASSERT(...);
                ...
            })
            BOOST_CONTRACT_OLD([&] { // Optional.
                old_var = BOOST_CONTRACT_OLDOF(old_expr);
                ...
            })
            BOOST_CONTRACT_POSTCONDITION([&] { // Optional.
                BOOST_CONTRACT_ASSERT(...);
                ...
            })
            BOOST_CONTRACT_EXCEPT([&] { // Optional.
                BOOST_CONTRACT_ASSERT(...);
                ...
            })
        ; // Trailing `;` is required.

        ... // Function body.
    }

This can be used to program contracts for non-member functions but also for private and protected functions, lambda functions, loops, arbitrary blocks of code, etc. For optimization, this can be omitted for code that does not have preconditions, postconditions, and exception guarantees.

`BOOST_CONTRACT_FUNCTION()` expands to code equivalent to the following (note that no code is generated when `BOOST_CONTRACT_NO_FUNCTIONS` is defined):

    #ifndef BOOST_CONTRACT_NO_FUNCTIONS
        boost::contract::check internal_var =
                boost::contract::function()
    #endif

Where:

- `internal_var` is a variable name internally generated by this library (this name is unique but only on different line numbers so this macro cannot be expanded multiple times on the same line).

# See Also:

Disable Contract Compilation, Non-Member Functions, Private and Protected Functions, Lambdas, Loops, Code Blocks

Program contracts that can be completely disabled at compile-time for static public functions.

This is used together with `BOOST_CONTRACT_PRECONDITION`, `BOOST_CONTRACT_POSTCONDITION`, `BOOST_CONTRACT_EXCEPT`, and `BOOST_CONTRACT_OLD` to specify preconditions, postconditions, exception guarantees, and old value copies at body that can be completely disabled at compile-time for static public functions:

    class u {
        friend class boost::contract::access;

        BOOST_CONTRACT_STATIC_INVARIANT({ // Optional (as for non-static).
            BOOST_CONTRACT_ASSERT(...);
            ...
        })

    public:
        static void f(...) {
            BOOST_CONTRACT_OLD_PTR(old_type)(old_var);
            BOOST_CONTRACT_PUBLIC_FUNCTION(u)
                BOOST_CONTRACT_PRECONDITION([&] { // Optional.
                    BOOST_CONTRACT_ASSERT(...);
                    ...
                })
                BOOST_CONTRACT_OLD([&] { // Optional.
                    old_var = BOOST_CONTRACT_OLDOF(old_expr);
                    ...
                })
                BOOST_CONTRACT_POSTCONDITION([&] { // Optional.
                    BOOST_CONTRACT_ASSERT(...);
                    ...
                })
                BOOST_CONTRACT_EXCEPT([&] { // Optional.
                    BOOST_CONTRACT_ASSERT(...);
                    ...
                })
            ; // Trailing `;` is required.

            ... // Function body.
        }

        ...
    };

For optimization, this can be omitted for static public functions that do not have preconditions, postconditions and exception guarantees, within classes that have no static invariants.

`BOOST_CONTRACT_STATIC_PUBLIC_FUNCTION(class_type)` expands to code equivalent to the following (note that no code is generated when `BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS` is defined):

    #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS
        boost::contract::check internal_var =
                boost::contract::public_function<class_type>()
    #endif

Where:

- `class_type` is the type of the class containing the static public function declaring the contract. (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.)

- `internal_var` is a variable name internally generated by this library (this name is unique but only on different line numbers so this macro cannot be expanded multiple times on the same line).

# See Also:

Disable Contract Compilation, Static Public Functions

Program contracts that can be completely disabled at compile-time for non-static public functions that do not override.

This is used together with `BOOST_CONTRACT_PRECONDITION`, `BOOST_CONTRACT_POSTCONDITION`, `BOOST_CONTRACT_EXCEPT`, and `BOOST_CONTRACT_OLD` to specify preconditions, postconditions, exception guarantees, and old value copies at body that can be completely disabled at compile-time for non-static public functions (virtual or not, void or not) that do not override:

    class u {
        friend class boost::contract::access;

        BOOST_CONTRACT_INVARIANT({ // Optional (as for static and volatile).
            BOOST_CONTRACT_ASSERT(...);
            ...
        })

    public:
        // Non-virtual (same if void).
        t f(...) {
            t result;
            BOOST_CONTRACT_OLD_PTR(old_type)(old_var);
            BOOST_CONTRACT_PUBLIC_FUNCTION(this)
                BOOST_CONTRACT_PRECONDITION([&] { // Optional.
                    BOOST_CONTRACT_ASSERT(...);
                    ...
                })
                BOOST_CONTRACT_OLD([&] { // Optional.
                    old_var = BOOST_CONTRACT_OLDOF(old_expr);
                    ...
                })
                BOOST_CONTRACT_POSTCONDITION([&] { // Optional.
                    BOOST_CONTRACT_ASSERT(...);
                    ...
                })
                BOOST_CONTRACT_EXCEPT([&] { // Optional.
                    BOOST_CONTRACT_ASSERT(...);
                    ...
                })
            ; // Trailing `;` is required.

            ... // Function body (use `return result = return_expr`).
        }

        // Virtual and void.
        virtual void g(..., boost::contract::virtual_* v = 0) {
            BOOST_CONTRACT_OLD_PTR(old_type)(old_var);
            BOOST_CONTRACT_PUBLIC_FUNCTION(v, this)
                ...
                BOOST_CONTRACT_OLD([&] { // Optional.
                    old_var = BOOST_CONTRACT_OLDOF(v, old_expr);
                    ...
                })
                ...
            ; // Trailing `;` is required.

            ... // Function body.
        }

        // Virtual and non-void.
        virtual t h(..., boost::contract::virtual_* v = 0) {
            t result;
            BOOST_CONTRACT_OLD_PTR(old_type)(old_var);
            BOOST_CONTRACT_PUBLIC_FUNCTION(v, result, this)
                ...
                BOOST_CONTRACT_OLD([&] { // Optional.
                    old_var = BOOST_CONTRACT_OLDOF(v, old_expr);
                    ...
                })
                BOOST_CONTRACT_POSTCONDITION([&] (t const& result) { // Optional
                    BOOST_CONTRACT_ASSERT(...);
                    ...
                })
                ...
            ; // Trailing `;` is required.

            ... // Function body (use `return result = return_expr`).
        }

        ...
    };

For optimization, this can be omitted for non-virtual public functions that do not have preconditions, postconditions and exception guarantees, within classes that have no invariants. Virtual public functions should always use `BOOST_CONTRACT_PUBLIC_FUNCTION` otherwise this library will not be able to correctly use them for subcontracting.

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_PUBLIC_FUNCTIONS` is defined).

1. `BOOST_CONTRACT_PUBLIC_FUNCTION(obj)` expands to code equivalent to the following (for non-virtual public functions that are not static and do not override, returning void or not):

    #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS
        boost::contract::check internal_var =
                boost::contract::public_function(obj)
    #endif

2. `BOOST_CONTRACT_PUBLIC_FUNCTION(v, obj)` expands to code equivalent to the following (for virtual public functions that do not override, returning void):

    #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS
        boost::contract::check internal_var =
                boost::contract::public_function(v, obj)
    #endif

3. `BOOST_CONTRACT_PUBLIC_FUNCTION(v, r, obj)` expands to code equivalent to the following (for virtual public functions that do not override, not returning void):

    #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS
        boost::contract::check internal_var =
                boost::contract::public_function(v, r, obj)
    #endif

Where (these are all variadic macro parameters so they can contain commas not protected by round parenthesis):

- `v` is the extra parameter of type ``boost::contract::virtual_```*` and default value `0` from the enclosing virtual public function declaring the contract.

- `r` is a reference to the return value of the enclosing virtual public function declaring the contract. This is usually a local variable declared by the enclosing virtual public function just before the contract, but programmers must set it to the actual value being returned by the function at each `return` statement.

- `obj` is the object `this` from the scope of the enclosing public function declaring the contract. This object might be mutable, `const`, `volatile`, or `const volatile` depending on the cv-qualifier of the enclosing function (volatile public functions will check volatile class invariants, see Volatile Public Functions).

- `internal_var` is a variable name internally generated by this library (this name is unique but only on different line numbers so this macro cannot be expanded multiple times on the same line).

# See Also:

Disable Contract Compilation, Public Functions, Virtual Public Functions

Program contracts that can be completely disabled at compile-time for public function overrides.

This is used together with `BOOST_CONTRACT_PRECONDITION`, `BOOST_CONTRACT_POSTCONDITION`, `BOOST_CONTRACT_EXCEPT`, and `BOOST_CONTRACT_OLD` to specify preconditions, postconditions, exception guarantees, and old value copies at body that can be completely disabled at compile-time for public function overrides (virtual or not):

    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

        BOOST_CONTRACT_INVARIANT({ // Optional (as for static and volatile).
            BOOST_CONTRACT_ASSERT(...);
            ...
        })

        BOOST_CONTRACT_OVERRIDES(f, g)

    public:
        // Override from `b::f`, and void.
        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_PUBLIC_FUNCTION_OVERRIDE(override_f)(
                    v, &u::f, this, a_1, ..., a_n)
                BOOST_CONTRACT_PRECONDITION([&] { // Optional.
                    BOOST_CONTRACT_ASSERT(...);
                    ...
                })
                BOOST_CONTRACT_OLD([&] { // Optional.
                    old_var = BOOST_CONTRACT_OLDOF(v, old_expr);
                    ...
                })
                BOOST_CONTRACT_POSTCONDITION([&] { // Optional.
                    BOOST_CONTRACT_ASSERT(...);
                    ...
                })
                BOOST_CONTRACT_EXCEPT([&] { // Optional.
                    BOOST_CONTRACT_ASSERT(...);
                    ...
                })
            ; // Trailing `;` is required.

            ... // Function body.
        }

        // Override from `b::g`, and void.
        t g(t_1 a_1, ..., t_n a_n, boost::contract::virtual_* v = 0) {
            t result;
            BOOST_CONTRACT_OLD_PTR(old_type)(old_var);
            BOOST_CONTRACT_PUBLIC_FUNCTION_OVERRIDE(override_g)(
                    v, result, &u::g, this, a_1, ..., a_n)
                ...
                BOOST_CONTRACT_OLD([&] { // Optional.
                    old_var = BOOST_CONTRACT_OLDOF(v, old_expr);
                    ...
                })
                BOOST_CONTRACT_POSTCONDITION([&] (t const& result) { // Optional
                    BOOST_CONTRACT_ASSERT(...);
                    ...
                })
                ...
            ; // Trailing `;` is required.

            ... // Function body (use `return result = return_expr`).
        }

        ...
    };

Public function overrides should always use `BOOST_CONTRACT_PUBLIC_FUNCTION_OVERRIDE` otherwise this library will not be able to correctly use it for subcontracting.

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_PUBLIC_FUNCTIONS` is defined).

1. `BOOST_CONTRACT_PUBLIC_FUNCTION_OVERRIDE(override_type)(v, f, obj, ...)` expands to code equivalent to the following (for public function overrides that return void):

    #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS
        boost::contract::check internal_var = boost::contract::
                public_function<override_type>(v, f, obj, ...)
    #endif

2. `BOOST_CONTRACT_PUBLIC_FUNCTION_OVERRIDE(override_type)(v, r, f, obj, ...)` expands to code equivalent to the following (for public function overrides that do not return void):

    #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS
        boost::contract::check internal_var = boost::contract::
                public_function<override_type>(v, r, f, obj, ...)
    #endif

Where (these are all variadic macro parameters so they can contain commas not protected by round parenthesis):

- `override_type` is the type `override_function-name` declared using the `BOOST_CONTRACT_OVERRIDE` or related macros.

- `v` is the extra parameter of type ``boost::contract::virtual_```*` and default value `0` from the enclosing virtual public function declaring the contract.

- `r` is a reference to the return value of the enclosing virtual public function declaring the contract. This is usually a local variable declared by the enclosing virtual public function just before the contract, but programmers must set it to the actual value being returned by the function at each `return` statement.

- `f` is a pointer to the enclosing public function override declaring the contract.

- `obj` is the object `this` from the scope of the enclosing public function declaring the contract. This object might be mutable, `const`, `volatile`, or `const volatile` depending on the cv-qualifier of the enclosing function (volatile public functions will check volatile class invariants, see Volatile Public Functions).

- `...` is a variadic macro parameter listing all the arguments passed to the enclosing public function override declaring the contract (by reference and in the order they appear in the enclosing function declaration), but excluding the trailing argument `v`.

- `internal_var` is a variable name internally generated by this library (this name is unique but only on different line numbers so this macro cannot be expanded multiple times on the same line).

# See Also:

Disable Contract Compilation, Public Function Overrides