]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/contract/assert.hpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / boost / contract / assert.hpp
1
2 #ifndef BOOST_CONTRACT_ASSERT_HPP_
3 #define BOOST_CONTRACT_ASSERT_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 Assert contract conditions.
12 */
13
14 #include <boost/contract/core/config.hpp>
15 #include <boost/contract/detail/noop.hpp>
16
17 #ifdef BOOST_CONTRACT_DETAIL_DOXYGEN
18 /**
19 Preferred way to assert contract conditions.
20
21 Any exception thrown from within a contract (preconditions, postconditions,
22 exception guarantees, old value copies at body, class invariants, etc.) is
23 interpreted by this library as a contract failure.
24 Therefore, users can program contract assertions manually throwing an
25 exception when an asserted condition is checked to be @c false (this
26 library will then call the appropriate contract failure handler
27 @RefFunc{boost::contract::precondition_failure}, etc.).
28 However, it is preferred to use this macro because it expands to
29 code that throws @RefClass{boost::contract::assertion_failure} with the
30 correct assertion file name (using <c>__FILE__</c>), line number (using
31 <c>__LINE__</c>), and asserted condition code so to produce informative
32 error messages.
33
34 @RefMacro{BOOST_CONTRACT_ASSERT}, @RefMacro{BOOST_CONTRACT_ASSERT_AUDIT},
35 and @RefMacro{BOOST_CONTRACT_ASSERT_AXIOM} are the three assertion levels
36 predefined by this library.
37
38 @see @RefSect{tutorial.preconditions, Preconditions},
39 @RefSect{tutorial.postconditions, Postconditions},
40 @RefSect{tutorial.exception_guarantees, Exceptions Guarantees},
41 @RefSect{tutorial.class_invariants, Class Invariants}
42
43 @param cond Boolean contract condition to check.
44 (This is not a variadic macro parameter so any comma it might
45 contain must be protected by round parenthesis,
46 @c BOOST_CONTRACT_ASSERT((cond)) will always work.)
47 */
48 // This must be an expression (a trivial one so the compiler can optimize it
49 // away). It cannot an empty code block `{}`, etc. otherwise code like
50 // `if(...) ASSERT(...); else ASSERT(...);` won't work when NO_ALL.
51 #define BOOST_CONTRACT_ASSERT(cond)
52 #elif !defined(BOOST_CONTRACT_NO_ALL)
53 #include <boost/contract/detail/assert.hpp>
54 #define BOOST_CONTRACT_ASSERT(cond) \
55 BOOST_CONTRACT_DETAIL_ASSERT(cond) /* no `;` here */
56 #else
57 // This must be an expression (a trivial one so the compiler can optimize it
58 // away). It cannot an empty code block `{}`, etc. otherwise code like
59 // `if(...) ASSERT(...); else ASSERT(...);` won't work when NO_ALL.
60 #define BOOST_CONTRACT_ASSERT(cond) \
61 BOOST_CONTRACT_DETAIL_NOOP
62 #endif
63
64 #ifdef BOOST_CONTRACT_DETAIL_DOXYGEN
65 /**
66 Preferred way to assert contract conditions that are computationally
67 expensive, at least compared to the cost of executing the function body.
68
69 The asserted condition will always be compiled and validated syntactically,
70 but it will not be checked at run-time unless
71 @RefMacro{BOOST_CONTRACT_AUDITS} is defined (undefined by default).
72 This macro is defined by code equivalent to:
73
74 @code
75 #ifdef BOOST_CONTRACT_AUDITS
76 #define BOOST_CONTRACT_ASSERT_AUDIT(cond) \
77 BOOST_CONTRACT_ASSERT(cond)
78 #else
79 #define BOOST_CONTRACT_ASSERT_AUDIT(cond) \
80 BOOST_CONTRACT_ASSERT(true || cond)
81 #endif
82 @endcode
83
84 @RefMacro{BOOST_CONTRACT_ASSERT}, @RefMacro{BOOST_CONTRACT_ASSERT_AUDIT},
85 and @RefMacro{BOOST_CONTRACT_ASSERT_AXIOM} are the three assertion levels
86 predefined by this library.
87 If there is a need, programmers are free to implement their own assertion
88 levels defining macros similar to the one above.
89
90 @see @RefSect{extras.assertion_levels, Assertion Levels}
91
92 @param cond Boolean contract condition to check.
93 (This is not a variadic macro parameter so any comma it might
94 contain must be protected by round parenthesis,
95 @c BOOST_CONTRACT_ASSERT_AUDIT((cond)) will always work.)
96 */
97 #define BOOST_CONTRACT_ASSERT_AUDIT(cond)
98 #elif defined(BOOST_CONTRACT_AUDITS)
99 #define BOOST_CONTRACT_ASSERT_AUDIT(cond) \
100 BOOST_CONTRACT_ASSERT(cond)
101 #else
102 #define BOOST_CONTRACT_ASSERT_AUDIT(cond) \
103 BOOST_CONTRACT_DETAIL_NOEVAL(cond)
104 #endif
105
106 /**
107 Preferred way to assert contract conditions that are computationally
108 prohibitive, at least compared to the cost of executing the function body.
109
110 The asserted condition will always be compiled and validated syntactically, but
111 it will never be checked at run-time.
112 This macro is defined by code equivalent to:
113
114 @code
115 #define BOOST_CONTRACT_ASSERT_AXIOM(cond) \
116 BOOST_CONTRACT_ASSERT(true || cond)
117 @endcode
118
119 @RefMacro{BOOST_CONTRACT_ASSERT}, @RefMacro{BOOST_CONTRACT_ASSERT_AUDIT}, and
120 @RefMacro{BOOST_CONTRACT_ASSERT_AXIOM} are the three assertion levels predefined
121 by this library.
122 If there is a need, programmers are free to implement their own assertion levels
123 defining macros similar to the one above.
124
125 @see @RefSect{extras.assertion_levels, Assertion Levels}
126
127 @param cond Boolean contract condition to check.
128 (This is not a variadic macro parameter so any comma it might
129 contain must be protected by round parenthesis,
130 @c BOOST_CONTRACT_ASSERT_AXIOM((cond)) will always work.)
131 */
132 #define BOOST_CONTRACT_ASSERT_AXIOM(cond) \
133 BOOST_CONTRACT_DETAIL_NOEVAL(cond)
134
135 #endif // #include guard
136