Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

Reference

Header <boost/contract.hpp>
Header <boost/contract/assert.hpp>
Header <boost/contract/base_types.hpp>
Header <boost/contract/call_if.hpp>
Header <boost/contract/check.hpp>
Header <boost/contract/constructor.hpp>
Header <boost/contract/core/access.hpp>
Header <boost/contract/core/check_macro.hpp>
Header <boost/contract/core/config.hpp>
Header <boost/contract/core/constructor_precondition.hpp>
Header <boost/contract/core/exception.hpp>
Header <boost/contract/core/specify.hpp>
Header <boost/contract/core/virtual.hpp>
Header <boost/contract/destructor.hpp>
Header <boost/contract/function.hpp>
Header <boost/contract/old.hpp>
Header <boost/contract/override.hpp>
Header <boost/contract/public_function.hpp>
Header <boost/contract_macro.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

Assert contract conditions.


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

Specify inheritance form base classes (for subcontracting).


BOOST_CONTRACT_BASE_TYPES(...)

Statically disable compilation and execution of functor calls.

[Note] 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);
  }
}

RAII object that checks contracts.

namespace boost {
  namespace contract {
    class check;
  }
}

Program contracts for constructors.

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

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

namespace boost {
  namespace contract {
    class access;
  }
}

Macros for implementation checks.


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

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

Program preconditions for constructors.

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

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 &);
  }
}

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;
  }
}

Handle virtual public functions with contracts (for subcontracting).

namespace boost {
  namespace contract {
    class virtual_;
  }
}

Program contracts for destructors.

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

Program contracts for (non-public) functions.

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

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_ *);
  }
}

Handle public function overrides (for subcontracting).


BOOST_CONTRACT_NAMED_OVERRIDE(type_name, func_name)
BOOST_CONTRACT_OVERRIDE(func_name)
BOOST_CONTRACT_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.

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 &...);
  }
}

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

PrevUpHomeNext