Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / contract / core / check_macro.hpp
1
2 #ifndef BOOST_CONTRACT_CHECK_MACRO_HPP_
3 #define BOOST_CONTRACT_CHECK_MACRO_HPP_
4
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
9
10 /** @file
11 Macros for implementation checks.
12 */
13
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>
17
18 #ifdef BOOST_CONTRACT_DETAIL_DOXYGEN
19     /**
20     Preferred way to assert implementation check conditions.
21     
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:
26
27     @code
28     void f() {
29         ...
30         BOOST_CONTRACT_CHECK(cond);
31         ...
32     }
33     @endcode
34     
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.
38
39     @see @RefSect{advanced.implementation_checks, Implementation Checks}
40
41     @param cond Boolean condition to check within implementation code (function
42                 body, etc.).
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.)
46     */
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>
51
52     #define BOOST_CONTRACT_CHECK(cond) \
53         BOOST_CONTRACT_DETAIL_CHECK(BOOST_CONTRACT_DETAIL_ASSERT(cond))
54 #else
55     #define BOOST_CONTRACT_CHECK(cond) /* nothing */
56 #endif
57
58 #ifdef BOOST_CONTRACT_DETAIL_DOXYGEN
59     /**
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.
63
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:
68
69     @code
70     #ifdef BOOST_CONTRACT_AUDITS
71         #define BOOST_CONTRACT_CHECK_AUDIT(cond) \
72             BOOST_CONTRACT_CHECK(cond)
73     #else
74         #define BOOST_CONTRACT_CHECK_AUDIT(cond) \
75             BOOST_CONTRACT_CHECK(true || cond)
76     #endif
77     @endcode
78
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.
84
85     @see @RefSect{extras.assertion_levels, Assertion Levels}
86
87     @param cond Boolean condition to check within implementation code (function
88                 body, etc.).
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.)
92     */
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)
97 #else
98     #define BOOST_CONTRACT_CHECK_AUDIT(cond) \
99         BOOST_CONTRACT_DETAIL_NOEVAL(cond)
100 #endif
101     
102 /**
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.
106
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:
110
111 @code
112 #define BOOST_CONTRACT_CHECK_AXIOM(cond) \
113     BOOST_CONTRACT_CHECK(true || cond)
114 @endcode
115
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.
121
122 @see @RefSect{extras.assertion_levels, Assertion Levels}
123
124 @param cond Boolean condition to check within implementation code (function
125             body, etc.).
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.)
129 */
130 #define BOOST_CONTRACT_CHECK_AXIOM(cond) \
131     BOOST_CONTRACT_DETAIL_NOEVAL(cond)
132
133 #endif // #include guard
134