| Home | Libraries | People | FAQ | More

## Reference

### Header <boost/contract.hpp>

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

### Header <boost/contract/assert.hpp>

Assert contract conditions.

    BOOST_CONTRACT_ASSERT(cond)
    BOOST_CONTRACT_ASSERT_AUDIT(cond)
    BOOST_CONTRACT_ASSERT_AXIOM(cond)

### Header <boost/contract/base_types.hpp>

Specify inheritance form base classes (for subcontracting).

    BOOST_CONTRACT_BASE_TYPES(...)

### Header <boost/contract/call_if.hpp>

Statically disable compilation and execution of functor calls.

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

    namespace boost {
      namespace contract {
        template<bool Pred, typename Then, typename ThenResult = internal_type>
          struct call_if_statement;

        template<typename Then>
          struct call_if_statement<false, Then, internal_type>;
        template<typename Then> struct call_if_statement<true, Then, internal_type>;
        template<typename Then, typename ThenResult>
          struct call_if_statement<true, Then, ThenResult>;
        template<typename Then> struct call_if_statement<true, Then, void>;
        template<bool Pred, typename Then>
          call_if_statement< Pred, Then > call_if_c(Then);
        template<typename Pred, typename Then>
          call_if_statement< Pred::value, Then > call_if(Then);
        template<bool Pred, typename Then> bool condition_if_c(Then, bool = true);
        template<typename Pred, typename Then>
          bool condition_if(Then, bool = true);
      }
    }

### Header <boost/contract/check.hpp>

RAII object that checks contracts.

    namespace boost {
      namespace contract {
        class check;
      }
    }

### Header <boost/contract/constructor.hpp>

Program contracts for constructors.

    namespace boost {
      namespace contract {
        template<typename Class>
          specify_old_postcondition_except constructor(Class *);
      }
    }

### Header <boost/contract/core/access.hpp>

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

    namespace boost {
      namespace contract {
        class access;
      }
    }

### Header <boost/contract/core/check_macro.hpp>

Macros for implementation checks.

    BOOST_CONTRACT_CHECK(cond)
    BOOST_CONTRACT_CHECK_AUDIT(cond)
    BOOST_CONTRACT_CHECK_AXIOM(cond)

### Header <boost/contract/core/config.hpp>

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

    BOOST_CONTRACT_DYN_LINK
    BOOST_CONTRACT_STATIC_LINK
    BOOST_CONTRACT_HEADER_ONLY
    BOOST_CONTRACT_DISABLE_THREADS
    BOOST_CONTRACT_MAX_ARGS
    BOOST_CONTRACT_BASES_TYPEDEF
    BOOST_CONTRACT_INVARIANT_FUNC
    BOOST_CONTRACT_STATIC_INVARIANT_FUNC
    BOOST_CONTRACT_PERMISSIVE
    BOOST_CONTRACT_ON_MISSING_CHECK_DECL
    BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION
    BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION
    BOOST_CONTRACT_AUDITS
    BOOST_CONTRACT_NO_CHECKS
    BOOST_CONTRACT_NO_PRECONDITIONS
    BOOST_CONTRACT_NO_POSTCONDITIONS
    BOOST_CONTRACT_NO_EXCEPTS
    BOOST_CONTRACT_NO_ENTRY_INVARIANTS
    BOOST_CONTRACT_NO_EXIT_INVARIANTS
    BOOST_CONTRACT_NO_INVARIANTS
    BOOST_CONTRACT_NO_OLDS
    BOOST_CONTRACT_NO_CONSTRUCTORS
    BOOST_CONTRACT_NO_DESTRUCTORS
    BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS
    BOOST_CONTRACT_NO_FUNCTIONS
    BOOST_CONTRACT_NO_CONDITIONS
    BOOST_CONTRACT_NO_ALL

### Header <boost/contract/core/constructor_precondition.hpp>

Program preconditions for constructors.

    namespace boost {
      namespace contract {
        template<typename Class> class constructor_precondition;
      }
    }

### Header <boost/contract/core/exception.hpp>

Handle contract assertion failures.

    namespace boost {
      namespace contract {
        class assertion_failure;
        class bad_virtual_result_cast;
        class exception;

        enum from;
        typedef boost::function< void(from)> from_failure_handler;
        typedef boost::function< void()> failure_handler;
        failure_handler const & set_check_failure(failure_handler const &);
        failure_handler get_check_failure();
        void check_failure();
        from_failure_handler const &
        set_precondition_failure(from_failure_handler const &);
        from_failure_handler get_precondition_failure();
        void precondition_failure(from);
        from_failure_handler const &
        set_postcondition_failure(from_failure_handler const &);
        from_failure_handler get_postcondition_failure();
        void postcondition_failure(from);
        from_failure_handler const &
        set_except_failure(from_failure_handler const &);
        from_failure_handler get_except_failure();
        void except_failure(from);
        from_failure_handler const & set_old_failure(from_failure_handler const &);
        from_failure_handler get_old_failure();
        void old_failure(from);
        from_failure_handler const &
        set_entry_invariant_failure(from_failure_handler const &);
        from_failure_handler get_entry_invariant_failure();
        void entry_invariant_failure(from);
        from_failure_handler const &
        set_exit_invariant_failure(from_failure_handler const &);
        from_failure_handler get_exit_invariant_failure();
        void exit_invariant_failure(from);
        from_failure_handler const &
        set_invariant_failure(from_failure_handler const &);
      }
    }

### Header <boost/contract/core/specify.hpp>

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.

    namespace boost {
      namespace contract {
        class specify_except;
        class specify_nothing;
        template<typename VirtualResult = void>
          class specify_old_postcondition_except;
        template<typename VirtualResult = void> class specify_postcondition_except;
        template<typename VirtualResult = void>
          class specify_precondition_old_postcondition_except;
      }
    }

### Header <boost/contract/core/virtual.hpp>

Handle virtual public functions with contracts (for subcontracting).

    namespace boost {
      namespace contract {
        class virtual_;
      }
    }

### Header <boost/contract/destructor.hpp>

Program contracts for destructors.

    namespace boost {
      namespace contract {
        template<typename Class>
          specify_old_postcondition_except destructor(Class *);
      }
    }

### Header <boost/contract/function.hpp>

Program contracts for (non-public) functions.

    namespace boost {
      namespace contract {
        specify_precondition_old_postcondition_except function();
      }
    }

### Header <boost/contract/old.hpp>

Handle old values.

    BOOST_CONTRACT_OLDOF(...)

    namespace boost {
      namespace contract {
        template<typename T> struct is_old_value_copyable;

        class old_pointer;
        template<typename T> class old_ptr;
        template<typename T> class old_ptr_if_copyable;
        class old_value;

        template<typename T> struct old_value_copy;
        old_value null_old();
        old_pointer make_old(old_value const &);
        old_pointer make_old(virtual_ *, old_value const &);
        bool copy_old();
        bool copy_old(virtual_ *);
      }
    }

### Header <boost/contract/override.hpp>

Handle public function overrides (for subcontracting).

    BOOST_CONTRACT_NAMED_OVERRIDE(type_name, func_name)
    BOOST_CONTRACT_OVERRIDE(func_name)
    BOOST_CONTRACT_OVERRIDES(...)

### Header <boost/contract/public_function.hpp>

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.

    namespace boost {
      namespace contract {
        template<typename Class>
          specify_precondition_old_postcondition_except public_function();
        template<typename Class>
          specify_precondition_old_postcondition_except public_function(Class *);
        template<typename Class>
          specify_precondition_old_postcondition_except
          public_function(virtual_ *, Class *);
        template<typename VirtualResult, typename Class>
          specify_precondition_old_postcondition_except< VirtualResult >
          public_function(virtual_ *, VirtualResult &, Class *);
        template<typename Override, typename F, typename Class, typename... Args>
          specify_precondition_old_postcondition_except
          public_function(virtual_ *, F, Class *, Args &...);
        template<typename Override, typename VirtualResult, typename F,
                 typename Class, typename... Args>
          specify_precondition_old_postcondition_except< VirtualResult >
          public_function(virtual_ *, VirtualResult &, F, Class *, Args &...);
      }
    }

### Header <boost/contract_macro.hpp>

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

    BOOST_CONTRACT_PRECONDITION(...)
    BOOST_CONTRACT_POSTCONDITION(...)
    BOOST_CONTRACT_EXCEPT(...)
    BOOST_CONTRACT_OLD(...)
    BOOST_CONTRACT_OLD_PTR(...)
    BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(...)
    BOOST_CONTRACT_INVARIANT(...)
    BOOST_CONTRACT_INVARIANT_VOLATILE(...)
    BOOST_CONTRACT_STATIC_INVARIANT(...)
    BOOST_CONTRACT_CONSTRUCTOR(...)
    BOOST_CONTRACT_CONSTRUCTOR_PRECONDITION(...)
    BOOST_CONTRACT_DESTRUCTOR(...)
    BOOST_CONTRACT_FUNCTION()
    BOOST_CONTRACT_STATIC_PUBLIC_FUNCTION(...)
    BOOST_CONTRACT_PUBLIC_FUNCTION(...)
    BOOST_CONTRACT_PUBLIC_FUNCTION_OVERRIDE(...)