2 #ifndef BOOST_CONTRACT_CHECK_MACRO_HPP_
3 #define BOOST_CONTRACT_CHECK_MACRO_HPP_
5 // Copyright (C) 2008-2018 Lorenzo Caminiti
6 // Distributed under the Boost Software License, Version 1.0 (see accompanying
7 // file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
8 // See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
11 Macros for implementation checks.
14 // IMPORTANT: Included by contract_macro.hpp so must #if-guard all its includes.
15 #include <boost/contract/core/config.hpp>
16 #include <boost/contract/detail/noop.hpp>
18 #ifdef BOOST_CONTRACT_DETAIL_DOXYGEN
20 Preferred way to assert implementation check conditions.
22 It is preferred to use this macro instead of programming implementation
23 checks in a nullary functor passed to @RefClass{boost::contract::check}
24 constructor because this macro will completely remove implementation checks
25 from the code when @RefMacro{BOOST_CONTRACT_NO_CHECKS} is defined:
30 BOOST_CONTRACT_CHECK(cond);
35 @RefMacro{BOOST_CONTRACT_CHECK}, @RefMacro{BOOST_CONTRACT_CHECK_AUDIT}, and
36 @RefMacro{BOOST_CONTRACT_CHECK_AXIOM} are the three assertion levels
37 predefined by this library for implementation checks.
39 @see @RefSect{advanced.implementation_checks, Implementation Checks}
41 @param cond Boolean condition to check within implementation code (function
43 (This is not a variadic macro parameter so any comma it might
44 contain must be protected by round parenthesis and
45 @c BOOST_CONTRACT_CHECK((cond)) will always work.)
47 #define BOOST_CONTRACT_CHECK(cond)
48 #elif !defined(BOOST_CONTRACT_NO_CHECKS)
49 #include <boost/contract/detail/check.hpp>
50 #include <boost/contract/detail/assert.hpp>
52 #define BOOST_CONTRACT_CHECK(cond) \
53 BOOST_CONTRACT_DETAIL_CHECK(BOOST_CONTRACT_DETAIL_ASSERT(cond))
55 #define BOOST_CONTRACT_CHECK(cond) /* nothing */
58 #ifdef BOOST_CONTRACT_DETAIL_DOXYGEN
60 Preferred way to assert implementation check conditions that are
61 computationally expensive, at least compared to the computational cost of
62 executing the function body.
64 The specified condition will always be compiled and validated syntactically,
65 but it will not be checked at run-time unless
66 @RefMacro{BOOST_CONTRACT_AUDITS} is defined (undefined by default).
67 This macro is defined by code equivalent to:
70 #ifdef BOOST_CONTRACT_AUDITS
71 #define BOOST_CONTRACT_CHECK_AUDIT(cond) \
72 BOOST_CONTRACT_CHECK(cond)
74 #define BOOST_CONTRACT_CHECK_AUDIT(cond) \
75 BOOST_CONTRACT_CHECK(true || cond)
79 @RefMacro{BOOST_CONTRACT_CHECK}, @RefMacro{BOOST_CONTRACT_CHECK_AUDIT}, and
80 @RefMacro{BOOST_CONTRACT_CHECK_AXIOM} are the three assertion levels
81 predefined by this library for implementation checks.
82 If there is a need, programmers are free to implement their own assertion
83 levels defining macros similar to the one above.
85 @see @RefSect{extras.assertion_levels, Assertion Levels}
87 @param cond Boolean condition to check within implementation code (function
89 (This is not a variadic macro parameter so any comma it might
90 contain must be protected by round parenthesis and
91 @c BOOST_CONTRACT_CHECK_AUDIT((cond)) will always work.)
93 #define BOOST_CONTRACT_CHECK_AUDIT(cond)
94 #elif defined(BOOST_CONTRACT_AUDITS)
95 #define BOOST_CONTRACT_CHECK_AUDIT(cond) \
96 BOOST_CONTRACT_CHECK(cond)
98 #define BOOST_CONTRACT_CHECK_AUDIT(cond) \
99 BOOST_CONTRACT_DETAIL_NOEVAL(cond)
103 Preferred way to document in the code implementation check conditions that are
104 computationally prohibitive, at least compared to the computational cost of
105 executing the function body.
107 The specified condition will always be compiled and validated syntactically, but
108 it will never be checked at run-time.
109 This macro is defined by code equivalent to:
112 #define BOOST_CONTRACT_CHECK_AXIOM(cond) \
113 BOOST_CONTRACT_CHECK(true || cond)
116 @RefMacro{BOOST_CONTRACT_CHECK}, @RefMacro{BOOST_CONTRACT_CHECK_AUDIT}, and
117 @RefMacro{BOOST_CONTRACT_CHECK_AXIOM} are the three assertion levels predefined
118 by this library for implementation checks.
119 If there is a need, programmers are free to implement their own assertion levels
120 defining macros similar to the one above.
122 @see @RefSect{extras.assertion_levels, Assertion Levels}
124 @param cond Boolean condition to check within implementation code (function
126 (This is not a variadic macro parameter so any comma it might
127 contain must be protected by round parenthesis and
128 @c BOOST_CONTRACT_CHECK_AXIOM((cond)) will always work.)
130 #define BOOST_CONTRACT_CHECK_AXIOM(cond) \
131 BOOST_CONTRACT_DETAIL_NOEVAL(cond)
133 #endif // #include guard