1 <?xml version="1.0" standalone="yes"?>
2 <library-reference id="reference"><title>Reference</title><header name="boost/contract.hpp">
3 <para>Include all header files required by this library at once (for convenience). </para><para>All header files <computeroutput>boost/contract/*.hpp</computeroutput> 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 <computeroutput>boost/contract.hpp</computeroutput> can be included directly in most cases). Instead the headers <computeroutput>boost/contract/core/*.hpp</computeroutput> are not independent from other library headers and they are automatically included by the <computeroutput>boost/contract/*.hpp</computeroutput> headers (so the <computeroutput>boost/contract/core/*.hpp</computeroutput> headers are usually not directly included by programmers).</para><para>All files under the <computeroutput>boost/contract/detail/</computeroutput> directory, names within the <computeroutput>boost::contract::detail</computeroutput> namespace, names prefixed by <computeroutput>boost_contract_detail</computeroutput>... and <computeroutput>BOOST_CONTRACT_DETAIL</computeroutput>... (in any namesapce, including user's code) are reserved for internal use of this library and should never be used directly by programmers.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.getting_started"> Getting Started</link> </para>
6 <header name="boost/contract/assert.hpp">
7 <para>Assert contract conditions. </para><macro name="BOOST_CONTRACT_ASSERT" kind="functionlike"><macro-parameter name="cond"><description><para>Boolean contract condition to check. (This is not a variadic macro parameter so any comma it might contain must be protected by round parenthesis and <computeroutput>BOOST_CONTRACT_ASSERT((cond))</computeroutput> will always work.) </para></description></macro-parameter><purpose>Preferred way to assert contract conditions. </purpose><description><para>Any exception thrown from within a contract (preconditions, postconditions, exception guarantees, old value copies at body, class invariants, etc.) is interpreted by this library as a contract failure. Therefore, users can program contract assertions manually throwing an exception when an asserted condition is checked to be <computeroutput>false</computeroutput> (this library will then call the appropriate contract failure handler <computeroutput><functionname alt="boost::contract::precondition_failure">boost::contract::precondition_failure</functionname></computeroutput>, etc.). However, it is preferred to use this macro because it expands to code that throws <computeroutput><classname alt="boost::contract::assertion_failure">boost::contract::assertion_failure</classname></computeroutput> with the correct assertion file name (using <computeroutput>__FILE__</computeroutput>), line number (using <computeroutput>__LINE__</computeroutput>), and asserted condition code so to produce informative error messages (C++11 <computeroutput>__func__</computeroutput> is not used here because in most cases it will simply expand to the internal compiler name of the lambda function used to program the contract conditions adding no specificity to the error message).</para><para> <computeroutput><macroname alt="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</macroname></computeroutput>, <computeroutput><macroname alt="BOOST_CONTRACT_ASSERT_AUDIT">BOOST_CONTRACT_ASSERT_AUDIT</macroname></computeroutput>, and <computeroutput><macroname alt="BOOST_CONTRACT_ASSERT_AXIOM">BOOST_CONTRACT_ASSERT_AXIOM</macroname></computeroutput> are the three assertion levels predefined by this library.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.preconditions"> Preconditions</link>, <link linkend="boost_contract.tutorial.postconditions"> Postconditions</link>, <link linkend="boost_contract.tutorial.exception_guarantees"> Exceptions Guarantees</link>, <link linkend="boost_contract.tutorial.class_invariants"> Class Invariants</link>, <link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_"> No Macros</link></para>
10 </para></description></macro>
11 <macro name="BOOST_CONTRACT_ASSERT_AUDIT" kind="functionlike"><macro-parameter name="cond"><description><para>Boolean contract condition to check. (This is not a variadic macro parameter so any comma it might contain must be protected by round parenthesis and <computeroutput>BOOST_CONTRACT_ASSERT_AUDIT((cond))</computeroutput> will always work.) </para></description></macro-parameter><purpose>Preferred way to assert contract conditions that are computationally expensive, at least compared to the computational cost of executing the function body. </purpose><description><para>The asserted condition will always be compiled and validated syntactically, but it will not be checked at run-time unless <computeroutput><macroname alt="BOOST_CONTRACT_AUDITS">BOOST_CONTRACT_AUDITS</macroname></computeroutput> is defined (undefined by default). This macro is defined by code equivalent to:</para><para><programlisting language="c++">#ifdef BOOST_CONTRACT_AUDITS
12 #define BOOST_CONTRACT_ASSERT_AUDIT(cond) \
13 BOOST_CONTRACT_ASSERT(cond)
15 #define BOOST_CONTRACT_ASSERT_AUDIT(cond) \
16 BOOST_CONTRACT_ASSERT(true || cond)
18 </programlisting></para><para> <computeroutput><macroname alt="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</macroname></computeroutput>, <computeroutput><macroname alt="BOOST_CONTRACT_ASSERT_AUDIT">BOOST_CONTRACT_ASSERT_AUDIT</macroname></computeroutput>, and <computeroutput><macroname alt="BOOST_CONTRACT_ASSERT_AXIOM">BOOST_CONTRACT_ASSERT_AXIOM</macroname></computeroutput> are the three assertion levels predefined by this library. If there is a need, programmers are free to implement their own assertion levels defining macros similar to the one above.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.assertion_levels"> Assertion Levels</link>, <link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_"> No Macros</link></para>
21 </para></description></macro>
22 <macro name="BOOST_CONTRACT_ASSERT_AXIOM" kind="functionlike"><macro-parameter name="cond"><description><para>Boolean contract condition to check. (This is not a variadic macro parameter so any comma it might contain must be protected by round parenthesis and <computeroutput>BOOST_CONTRACT_ASSERT_AXIOM((cond))</computeroutput> will always work.) </para></description></macro-parameter><purpose>Preferred way to document in the code contract conditions that are computationally prohibitive, at least compared to the computational cost of executing the function body. </purpose><description><para>The asserted condition will always be compiled and validated syntactically, but it will never be checked at run-time. This macro is defined by code equivalent to:</para><para><programlisting language="c++">#define BOOST_CONTRACT_ASSERT_AXIOM(cond) \
23 BOOST_CONTRACT_ASSERT(true || cond)
24 </programlisting></para><para> <computeroutput><macroname alt="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</macroname></computeroutput>, <computeroutput><macroname alt="BOOST_CONTRACT_ASSERT_AUDIT">BOOST_CONTRACT_ASSERT_AUDIT</macroname></computeroutput>, and <computeroutput><macroname alt="BOOST_CONTRACT_ASSERT_AXIOM">BOOST_CONTRACT_ASSERT_AXIOM</macroname></computeroutput> are the three assertion levels predefined by this library. If there is a need, programmers are free to implement their own assertion levels defining macros similar to the one above.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.assertion_levels"> Assertion Levels</link>, <link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_"> No Macros</link></para>
27 </para></description></macro>
29 <header name="boost/contract/base_types.hpp">
30 <para>Specify inheritance form base classes (for subcontracting). </para><macro name="BOOST_CONTRACT_BASE_TYPES" kind="functionlike"><macro-parameter name="..."><description><para>Comma separated list of base classes. Each base must explicitly specify its access specifier <computeroutput>public</computeroutput>, <computeroutput>protected</computeroutput>, or <computeroutput>private</computeroutput>, and also <computeroutput>virtual</computeroutput> when present (this not always required in C++ instead). There is a limit of about 20 maximum bases that can be listed (because of similar limits in Boost.MPL internally used by this library). This is a variadic macro parameter, on compilers that do not support variadic macros, the <computeroutput>typedef</computeroutput> for base classes can be programmed manually without using this macro (see <link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_"> No Macros</link>). </para></description></macro-parameter><purpose>Used to program the <computeroutput>typedef</computeroutput> that lists the bases of a derived class. </purpose><description><para>In order to support subcontracting, a derived class that specifies contracts for one or more overriding public functions must declare a <computeroutput>typedef</computeroutput> named <computeroutput>base_types</computeroutput> (or <computeroutput><macroname alt="BOOST_CONTRACT_BASES_TYPEDEF">BOOST_CONTRACT_BASES_TYPEDEF</macroname></computeroutput>) using this macro:</para><para><programlisting language="c++">class u
31 #define BASES public b, protected virtual w1, private w2
34 friend class boost::contract:access;
36 typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types;
41 </programlisting></para><para>This <computeroutput>typedef</computeroutput> must be <computeroutput>public</computeroutput> unless <computeroutput><classname alt="boost::contract::access">boost::contract::access</classname></computeroutput> is used.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.base_classes__subcontracting_"> Base Classes</link></para>
44 </para></description></macro>
46 <header name="boost/contract/call_if.hpp">
47 <para>Statically disable compilation and execution of functor calls. </para><para><note><para>These facilities allow to emulate C++17 <computeroutput>if constexpr</computeroutput> statements when used together with functor templates (and C++14 generic lambdas). Therefore, they are not useful on C++17 compilers where <computeroutput> if constexpr</computeroutput> can be directly used instead. </para>
49 </para><namespace name="boost">
50 <namespace name="contract">
51 <struct name="call_if_statement"><template>
52 <template-nontype-parameter name="Pred"><type>bool</type><purpose><para>Static boolean predicate that selects which functor template call to compile and execute. </para></purpose></template-nontype-parameter>
53 <template-type-parameter name="Then"><purpose><para>Type of the functor template to call if the static predicate <computeroutput>Pred</computeroutput> is <computeroutput>true</computeroutput>. </para></purpose></template-type-parameter>
54 <template-type-parameter name="ThenResult"><default>internal_type</default><purpose><para>Return type of then-branch functor template call (this is usually automatically deduced by this library so it is never explicitly specified by the user, and that is why it is often marked as <computeroutput>internal_type</computeroutput> in this documentation). </para></purpose></template-type-parameter>
55 </template><purpose>Select compilation and execution of functor template calls using a static boolean predicate (not needed on C++17 compilers, use <computeroutput>if constexpr</computeroutput> instead). </purpose><description><para>This class template has no members because it is never used directly, it is only used via its specializations. Usually this class template is instantiated only via the return value of <computeroutput><functionname alt="boost::contract::call_if">boost::contract::call_if</functionname></computeroutput> and <computeroutput><functionname alt="boost::contract::call_if_c">boost::contract::call_if_c</functionname></computeroutput>.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.assertion_requirements__templates_">
56 Assertion Requirements</link></para>
59 </para></description></struct><struct-specialization name="call_if_statement"><template>
60 <template-type-parameter name="Then"><purpose><para>Type of functor template to call when the static predicate is <computeroutput>true</computeroutput> (never the case for this template specialization). </para></purpose></template-type-parameter>
61 </template><specialization><template-arg>false</template-arg><template-arg>Then</template-arg><template-arg>internal_type</template-arg></specialization><purpose>Template specialization to handle static predicates that are <computeroutput>false</computeroutput> (not needed on C++17 compilers, use <computeroutput>if constexpr</computeroutput> instead). </purpose><description><para>This template specialization handles all else-branch functor template calls (whether they return void or not). Usually this class template is instantiated only via the return value of <computeroutput><functionname alt="boost::contract::call_if">boost::contract::call_if</functionname></computeroutput> and <computeroutput><functionname alt="boost::contract::call_if_c">boost::contract::call_if_c</functionname></computeroutput>.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.assertion_requirements__templates_">
62 Assertion Requirements</link></para>
65 </para></description><method-group name="public member functions">
66 <method name="else_" cv="const"><type>result_of< Else()>::type</type><template>
67 <template-type-parameter name="Else"/>
68 </template><parameter name="f"><paramtype>Else</paramtype><description><para>Else-branch nullary functor template. The functor template call <computeroutput>f()</computeroutput> is actually compiled and executed for this template specialization (because the if-statement static predicate is <computeroutput>false</computeroutput>). The return type of <computeroutput>f()</computeroutput> must be the same as (or implicitly convertible to) the return type of all other functor template calls specified for this call-if object.</para></description></parameter><purpose>Specify the else-branch functor template. </purpose><description><para><note><para>The <computeroutput>result_of<Else()>::type</computeroutput> expression needs be evaluated only when the static predicate is already checked to be <computeroutput>false</computeroutput> (because <computeroutput>Else()</computeroutput> is required to compile only in that case). Thus, this result-of expression is evaluated lazily and only in instantiations of this template specialization.</para>
72 </para></description><returns><para>A copy of the value returned by the call to the else-branch functor template <computeroutput>f()</computeroutput>. </para>
74 <method name="else_if_c" cv="const"><type><classname>call_if_statement</classname>< ElseIfPred, ElseIfThen ></type><template>
75 <template-nontype-parameter name="ElseIfPred"><type>bool</type><purpose><para>Static boolean predicate selecting which functor template call to compile and execute.</para></purpose></template-nontype-parameter>
76 <template-type-parameter name="ElseIfThen"/>
77 </template><parameter name="f"><paramtype>ElseIfThen</paramtype><description><para>Else-if-branch nullary functor template. The functor template call <computeroutput>f()</computeroutput> is actually compiled and executed if and only if <computeroutput>ElseIfPred</computeroutput> is <computeroutput>true</computeroutput> (because the if-statement static predicate is already <computeroutput>false</computeroutput> for this template specialization). The return type of <computeroutput>f()</computeroutput> must be the same as (or implicitly convertible to) the return type of all other functor template calls specified for this call-if object.</para></description></parameter><purpose>Specify an else-if-branch functor template (using a static boolean predicate). </purpose><description><para>
80 </para></description><returns><para>A call-if statement so the else statement and additional else-if statements can be specified if needed. Eventually, this will be the return value of the one functor template call being compiled and executed. </para>
82 <method name="else_if" cv="const"><type><classname>call_if_statement</classname>< ElseIfPred::value, ElseIfThen ></type><template>
83 <template-type-parameter name="ElseIfPred"><purpose><para>Nullary boolean meta-function selecting which functor template call to compile and execute.</para></purpose></template-type-parameter>
84 <template-type-parameter name="ElseIfThen"/>
85 </template><parameter name="f"><paramtype>ElseIfThen</paramtype><description><para>Else-if-branch nullary functor template. The functor template call <computeroutput>f()</computeroutput> is actually compiled and executed if and only if <computeroutput>ElseIfPred::value</computeroutput> is <computeroutput>true</computeroutput> (because the if-statement static predicate is already <computeroutput>false</computeroutput> for this template specialization). The return type of <computeroutput>f()</computeroutput> must be the same as (or implicitly convertible to) the return type of all other functor template calls specified for this call-if object.</para></description></parameter><purpose>Specify an else-if-branch functor template (using a nullary boolen meta-function). </purpose><description><para>
88 </para></description><returns><para>A call-if statement so the else statement and additional else-if statements can be specified if needed. Eventually, this will be the return value of the one functor template call being compiled and executed. </para>
91 <constructor specifiers="explicit"><parameter name="f"><paramtype>Then const &</paramtype><description><para>Then-branch nullary functor template. The functor template call <computeroutput>f()</computeroutput> is never compiled or executed for this template specialization (because the if-statement static predicate is <computeroutput>false</computeroutput>). The return type of <computeroutput>f()</computeroutput> must be the same as (or implicitly convertible to) the return type of all other functor template calls specified for this call-if object. </para></description></parameter><purpose>Construct this object with the then-branch functor template. </purpose><description><para>
92 </para></description></constructor>
93 </struct-specialization><struct-specialization name="call_if_statement"><template>
94 <template-type-parameter name="Then"><purpose><para>Type of functor template to call when the static predicate is <computeroutput>true</computeroutput> (as it is for this template specialization). </para></purpose></template-type-parameter>
95 </template><specialization><template-arg>true</template-arg><template-arg>Then</template-arg><template-arg>internal_type</template-arg></specialization><inherit access="public">boost::contract::call_if_statement< true, Then, result_of< Then()>::type ></inherit><purpose>Template specialization to dispatch between then-branch functor template calls that return void and the ones that return non-void (not needed on C++17 compilers, use <computeroutput>if constexpr</computeroutput> instead). </purpose><description><para>The base class is a call-if statement so the else and else-if statements can be specified if needed. Usually this class template is instantiated only via the return value of <computeroutput><functionname alt="boost::contract::call_if">boost::contract::call_if</functionname></computeroutput> and <computeroutput><functionname alt="boost::contract::call_if_c">boost::contract::call_if_c</functionname></computeroutput>.</para><para><note><para>The <computeroutput>result_of<Then()>::type</computeroutput> expression needs be evaluated only when the static predicate is already checked to be <computeroutput>true</computeroutput> (because <computeroutput>Then()</computeroutput> is required to compile only in that case). Thus, this template specialization introduces an extra level of indirection necessary for proper lazy evaluation of this result-of expression.</para>
97 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.assertion_requirements__templates_">
98 Assertion Requirements</link></para>
101 </para></description><method-group name="public member functions">
103 <constructor specifiers="explicit"><parameter name="f"><paramtype>Then</paramtype><description><para>Then-branch nullary functor template. The functor template call <computeroutput>f()</computeroutput> is compiled and called for this template specialization (because the if-statement static predicate is <computeroutput>true</computeroutput>). The return type of <computeroutput>f()</computeroutput> must be the same as (or implicitly convertible to) the return type of all other functor template calls specified for this call-if object. </para></description></parameter><purpose>Construct this object with the then-branch functor template. </purpose><description><para>
104 </para></description></constructor>
105 </struct-specialization><struct-specialization name="call_if_statement"><template>
106 <template-type-parameter name="Then"><purpose><para>Type of functor template to call when the static predicate is <computeroutput>true</computeroutput> (as it is for this template specialization). </para></purpose></template-type-parameter>
107 <template-type-parameter name="ThenResult"><purpose><para>Non-void return type of the then-branch functor template call. </para></purpose></template-type-parameter>
108 </template><specialization><template-arg>true</template-arg><template-arg>Then</template-arg><template-arg>ThenResult</template-arg></specialization><purpose>Template specialization to handle static predicates that are <computeroutput>true</computeroutput> for then-branch functor template calls that do not return void (not needed on C++17 compilers, use <computeroutput>if constexpr</computeroutput> instead). </purpose><description><para>Usually this class template is instantiated only via the return value of <computeroutput><functionname alt="boost::contract::call_if">boost::contract::call_if</functionname></computeroutput> and <computeroutput><functionname alt="boost::contract::call_if_c">boost::contract::call_if_c</functionname></computeroutput>.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.assertion_requirements__templates_">
109 Assertion Requirements</link></para>
112 </para></description><method-group name="public member functions">
113 <method name="conversion-operator" cv="const"><type>ThenResult</type><purpose>This implicit type conversion returns a copy of the value returned by the call to the then-branch functor template. </purpose></method>
114 <method name="else_" cv="const"><type>ThenResult</type><template>
115 <template-type-parameter name="Else"/>
116 </template><parameter name="f"><paramtype>Else const &</paramtype><description><para>Else-branch nullary functor template. The functor template call <computeroutput>f()</computeroutput> is never compiled or executed for this template specialization (because the if-statement static predicate is <computeroutput>true</computeroutput>). The return type of <computeroutput>f()</computeroutput> must be the same as (or implicitly convertible to) the <computeroutput>ThenResult</computeroutput> type.</para></description></parameter><purpose>Specify the else-branch functor template. </purpose><description><para>
118 </para></description><returns><para>A copy of the value returned by the call to the then-branch functor template (because the else-branch functor template call is not executed). </para>
120 <method name="else_if_c" cv="const"><type><classname>call_if_statement</classname>< true, Then, ThenResult ></type><template>
121 <template-nontype-parameter name="ElseIfPred"><type>bool</type><purpose><para>Static boolean predicate selecting which functor template call to compile and execute.</para></purpose></template-nontype-parameter>
122 <template-type-parameter name="ElseIfThen"/>
123 </template><parameter name="f"><paramtype>ElseIfThen const &</paramtype><description><para>Else-if-branch nullary functor template. The functor template call <computeroutput>f()</computeroutput> is never compiled or executed for this template specialization (because the if-statement static predicate is <computeroutput>true</computeroutput>). The return type of <computeroutput>f()</computeroutput> must be the same as (or implicitly convertible to) the <computeroutput>ThenResult</computeroutput> type.</para></description></parameter><purpose>Specify an else-if-branch functor template (using a static boolean predicate). </purpose><description><para>
126 </para></description><returns><para>A call-if statement so the else statement and additional else-if statements can be specified if needed. Eventually, it will be the return value of the then-branch functor template call for this template specialization (because the if-statement static predicate is <computeroutput>true</computeroutput>). </para>
128 <method name="else_if" cv="const"><type><classname>call_if_statement</classname>< true, Then, ThenResult ></type><template>
129 <template-type-parameter name="ElseIfPred"><purpose><para>Nullary boolean meta-function selecting which functor template call to compile and execute.</para></purpose></template-type-parameter>
130 <template-type-parameter name="ElseIfThen"/>
131 </template><parameter name="f"><paramtype>ElseIfThen const &</paramtype><description><para>Else-if-branch nullary functor template. The functor template call <computeroutput>f()</computeroutput> is never compiled or executed for this template specialization (because the if-statement static predicate is <computeroutput>true</computeroutput>). The return type of <computeroutput>f()</computeroutput> must be the same as (or implicitly convertible to) the <computeroutput>ThenResult</computeroutput> type.</para></description></parameter><purpose>Specify an else-if-branch functor template (using a nullary boolean meta-function). </purpose><description><para>
134 </para></description><returns><para>A call-if statement so the else statement and additional else-if statements can be specified if needed. Eventually, it will be the return value of the then-branch functor template call for this template specialization (because the if-statement static predicate is <computeroutput>true</computeroutput>). </para>
137 <constructor specifiers="explicit"><parameter name="f"><paramtype>Then</paramtype><description><para>Then-branch nullary functor template. The functor template call <computeroutput>f()</computeroutput> is actually compiled and executed for this template specialization (because the if-statement static predicate is <computeroutput>true</computeroutput>). The return type of <computeroutput>f()</computeroutput> must be the same as (or implicitly convertible to) the <computeroutput>ThenResult</computeroutput> type. </para></description></parameter><purpose>Construct this object with the then-branch functor template. </purpose><description><para>
138 </para></description></constructor>
139 </struct-specialization><struct-specialization name="call_if_statement"><template>
140 <template-type-parameter name="Then"><purpose><para>Type of functor template to call when the static predicate if <computeroutput>true</computeroutput> (as it is for this template specialization). </para></purpose></template-type-parameter>
141 </template><specialization><template-arg>true</template-arg><template-arg>Then</template-arg><template-arg>void</template-arg></specialization><purpose>Template specialization to handle static predicates that are <computeroutput>true</computeroutput> for then-branch functor template calls that return void (not needed on C++17 compilers, use <computeroutput>if constexpr</computeroutput> instead). </purpose><description><para>Usually this class template is instantiated only via the return value of <computeroutput><functionname alt="boost::contract::call_if">boost::contract::call_if</functionname></computeroutput> and <computeroutput><functionname alt="boost::contract::call_if_c">boost::contract::call_if_c</functionname></computeroutput>.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.assertion_requirements__templates_">
142 Assertion Requirements</link></para>
145 </para></description><method-group name="public member functions">
146 <method name="else_" cv="const"><type>void</type><template>
147 <template-type-parameter name="Else"/>
148 </template><parameter name="f"><paramtype>Else const &</paramtype><description><para>Else-branch nullary functor template. The functor template call <computeroutput>f()</computeroutput> is never compiled or executed for this template specialization (because the if-statement static predicate is <computeroutput>true</computeroutput>). The return type of <computeroutput>f()</computeroutput> must be <computeroutput>void</computeroutput> for this template specialization (because the then-branch functor template calls return void). </para></description></parameter><purpose>Specify the else-branch functor template. </purpose><description><para>
149 </para></description></method>
150 <method name="else_if_c" cv="const"><type><classname>call_if_statement</classname>< true, Then, void ></type><template>
151 <template-nontype-parameter name="ElseIfPred"><type>bool</type><purpose><para>Static boolean predicate selecting which functor template call to compile and execute.</para></purpose></template-nontype-parameter>
152 <template-type-parameter name="ElseIfThen"/>
153 </template><parameter name="f"><paramtype>ElseIfThen const &</paramtype><description><para>Else-if-branch nullary functor template. The functor template call <computeroutput>f()</computeroutput> is never compiled or executed for this template specialization (because the if-statement static predicate is <computeroutput>true</computeroutput>). The return type of <computeroutput>f()</computeroutput> must be <computeroutput>void</computeroutput> for this template specialization (because the then-branch functor template calls return void).</para></description></parameter><purpose>Specify an else-if-branch functor template (using a static boolean predicate). </purpose><description><para>
156 </para></description><returns><para>A call-if statement so the else statement and additional else-if statements can be specified if needed. Eventually, it will return void for this template specialization (because the then-branch functor template calls return void). </para>
158 <method name="else_if" cv="const"><type><classname>call_if_statement</classname>< true, Then, void ></type><template>
159 <template-type-parameter name="ElseIfPred"><purpose><para>Nullary boolean meta-function selecting which functor template call to compile and execute.</para></purpose></template-type-parameter>
160 <template-type-parameter name="ElseIfThen"/>
161 </template><parameter name="f"><paramtype>ElseIfThen const &</paramtype><description><para>Else-if-branch nullary functor template. The functor template call <computeroutput>f()</computeroutput> is never compiled or executed for this template specialization (because the if-statement static predicate is <computeroutput>true</computeroutput>). The return type of <computeroutput>f()</computeroutput> must be <computeroutput>void</computeroutput> for this template specialization (because the then-branch functor template calls return void).</para></description></parameter><purpose>Specify an else-if-branch functor template (using a nullary boolean meta-function). </purpose><description><para>
164 </para></description><returns><para>A call-if statement so the else statement and additional else-if statements can be specified if needed. Eventually, it will return void for this template specialization (because the then-branch functor template calls return void). </para>
167 <constructor specifiers="explicit"><parameter name="f"><paramtype>Then</paramtype><description><para>Then-branch nullary functor template. The functor template call <computeroutput>f()</computeroutput> is actually compiled and executed for this template specialization (because the if-statement static predicate is <computeroutput>true</computeroutput>). The return type of <computeroutput>f()</computeroutput> must be <computeroutput>void</computeroutput> for this template specialization (because the then-branch functor template calls return void). </para></description></parameter><purpose>Construct this object with the then-branch functor template. </purpose><description><para>
168 </para></description></constructor>
169 </struct-specialization><function name="call_if_c"><type><classname>call_if_statement</classname>< Pred, Then ></type><template>
170 <template-nontype-parameter name="Pred"><type>bool</type><purpose><para>Static boolean predicate selecting which functor template call to compile and execute.</para></purpose></template-nontype-parameter>
171 <template-type-parameter name="Then"/>
172 </template><parameter name="f"><paramtype>Then</paramtype><description><para>Then-branch nullary functor template. The functor template call <computeroutput>f()</computeroutput> is compiled and executed if and only if <computeroutput>Pred</computeroutput> is <computeroutput>true</computeroutput>. The return type of other functor template calls specified for this call-if statement (else-branch, else-if-branches, etc.) must be the same as (or implicitly convertible to) the return type of then-branch functor call <computeroutput>f()</computeroutput>.</para></description></parameter><purpose>Select compilation and execution of functor template calls using a static boolean predicate (not needed on C++17 compilers, use <computeroutput>if constexpr</computeroutput> instead). </purpose><description><para>Create a call-if object with the specified then-branch functor template:</para><para><programlisting language="c++">boost::contract::call_if_c<Pred1>(
173 then_functor_template1
174 ).template else_if_c<Pred2>( // Optional.
175 then_functor_template2
176 ) // Optionally, other `else_if_c` or
178 .else_( // Optional for `void` functors,
179 else_functor_template // but required for non `void`.
181 </programlisting></para><para>Optional functor templates for else-if-branches and the else-branch can be specified as needed (the else-branch function template is required if <computeroutput>f</computeroutput> returns non-void).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.assertion_requirements__templates_">
182 Assertion Requirements</link></para>
187 </para></description><returns><para>A call-if statement so else and else-if statements can be specified if needed. Eventually, this will be the return value of the one functor template call being compiled and executed (which could also be <computeroutput>void</computeroutput>). </para>
188 </returns></function>
189 <function name="call_if"><type><classname>call_if_statement</classname>< Pred::value, Then ></type><template>
190 <template-type-parameter name="Pred"><purpose><para>Nullary boolean meta-function selecting which functor template call to compile and execute.</para></purpose></template-type-parameter>
191 <template-type-parameter name="Then"/>
192 </template><parameter name="f"><paramtype>Then</paramtype><description><para>Then-branch nullary functor template. The functor template call <computeroutput>f()</computeroutput> is compiled and executed if and only if <computeroutput>Pred::value</computeroutput> is <computeroutput>true</computeroutput>. The return type of other functor template calls specified for this call-if statement (else-branch, else-if-branches, etc.) must be the same as (or implicitly convertible to) the return type of then-branch functor template call <computeroutput>f()</computeroutput>.</para></description></parameter><purpose>Select compilation and execution of functor template calls using a nullary boolean meta-function (not needed on C++17 compilers, use <computeroutput>if constexpr</computeroutput> instead). </purpose><description><para>This is equivalent to <computeroutput>boost::contract::call_if_c<Pred::value>(f)</computeroutput>. Create a call-if object with the specified then-branch functor template:</para><para><programlisting language="c++">boost::contract::call_if<Pred1>(
193 then_functor_template1
194 ).template else_if<Pred2>( // Optional.
195 then_functor_template2
196 ) // Optionally, other `else_if` or
198 .else_( // Optional for `void` functors,
199 else_functor_template // but required for non `void`.
201 </programlisting></para><para>Optional functor templates for else-if-branches and the else-branch can be specified as needed (the else-branch functor template is required if <computeroutput>f</computeroutput> returns non-void).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.assertion_requirements__templates_">
202 Assertion Requirements</link></para>
207 </para></description><returns><para>A call-if statement so else and else-if statements can be specified if needed. Eventually, this will be the return value of the one functor template call being compiled and executed (which could also be <computeroutput>void</computeroutput>). </para>
208 </returns></function>
209 <function name="condition_if_c"><type>bool</type><template>
210 <template-nontype-parameter name="Pred"><type>bool</type><purpose><para>Static boolean predicate selecting when the functor template call <computeroutput>f()</computeroutput> should be compiled and executed. </para></purpose></template-nontype-parameter>
211 <template-type-parameter name="Then"/>
212 </template><parameter name="f"><paramtype>Then</paramtype><description><para>Nullary boolean functor template. The functor template call <computeroutput>f()</computeroutput> is compiled and executed if and only if <computeroutput>Pred</computeroutput> is <computeroutput>true</computeroutput>.</para></description></parameter><parameter name="else_"><paramtype>bool</paramtype><default>true</default><description><para>Boolean value to return when <computeroutput>Pred</computeroutput> is <computeroutput>false</computeroutput> (instead of compiling and executing the functor template call <computeroutput>f()</computeroutput>).</para></description></parameter><purpose>Select compilation and execution of a boolean functor template condition using a static boolean predicate (not needed on C++17 compilers, use <computeroutput>if constexpr</computeroutput> instead). </purpose><description><para>Compile and execute the nullary boolean functor template call <computeroutput>f()</computeroutput> if and only if the specified static boolean predicate <computeroutput>Pred</computeroutput> is <computeroutput>true</computeroutput>, otherwise trivially return <computeroutput>else_</computeroutput> (<computeroutput>true</computeroutput> by default) at run-time.</para><para>A call to <computeroutput>boost::contract::condition_if_c<Pred>(f, else_)</computeroutput> is logically equivalent to <computeroutput>boost::contract::call_if_c<Pred>(f, [] { return else_; })</computeroutput> (but its internal implementation is optimized and it does not actually use <computeroutput>call_if_c</computeroutput>).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.assertion_requirements__templates_">
213 Assertion Requirements</link></para>
219 </para></description><returns><para>Boolean value returned by <computeroutput>f()</computeroutput> if the static predicate <computeroutput>Pred</computeroutput> is <computeroutput>true</computeroutput>. Otherwise, trivially return <computeroutput>else_</computeroutput>. </para>
220 </returns></function>
221 <function name="condition_if"><type>bool</type><template>
222 <template-type-parameter name="Pred"><purpose><para>Nullary boolean meta-function selecting when the functor template call <computeroutput>f()</computeroutput> should be compiled and executed.</para></purpose></template-type-parameter>
223 <template-type-parameter name="Then"/>
224 </template><parameter name="f"><paramtype>Then</paramtype><description><para>Nullary boolean functor template. The functor template call <computeroutput>f()</computeroutput> is compiled and executed if and only if <computeroutput>Pred::value</computeroutput> is <computeroutput>true</computeroutput>. </para></description></parameter><parameter name="else_"><paramtype>bool</paramtype><default>true</default><description><para>Boolean value to return when <computeroutput>Pred::value</computeroutput> is <computeroutput>false</computeroutput> (instead of compiling and executing the functor template call <computeroutput>f()</computeroutput>).</para></description></parameter><purpose>Select compilation and execution of a boolean functor template condition using a nullary boolean meta-function (not needed on C++17 compilers, use <computeroutput>if constexpr</computeroutput> instead). </purpose><description><para>This is equivalent to <computeroutput>boost::contract::condition_if_c<Pred::value>(f, else_)</computeroutput>. Compile and execute the nullary boolean functor template call <computeroutput>f()</computeroutput> if and only if the specified nullary boolean meta-function <computeroutput>Pred::value</computeroutput> is <computeroutput>true</computeroutput>, otherwise trivially return <computeroutput>else_</computeroutput> (<computeroutput>true</computeroutput> by default) at run-time.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.assertion_requirements__templates_">
225 Assertion Requirements</link></para>
230 </para></description><returns><para>Boolean value returned by <computeroutput>f()</computeroutput> if the static predicate <computeroutput>Pred::value</computeroutput> is <computeroutput>true</computeroutput>. Otherwise, trivially return <computeroutput>else_</computeroutput>. </para>
231 </returns></function>
271 <header name="boost/contract/check.hpp">
272 <para>RAII object that checks contracts. </para><namespace name="boost">
273 <namespace name="contract">
274 <class name="check"><purpose>RAII object that checks the contracts. </purpose><description><para>In general, when this object is constructed it checks class invariants at entry, preconditions, and makes old value copies at body. When it is destructed, it checks class invariants at exist, postconditions, and exception guarantees. This object enforces the following (see <link linkend="boost_contract.contract_programming_overview"> Contract Programming Overview</link>):</para><para><itemizedlist>
275 <listitem><para>Postconditions are checked only if the body does not throw an exception. </para>
277 <listitem><para>Exceptions guarantees are checked only if the body throws an exception. </para>
279 <listitem><para>Constructor entry never checks class invariants. </para>
281 <listitem><para>Destructor exit checks class invariants only if the body throws an exception (even if destructors should usually not be programmed to throw exceptions in C++ and they are implicitly declared <computeroutput>noexcept</computeroutput> since C++11). </para>
283 <listitem><para>Static invariants are always checked at entry and exit (and regardless of the body throwing exceptions or not).</para>
286 When used this way, this object is constructed and initialized to the return value of one of the contract functions <computeroutput><functionname alt="boost::contract::function">boost::contract::function</functionname></computeroutput>, <computeroutput><functionname alt="boost::contract::constructor">boost::contract::constructor</functionname></computeroutput>, <computeroutput><functionname alt="boost::contract::destructor">boost::contract::destructor</functionname></computeroutput>, or <computeroutput><functionname alt="boost::contract::public_function">boost::contract::public_function</functionname></computeroutput>. In addition to that, this object can be constructed from a nullary functor when it is used to program implementation checks.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial"> Tutorial</link>, <link linkend="boost_contract.advanced.implementation_checks"> Implementation Checks</link> </para>
288 </para></description><method-group name="public member functions">
290 <constructor><template>
291 <template-type-parameter name="F"/>
292 </template><parameter name="f"><paramtype>F const &</paramtype><description><para>Nullary functor that asserts implementation checks. <computeroutput>f()</computeroutput> will be called as soon as this object is constructed at the point it is declared within the implementation code (see <link linkend="boost_contract.advanced.implementation_checks">
293 Implementation Checks</link>). </para></description></parameter><purpose>Construct this object for implementation checks. </purpose><description><para>This can be used to program checks within implementation code (body, etc.). This constructor is not declared <computeroutput>explicit</computeroutput> so initializations can use assignment syntax <computeroutput>=</computeroutput>.</para><para><emphasis role="bold">Throws:</emphasis> This can throw in case programmers specify contract failure handlers that throw exceptions instead of terminating the program (see <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__">
294 Throw on Failure</link>).</para><para>
295 </para></description></constructor>
296 <constructor><parameter name="other"><paramtype><classname>check</classname> const &</paramtype><description><para>Copied-from object. </para></description></parameter><purpose>Construct this object copying it from the specified one. </purpose><description><para>This object will check the contract, the copied-from object will not (i.e., contract check ownership is transferred from the copied object to the new object being created by this constructor).</para><para>
297 </para></description></constructor>
298 <constructor><template>
299 <template-type-parameter name="VirtualResult"><purpose><para>Return type of the enclosing function declaring the contract if that is either a virtual or an overriding public function, otherwise this is always <computeroutput>void</computeroutput>. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.) </para></purpose></template-type-parameter>
300 </template><parameter name="contract"><paramtype><classname>specify_precondition_old_postcondition_except</classname>< VirtualResult > const &</paramtype><description><para>Contract to be checked (usually the return value of <computeroutput><functionname alt="boost::contract::function">boost::contract::function</functionname></computeroutput> or <computeroutput><functionname alt="boost::contract::public_function">boost::contract::public_function</functionname></computeroutput>).</para></description></parameter><purpose>Construct this object to check the specified contract. </purpose><description><para>This checks class invariants at entry (if those were specified for the given contract). This constructor is not declared <computeroutput>explicit</computeroutput> so initializations can use assignment syntax <computeroutput>=</computeroutput>.</para><para><emphasis role="bold">Throws:</emphasis> This can throw in case programmers specify contract failure handlers that throw exceptions instead of terminating the program (see <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__">
301 Throw on Failure</link>).</para><para>
303 </para></description></constructor>
304 <constructor><template>
305 <template-type-parameter name="VirtualResult"><purpose><para>Return type of the enclosing function declaring the contract if that is either a virtual or an overriding public function, otherwise this is always <computeroutput>void</computeroutput>. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.) </para></purpose></template-type-parameter>
306 </template><parameter name="contract"><paramtype><classname>specify_old_postcondition_except</classname>< VirtualResult > const &</paramtype><description><para>Contract to be checked (usually the return value of <computeroutput><functionname alt="boost::contract::function">boost::contract::function</functionname></computeroutput>, <computeroutput><functionname alt="boost::contract::constructor">boost::contract::constructor</functionname></computeroutput>, <computeroutput><functionname alt="boost::contract::destructor">boost::contract::destructor</functionname></computeroutput>, or <computeroutput><functionname alt="boost::contract::public_function">boost::contract::public_function</functionname></computeroutput>).</para></description></parameter><purpose>Construct this object to check the specified contract. </purpose><description><para>This checks class invariants at entry and preconditions (if any of those were specified for the given contract). This constructor is not declared <computeroutput>explicit</computeroutput> so initializations can use assignment syntax <computeroutput>=</computeroutput>.</para><para><emphasis role="bold">Throws:</emphasis> This can throw in case programmers specify contract failure handlers that throw exceptions instead of terminating the program (see <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__">
307 Throw on Failure</link>).</para><para>
309 </para></description></constructor>
310 <constructor><template>
311 <template-type-parameter name="VirtualResult"><purpose><para>Return type of the enclosing function declaring the contract if that is either a virtual or an overriding public function, otherwise this is always <computeroutput>void</computeroutput>. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.) </para></purpose></template-type-parameter>
312 </template><parameter name="contract"><paramtype><classname>specify_postcondition_except</classname>< VirtualResult > const &</paramtype><description><para>Contract to be checked (usually the return value of <computeroutput><functionname alt="boost::contract::function">boost::contract::function</functionname></computeroutput>, <computeroutput><functionname alt="boost::contract::constructor">boost::contract::constructor</functionname></computeroutput>, <computeroutput><functionname alt="boost::contract::destructor">boost::contract::destructor</functionname></computeroutput>, or <computeroutput><functionname alt="boost::contract::public_function">boost::contract::public_function</functionname></computeroutput>).</para></description></parameter><purpose>Construct this object to check the specified contract. </purpose><description><para>This checks class invariants at entry and preconditions then it makes old value copies at body (if any of those were specified for the given contract). This constructor is not declared <computeroutput>explicit</computeroutput> so initializations can use assignment syntax <computeroutput>=</computeroutput>.</para><para><emphasis role="bold">Throws:</emphasis> This can throw in case programmers specify contract failure handlers that throw exceptions instead of terminating te program (see <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__">
313 Throw on Failure</link>).</para><para>
315 </para></description></constructor>
316 <constructor><parameter name="contract"><paramtype><classname>specify_except</classname> const &</paramtype><description><para>Contract to be checked (usually the return value of <computeroutput><functionname alt="boost::contract::function">boost::contract::function</functionname></computeroutput>, <computeroutput><functionname alt="boost::contract::constructor">boost::contract::constructor</functionname></computeroutput>, <computeroutput><functionname alt="boost::contract::destructor">boost::contract::destructor</functionname></computeroutput>, or <computeroutput><functionname alt="boost::contract::public_function">boost::contract::public_function</functionname></computeroutput>).</para></description></parameter><purpose>Construct this object to check the specified contract. </purpose><description><para>This checks class invariants at entry and preconditions then it makes old value copies at body, plus the destructor of this object will also check postconditions in this case (if any of those were specified for the given contract). This constructor is not declared <computeroutput>explicit</computeroutput> so initializations can use assignment syntax <computeroutput>=</computeroutput>.</para><para><emphasis role="bold">Throws:</emphasis> This can throw in case programmers specify contract failure handlers that throw exceptions instead of terminating the program (see <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__">
317 Throw on Failure</link>).</para><para>
319 </para></description></constructor>
320 <constructor><parameter name="contract"><paramtype><classname>specify_nothing</classname> const &</paramtype><description><para>Contract to be checked (usually the return value of <computeroutput><functionname alt="boost::contract::function">boost::contract::function</functionname></computeroutput>, <computeroutput><functionname alt="boost::contract::constructor">boost::contract::constructor</functionname></computeroutput>, <computeroutput><functionname alt="boost::contract::destructor">boost::contract::destructor</functionname></computeroutput>, or <computeroutput><functionname alt="boost::contract::public_function">boost::contract::public_function</functionname></computeroutput>).</para></description></parameter><purpose>Construct this object to check the specified contract. </purpose><description><para>This checks class invariants at entry and preconditions then it makes old value copies at body, plus the destructor of this object will also check postconditions and exception guarantees in this case (if any of those were specified for the given contract). This constructor is not declared <computeroutput>explicit</computeroutput> so initializations can use assignment syntax <computeroutput>=</computeroutput>.</para><para><emphasis role="bold">Throws:</emphasis> This can throw in case programmers specify contract failure handlers that throw exceptions instead of terminating the program (see <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__">
321 Throw on Failure</link>).</para><para>
323 </para></description></constructor>
324 <destructor><purpose>Destruct this object. </purpose><description><para>This checks class invariants at exit and either postconditions when the enclosing function body did not throw an exception, or exception guarantees when the function body threw an exception (if class invariants, postconditions, and exception guarantees respectively were specified for the enclosing class and the contract parameter given when constructing this object).</para><para><emphasis role="bold">Throws:</emphasis> This can throw in case programmers specify contract failure handlers that throw exceptions instead of terminating the program (see <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__">
325 Throw on Failure</link>). (This is declared <computeroutput>noexcept(false)</computeroutput> since C++11.) </para></description></destructor>
369 <header name="boost/contract/constructor.hpp">
370 <para>Program contracts for constructors. </para><namespace name="boost">
371 <namespace name="contract">
376 <function name="constructor"><type><classname>specify_old_postcondition_except</classname></type><template>
377 <template-type-parameter name="Class"><purpose><para>The type of the class containing the constructor declaring the contract. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.)</para></purpose></template-type-parameter>
378 </template><parameter name="obj"><paramtype>Class *</paramtype><description><para>The object <computeroutput>this</computeroutput> from the scope of the enclosing constructor declaring the contract. (Constructors check all class invariants, including static and volatile invariants, see <link linkend="boost_contract.tutorial.class_invariants">
379 Class Invariants</link> and <link linkend="boost_contract.extras.volatile_public_functions">
380 Volatile Public Functions</link>).</para></description></parameter><purpose>Program contracts for constructors. </purpose><description><para>This is used to specify postconditions, exception guarantees, old value copies at body, and check class invariants for constructors (see <computeroutput><classname alt="boost::contract::constructor_precondition">boost::contract::constructor_precondition</classname></computeroutput> to specify preconditions for constructors):</para><para><programlisting language="c++">class u {
381 friend class boost::contract:access;
383 void invariant() const { // Optional (as for static and volatile).
384 BOOST_CONTRACT_ASSERT(...);
390 boost::contract::old_ptr<old_type> old_var;
391 boost::contract::check c = boost::contract::constructor(this)
392 // No `.precondition` (use `constructor_precondition` instead).
393 .old([&] { // Optional.
394 old_var = BOOST_CONTRACT_OLDOF(old_expr);
397 .postcondition([&] { // Optional.
398 BOOST_CONTRACT_ASSERT(...);
401 .except([&] { // Optional.
402 BOOST_CONTRACT_ASSERT(...);
407 ... // Constructor body.
412 </programlisting></para><para>For optimization, this can be omitted for constructors that do not have postconditions and exception guarantees, within classes that have no invariants.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.constructors"> Constructors</link></para>
417 </para></description><returns><para>The result of this function must be assigned to a variable of type <computeroutput><classname alt="boost::contract::check">boost::contract::check</classname></computeroutput> declared explicitly (i.e., without using C++11 <computeroutput>auto</computeroutput> declarations) and locally just before the code of the constructor body (otherwise this library will generate a run-time error, see <computeroutput><macroname alt="BOOST_CONTRACT_ON_MISSING_CHECK_DECL">BOOST_CONTRACT_ON_MISSING_CHECK_DECL</macroname></computeroutput>). </para>
418 </returns></function>
457 <header name="boost/contract/core/access.hpp">
458 <para>Allow to declare invariants, base types, etc all as private members. </para><namespace name="boost">
459 <namespace name="contract">
460 <class name="access"><purpose>Declare this class as friend to program invariants and base types as private members. </purpose><description><para>Declare this class a friend of the user-defined class specifying the contracts and then invariant functions and the base types <computeroutput>typedef</computeroutput> can be declared as non-public members:</para><para><programlisting language="c++">class u
461 #define BASES public b, private w
464 friend class boost::contract::access;
466 typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; // Private.
469 void invariant() const { ... } // Private (same for static and volatile).
474 </programlisting></para><para>In real code, programmers will likely chose to declare this class as friend so to fully control public interfaces of their user-defined classes (this is not extensively done in the examples of this documentation only for brevity). This class is not intended to be directly used by programmers a part from being declared as <computeroutput>friend</computeroutput> (and that is why this class does not have any public member and it is not copyable).</para><para><warning><para>Not declaring this class friend of user-defined classes will cause compiler errors on some compilers (e.g., MSVC) because the private members needed to check the contracts will not be accessible. On other compilers (e.g., GCC and CLang), the private access will instead fail SFINAE and no compiler error will be reported while invariants and subcontracting will be silently skipped at run-time. Therefore, programmers must make sure to either declare this class as friend or to always declare invariant functions and base types <computeroutput>typedef</computeroutput> as public members.</para>
476 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.access_specifiers"> Access Specifiers</link> </para>
478 </para></description></class>
521 <header name="boost/contract/core/check_macro.hpp">
522 <para>Macros for implementation checks. </para><macro name="BOOST_CONTRACT_CHECK" kind="functionlike"><macro-parameter name="cond"><description><para>Boolean condition to check within implementation code (function body, etc.). (This is not a variadic macro parameter so any comma it might contain must be protected by round parenthesis and <computeroutput>BOOST_CONTRACT_CHECK((cond))</computeroutput> will always work.) </para></description></macro-parameter><purpose>Preferred way to assert implementation check conditions. </purpose><description><para>It is preferred to use this macro instead of programming implementation checks in a nullary functor passed to <computeroutput><classname alt="boost::contract::check">boost::contract::check</classname></computeroutput> constructor because this macro will completely remove implementation checks from the code when <computeroutput><macroname alt="BOOST_CONTRACT_NO_CHECKS">BOOST_CONTRACT_NO_CHECKS</macroname></computeroutput> is defined:</para><para><programlisting language="c++">void f() {
524 BOOST_CONTRACT_CHECK(cond);
527 </programlisting></para><para> <computeroutput><macroname alt="BOOST_CONTRACT_CHECK">BOOST_CONTRACT_CHECK</macroname></computeroutput>, <computeroutput><macroname alt="BOOST_CONTRACT_CHECK_AUDIT">BOOST_CONTRACT_CHECK_AUDIT</macroname></computeroutput>, and <computeroutput><macroname alt="BOOST_CONTRACT_CHECK_AXIOM">BOOST_CONTRACT_CHECK_AXIOM</macroname></computeroutput> are the three assertion levels predefined by this library for implementation checks.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.implementation_checks"> Implementation Checks</link></para>
530 </para></description></macro>
531 <macro name="BOOST_CONTRACT_CHECK_AUDIT" kind="functionlike"><macro-parameter name="cond"><description><para>Boolean condition to check within implementation code (function body, etc.). (This is not a variadic macro parameter so any comma it might contain must be protected by round parenthesis and <computeroutput>BOOST_CONTRACT_CHECK_AUDIT((cond))</computeroutput> will always work.) </para></description></macro-parameter><purpose>Preferred way to assert implementation check conditions that are computationally expensive, at least compared to the computational cost of executing the function body. </purpose><description><para>The specified condition will always be compiled and validated syntactically, but it will not be checked at run-time unless <computeroutput><macroname alt="BOOST_CONTRACT_AUDITS">BOOST_CONTRACT_AUDITS</macroname></computeroutput> is defined (undefined by default). This macro is defined by code equivalent to:</para><para><programlisting language="c++">#ifdef BOOST_CONTRACT_AUDITS
532 #define BOOST_CONTRACT_CHECK_AUDIT(cond) \
533 BOOST_CONTRACT_CHECK(cond)
535 #define BOOST_CONTRACT_CHECK_AUDIT(cond) \
536 BOOST_CONTRACT_CHECK(true || cond)
538 </programlisting></para><para> <computeroutput><macroname alt="BOOST_CONTRACT_CHECK">BOOST_CONTRACT_CHECK</macroname></computeroutput>, <computeroutput><macroname alt="BOOST_CONTRACT_CHECK_AUDIT">BOOST_CONTRACT_CHECK_AUDIT</macroname></computeroutput>, and <computeroutput><macroname alt="BOOST_CONTRACT_CHECK_AXIOM">BOOST_CONTRACT_CHECK_AXIOM</macroname></computeroutput> are the three assertion levels predefined by this library for implementation checks. If there is a need, programmers are free to implement their own assertion levels defining macros similar to the one above.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.assertion_levels"> Assertion Levels</link></para>
541 </para></description></macro>
542 <macro name="BOOST_CONTRACT_CHECK_AXIOM" kind="functionlike"><macro-parameter name="cond"><description><para>Boolean condition to check within implementation code (function body, etc.). (This is not a variadic macro parameter so any comma it might contain must be protected by round parenthesis and <computeroutput>BOOST_CONTRACT_CHECK_AXIOM((cond))</computeroutput> will always work.) </para></description></macro-parameter><purpose>Preferred way to document in the code implementation check conditions that are computationally prohibitive, at least compared to the computational cost of executing the function body. </purpose><description><para>The specified condition will always be compiled and validated syntactically, but it will never be checked at run-time. This macro is defined by code equivalent to:</para><para><programlisting language="c++">#define BOOST_CONTRACT_CHECK_AXIOM(cond) \
543 BOOST_CONTRACT_CHECK(true || cond)
544 </programlisting></para><para> <computeroutput><macroname alt="BOOST_CONTRACT_CHECK">BOOST_CONTRACT_CHECK</macroname></computeroutput>, <computeroutput><macroname alt="BOOST_CONTRACT_CHECK_AUDIT">BOOST_CONTRACT_CHECK_AUDIT</macroname></computeroutput>, and <computeroutput><macroname alt="BOOST_CONTRACT_CHECK_AXIOM">BOOST_CONTRACT_CHECK_AXIOM</macroname></computeroutput> are the three assertion levels predefined by this library for implementation checks. If there is a need, programmers are free to implement their own assertion levels defining macros similar to the one above.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.assertion_levels"> Assertion Levels</link></para>
547 </para></description></macro>
549 <header name="boost/contract/core/config.hpp">
550 <para>Configure this library compile-time and run-time behaviours. </para><macro name="BOOST_CONTRACT_DYN_LINK"><purpose>Define this macro to compile this library as a shared library (recommended). </purpose><description><para>If this macro is defined, this library is compiled so it can be linked as a shared library (a.k.a., Dynamically Linked Library or DLL) to user code. This library will automatically define this macro when Boost libraries are built as shared libraries (e.g., defining <computeroutput>BOOST_ALL_DYN_LINK</computeroutput> or using <computeroutput>bjam link=shared ...</computeroutput>).</para><para><warning><para>In general this library will correctly check contracts at run-time only when compiled as a shared library, unless user code checks contracts in a single program unit (e.g., a single program with only statically linked libraries). Therefore, it is recommended to build and use this library as a shared library by defining this macro (or equivalently by building all Boost libraries as shared libraries).</para>
552 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.getting_started"> Getting Started</link> </para>
554 </para></description></macro>
555 <macro name="BOOST_CONTRACT_STATIC_LINK"><purpose>Define this macro to compile this library as a static library (not recommended). </purpose><description><para>If this macro is defined, this library is compiled so it can be linked statically to user code. This library will automatically define this macro when Boost libraries are built as static libraries.</para><para><warning><para>This library is not guaranteed to always work correctly at run-time when this macro is defined (define <computeroutput><macroname alt="BOOST_CONTRACT_DYN_LINK">BOOST_CONTRACT_DYN_LINK</macroname></computeroutput> or <computeroutput>BOOST_ALL_DYN_LINK</computeroutput> instead). However, this macro can be defined and this library can be safely used as a static library for user code that checks contracts in a single program unit (e.g., a single program with only statically linked libraries).</para>
557 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.getting_started"> Getting Started</link> </para>
559 </para></description></macro>
560 <macro name="BOOST_CONTRACT_HEADER_ONLY"><purpose>Automatically defined by this library when it is being used as a header-only library (not recommended). </purpose><description><para>This macro is not a configuration macro and this library will generate a compile-time error if users try to define it directly. This library will automatically define this macro when users do not define <computeroutput><macroname alt="BOOST_CONTRACT_DYN_LINK">BOOST_CONTRACT_DYN_LINK</macroname></computeroutput> (or <computeroutput>BOOST_ALL_DYN_LINK</computeroutput>) and <computeroutput><macroname alt="BOOST_CONTRACT_STATIC_LINK">BOOST_CONTRACT_STATIC_LINK</macroname></computeroutput>. When used as a header-only library, this library code does not have to be compiled separately from user code, this library headers are simply included and compiled as part of the user program.</para><para><warning><para>This library is not guaranteed to always work correctly at run-time when this macro is defined (define <computeroutput><macroname alt="BOOST_CONTRACT_DYN_LINK">BOOST_CONTRACT_DYN_LINK</macroname></computeroutput> or <computeroutput>BOOST_ALL_DYN_LINK</computeroutput> instead). However, this macro can be defined and this library can be safely used as a header-only library for user code that checks contracts in a single program unit (e.g., a single program with only statically linked libraries).</para>
562 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.getting_started"> Getting Started</link> </para>
564 </para></description></macro>
565 <macro name="BOOST_CONTRACT_DISABLE_THREADS"><purpose>Define this macro to not lock internal library data for thread safety (undefined by default). </purpose><description><para>Defining this macro will make the library implementation code not thread safe so this macro should not be defined unless the library is being used by single-threaded applications only. This library will automatically define this macro when Boost libraries are built without threads (e.g., defining <computeroutput>BOOST_DISABLE_THREADS</computeroutput>).</para><para><note><para>When this macro is left undefined this library needs to internally use some sort of global lock (to ensure contract checking is globally disabled when other contracts are being checked and also to safely access failure handler functors). That could introduce an undesired amount of synchronization in some multi-threaded applications.</para>
567 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.contract_programming_overview.assertions"> Assertions</link> </para>
569 </para></description></macro>
570 <macro name="BOOST_CONTRACT_MAX_ARGS"><purpose>Maximum number of arguments for public function overrides on compilers that do not support variadic templates (default to <computeroutput>10</computeroutput>). </purpose><description><para>On compilers that do not support C++11 variadic templates, this macro is defined to the maximum number of arguments that public function overrides can have and pass to <computeroutput><functionname alt="boost::contract::public_function">boost::contract::public_function</functionname></computeroutput> (users can redefine this macro to a different value). On compilers that support variadic templates, this macro has no effect.</para><para><note><para>Regardless of the value of this macro and of compiler support for variadic templates, there might be an intrinsic limit of about 18 arguments for public function overrides (because of similar limits in Boost.MPL and Boost.FunctionTypes internally used by this library).</para>
572 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_"> No Macros</link> </para>
574 </para></description></macro>
575 <macro name="BOOST_CONTRACT_BASES_TYPEDEF"><purpose>Define the name of the base type <computeroutput>typedef</computeroutput> (<computeroutput>base_types</computeroutput> by default). </purpose><description><para>This macro expands to the name of the <computeroutput>typedef</computeroutput> that lists the base classes for subcontracting via <computeroutput><macroname alt="BOOST_CONTRACT_BASE_TYPES">BOOST_CONTRACT_BASE_TYPES</macroname></computeroutput>:</para><para><programlisting language="c++">class u
576 #define BASES public b, private w
579 friend class boost::contract:access;
581 typedef BOOST_CONTRACT_BASE_TYPES(BASES) BOOST_CONTRACT_TYPEDEF;
586 </programlisting></para><para>When used this way, users can redefine this macro if the <computeroutput>typedef</computeroutput> must have a name different from <computeroutput>base_types</computeroutput> (because of name clashes in user code, etc.).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.base_classes__subcontracting_"> Base Classes</link> </para>
588 </para></description></macro>
589 <macro name="BOOST_CONTRACT_INVARIANT_FUNC"><purpose>Define the name of the class invariant member function (<computeroutput>invariant</computeroutput> by default). </purpose><description><para>This macro expands to the name of the <computeroutput>const</computeroutput> and <computeroutput>const volatile</computeroutput> member functions that check class invariants and volatile class invariants respectively:</para><para><programlisting language="c++">class u {
590 friend class boost::contract::access;
592 void BOOST_CONTRACT_INVARIANT_FUNC() const {
593 BOOST_CONTRACT_ASSERT(...);
597 void BOOST_CONTRACT_INVARIANT_FUNC() const volatile {
598 BOOST_CONTRACT_ASSERT(...);
604 </programlisting></para><para>When used this way, users can redefine this macro if the invariant functions must have a name different from <computeroutput>invariant</computeroutput> (because of name clashes in user code, etc.).</para><para><note><para>C++ does not allow to overload member functions based on the <computeroutput>static</computeroutput> classifier, so this macro must always be defined to be different than the function name defined for <computeroutput><macroname alt="BOOST_CONTRACT_STATIC_INVARIANT_FUNC">BOOST_CONTRACT_STATIC_INVARIANT_FUNC</macroname></computeroutput>.</para>
606 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.class_invariants"> Class Invariants</link>, <link linkend="boost_contract.extras.volatile_public_functions">
607 Volatile Public Functions</link> </para>
609 </para></description></macro>
610 <macro name="BOOST_CONTRACT_STATIC_INVARIANT_FUNC"><purpose>Define the name of the static invariant member function (<computeroutput>static_invariant</computeroutput> by default). </purpose><description><para>This macro expands to the name of the <computeroutput>static</computeroutput> member function that checks static class invariants:</para><para><programlisting language="c++">class u {
611 friend class boost::contract::access;
613 static void BOOST_CONTRACT_STATIC_INVARIANT_FUNC() {
614 BOOST_CONTRACT_ASSERT(...);
620 </programlisting></para><para>When used this way, users can redefine this macro if the static invariant function must have a name different from <computeroutput>static_invariant</computeroutput> (because of name clashes in user code, etc.).</para><para><note><para>C++ does not allow to overload member functions based on the <computeroutput>static</computeroutput> classifier, so this macro must always be defined to be different than the function name defined for <computeroutput><macroname alt="BOOST_CONTRACT_INVARIANT_FUNC">BOOST_CONTRACT_INVARIANT_FUNC</macroname></computeroutput>.</para>
622 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.class_invariants"> Class Invariants</link> </para>
624 </para></description></macro>
625 <macro name="BOOST_CONTRACT_PERMISSIVE"><purpose>Disable some compile-time errors generated by this library (undefined by default). </purpose><description><para>Defining this macro disables a number of static checks and related compile-time errors generated by this library, for example:</para><para><itemizedlist>
626 <listitem><para>The static invariant member function named as <computeroutput>BOOST_CONTRACT_STATIC_INVARIANT_FUNC</computeroutput> must be declared <computeroutput>static</computeroutput>. </para>
628 <listitem><para>Non-static invariant member functions named as <computeroutput>BOOST_CONTRACT_INVARIANT_FUNC</computeroutput> must be declared either <computeroutput>const</computeroutput>, <computeroutput>const volatile</computeroutput>, or <computeroutput>volatile const</computeroutput>. </para>
630 <listitem><para>Derived classes that program contracts for one or more public function overrides via <computeroutput><functionname alt="boost::contract::public_function">boost::contract::public_function</functionname></computeroutput> must also define the <computeroutput><macroname alt="BOOST_CONTRACT_BASE_TYPES">BOOST_CONTRACT_BASE_TYPES</macroname></computeroutput> <computeroutput>typedef</computeroutput>.</para>
633 In general, it is not recommended to define this macro because these compile-time checks can guard against misuses of this library.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.class_invariants"> Class Invariants</link>, <link linkend="boost_contract.tutorial.base_classes__subcontracting_"> Base Classes</link> </para>
635 </para></description></macro>
636 <macro name="BOOST_CONTRACT_ON_MISSING_CHECK_DECL"><purpose>Code block to execute if contracts are not assigned to a <computeroutput><classname alt="boost::contract::check">boost::contract::check</classname></computeroutput> variable (undefined and executes <computeroutput>BOOST_ASSERT(false)</computeroutput> by default). </purpose><description><para>In general, there is a logic error in the program when contracts are not explicitly assigned to a local variable of type <computeroutput><classname alt="boost::contract::check">boost::contract::check</classname></computeroutput> and without using C++11 <computeroutput>auto</computeroutput> declarations (because that is a misuse of this library). Therefore, by default (i.e., when this macro is not defined) this library calls <computeroutput>BOOST_ASSERT(false)</computeroutput> in those cases. If this macro is defined, this library will execute the code expanded by this macro instead of calling <computeroutput>BOOST_ASSERT(false)</computeroutput> (if programmers prefer to throw an exception, etc.).</para><para>This macro can also be defined to be any block of code (and use empty curly brackets <computeroutput>{}</computeroutput> to generate no error, not recommended), for example (on GCC): <programlisting language="c++">gcc -DBOOST_CONTRACT_ON_MISSING_CHECK_DECL='{ throw std::logic_error("missing contract check declaration"); }' ...
637 </programlisting></para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial"> Tutorial</link> </para>
639 </para></description></macro>
640 <macro name="BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION"><purpose>Define this macro to not disable other assertions while checking preconditions (undefined by default). </purpose><description><para>Not disabling other assertions while checking preconditions can lead to infinite recursion in user code so by default this macro is not defined.</para><para>However, the <link linkend="boost_contract.bibliography"> [N1962]</link> proposal does not disable assertions while checking preconditions because arguments can reach the function body unchecked if assertions are disabled while checking preconditions (e.g., when these same functions bodies are called to check the preconditions in question). This macro can be defined to obtain the behaviour specified in <link linkend="boost_contract.bibliography"> [N1962]</link> (at the risk of infinite recursion).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.contract_programming_overview.feature_summary">
641 Feature Summary</link> </para>
643 </para></description></macro>
644 <macro name="BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION"><purpose>Define this macro to not disable any assertion while checking other assertions (undefined by default). </purpose><description><para>Not disabling assertions while checking other assertions can lead to infinite recursion in user code so by default this macro is not defined. (Defining this macro automatically implies that other assertion checking is disabled while checking preconditions as if <computeroutput><macroname alt="BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION">BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION</macroname></computeroutput> was also defined.)</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.contract_programming_overview.feature_summary">
645 Feature Summary</link> </para>
647 </para></description></macro>
648 <macro name="BOOST_CONTRACT_AUDITS"><purpose>Define this macro to evaluate and check audit assertions at run-time (undefined by default). </purpose><description><para>Audit assertions and implementation checks programmed via <computeroutput><macroname alt="BOOST_CONTRACT_ASSERT_AUDIT">BOOST_CONTRACT_ASSERT_AUDIT</macroname></computeroutput> and <computeroutput><macroname alt="BOOST_CONTRACT_CHECK_AUDIT">BOOST_CONTRACT_CHECK_AUDIT</macroname></computeroutput> are always compiled and validated syntactically. However, they are not evaluated and checked at run-time unless this macro is defined (because these conditions can be computationally expensive, at least compared to the computational cost of executing the function body).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.assertion_levels"> Assertion Levels</link> </para>
650 </para></description></macro>
651 <macro name="BOOST_CONTRACT_NO_CHECKS"><purpose>If defined, this library disables implementation checks (undefined by default). </purpose><description><para>If this macro is defined, this library internal code is also optimized to reduce compile-time (not just run-time) overhead associated with implementation checks. In addition, users can manually program <computeroutput>#ifndef</computeroutput> statements in their code using this macro to completely disable compilation of implementation checks or use <computeroutput><macroname alt="BOOST_CONTRACT_CHECK">BOOST_CONTRACT_CHECK</macroname></computeroutput> (recommended).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.implementation_checks">
652 Implementation Checks</link>, <link linkend="boost_contract.extras.disable_contract_checking">
653 Disable Contract Checking</link>, <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
654 Disable Contract Compilation</link> </para>
656 </para></description></macro>
657 <macro name="BOOST_CONTRACT_NO_PRECONDITIONS"><purpose>If defined, this library does not check preconditions (undefined by default). </purpose><description><para>If this macro is defined, this library internal code is also optimized to reduce compile-time (not just run-time) overhead associated with checking preconditions. In addition, users can manually program <computeroutput>#ifndef</computeroutput> statements in their code using this macro to completely disable compilation of preconditions or use the macros defined in <computeroutput>boost/contract_macro.hpp</computeroutput> (recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.preconditions"> Preconditions</link>, <link linkend="boost_contract.extras.disable_contract_checking">
658 Disable Contract Checking</link>, <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
659 Disable Contract Compilation</link> </para>
661 </para></description></macro>
662 <macro name="BOOST_CONTRACT_NO_POSTCONDITIONS"><purpose>If defined, this library does not check postconditions (undefined by default). </purpose><description><para>If this macro is defined, this library internal code is also optimized to reduce compile-time (not just run-time) overhead associated with checking postconditions. In addition, users can manually program <computeroutput>#ifndef</computeroutput> statements in their code using this macro to completely disable compilation of postconditions or use the macros defined in <computeroutput>boost/contract_macro.hpp</computeroutput> (recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).</para><para>It is necessary to disable both postconditions and exception guarantees defining <computeroutput><macroname alt="BOOST_CONTRACT_NO_POSTCONDITIONS">BOOST_CONTRACT_NO_POSTCONDITIONS</macroname></computeroutput> and <computeroutput><macroname alt="BOOST_CONTRACT_NO_EXCEPTS">BOOST_CONTRACT_NO_EXCEPTS</macroname></computeroutput> in order to disable old value copies (see <computeroutput><macroname alt="BOOST_CONTRACT_NO_OLDS">BOOST_CONTRACT_NO_OLDS</macroname></computeroutput>).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.postconditions"> Postconditions</link>, <link linkend="boost_contract.extras.disable_contract_checking">
663 Disable Contract Checking</link>, <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
664 Disable Contract Compilation</link> </para>
666 </para></description></macro>
667 <macro name="BOOST_CONTRACT_NO_EXCEPTS"><purpose>If defined, this library does not check exception guarantees (undefined by default). </purpose><description><para>If this macro is defined, this library internal code is also optimized to reduce compile-time (not just run-time) overhead associated with checking exception guarantees. In addition, users can manually program <computeroutput>#ifndef</computeroutput> statements in their code using this macro to completely disable compilation of exception guarantees or use the macros defined in <computeroutput>boost/contract_macro.hpp</computeroutput> (recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).</para><para>It is necessary to disable both postconditions and exception guarantees defining <computeroutput><macroname alt="BOOST_CONTRACT_NO_POSTCONDITIONS">BOOST_CONTRACT_NO_POSTCONDITIONS</macroname></computeroutput> and <computeroutput><macroname alt="BOOST_CONTRACT_NO_EXCEPTS">BOOST_CONTRACT_NO_EXCEPTS</macroname></computeroutput> in order to disable old value copies (see <computeroutput><macroname alt="BOOST_CONTRACT_NO_OLDS">BOOST_CONTRACT_NO_OLDS</macroname></computeroutput>).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.exception_guarantees"> Exception Guarantees</link>, <link linkend="boost_contract.extras.disable_contract_checking">
668 Disable Contract Checking</link>, <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
669 Disable Contract Compilation</link> </para>
671 </para></description></macro>
672 <macro name="BOOST_CONTRACT_NO_ENTRY_INVARIANTS"><purpose>If defined, this library does not check class invariants at entry (undefined by default). </purpose><description><para>If this macro is defined, this library internal code is also optimized to reduce compile-time (not just run-time) overhead associated with checking class invariants at entry. In addition, users can manually program <computeroutput>#ifndef</computeroutput> statements in their code using this macro to completely disable compilation of entry class invariants or use the macros defined in <computeroutput>boost/contract_macro.hpp</computeroutput> (recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).</para><para>This macro is automatically defined when <computeroutput><macroname alt="BOOST_CONTRACT_NO_INVARIANTS">BOOST_CONTRACT_NO_INVARIANTS</macroname></computeroutput> is defined.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.class_invariants"> Class Invariants</link>, <link linkend="boost_contract.extras.disable_contract_checking">
673 Disable Contract Checking</link>, <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
674 Disable Contract Compilation</link> </para>
676 </para></description></macro>
677 <macro name="BOOST_CONTRACT_NO_EXIT_INVARIANTS"><purpose>If defined, this library does not check class invariants at exit (undefined by default). </purpose><description><para>If this macro is defined, this library internal code is also optimized to reduce compile-time (not just run-time) overhead associated with checking class invariants at exit. In addition, users can manually program <computeroutput>#ifndef</computeroutput> statements in their code using this macro to completely disable compilation of exit class invariants or use the macros defined in <computeroutput>boost/contract_macro.hpp</computeroutput> (recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).</para><para>This macro is automatically defined when <computeroutput><macroname alt="BOOST_CONTRACT_NO_INVARIANTS">BOOST_CONTRACT_NO_INVARIANTS</macroname></computeroutput> is defined.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.class_invariants"> Class Invariants</link>, <link linkend="boost_contract.extras.disable_contract_checking">
678 Disable Contract Checking</link>, <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
679 Disable Contract Compilation</link> </para>
681 </para></description></macro>
682 <macro name="BOOST_CONTRACT_NO_INVARIANTS"><purpose>If defined, this library does not check class invariants (undefined by default). </purpose><description><para>If this macro is defined, this library internal code is also optimized to reduce compile-time (not just run-time) overhead associated with checking class invariants. In addition, users can manually program <computeroutput>#ifndef</computeroutput> statements in their code using this macro to completely disable compilation of class invariants or use the macros defined in <computeroutput>boost/contract_macro.hpp</computeroutput> (recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).</para><para>Defining this macro is equivalent to defining both <computeroutput><macroname alt="BOOST_CONTRACT_NO_ENTRY_INVARIANTS">BOOST_CONTRACT_NO_ENTRY_INVARIANTS</macroname></computeroutput> and <computeroutput><macroname alt="BOOST_CONTRACT_NO_EXIT_INVARIANTS">BOOST_CONTRACT_NO_EXIT_INVARIANTS</macroname></computeroutput>.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.class_invariants"> Class Invariants</link>, <link linkend="boost_contract.extras.disable_contract_checking">
683 Disable Contract Checking</link>, <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
684 Disable Contract Compilation</link> </para>
686 </para></description></macro>
687 <macro name="BOOST_CONTRACT_NO_OLDS"><purpose>Automatically defined by this library when old value copies are not to be performed. </purpose><description><para>This macro is not a configuration macro and this library will generate a compile-time error if users try to define it directly. This library will automatically define this macro when users define both <computeroutput><macroname alt="BOOST_CONTRACT_NO_POSTCONDITIONS">BOOST_CONTRACT_NO_POSTCONDITIONS</macroname></computeroutput> and <computeroutput><macroname alt="BOOST_CONTRACT_NO_EXCEPTS">BOOST_CONTRACT_NO_EXCEPTS</macroname></computeroutput>. Users can manually program <computeroutput>#ifndef</computeroutput> statements in their code using this macro to completely disable compilation of old value copies or use the macros defined in <computeroutput>boost/contract_macro.hpp</computeroutput> (recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.old_values"> Old Values</link>, <link linkend="boost_contract.advanced.old_values_copied_at_body">
688 Old Values Copied at Body</link>, <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
689 Disable Contract Compilation</link> </para>
691 </para></description></macro>
692 <macro name="BOOST_CONTRACT_NO_CONSTRUCTORS"><purpose>Automatically defined by this library when contracts are not checked for constructors. </purpose><description><para>This macro is not a configuration macro and this library will generate a compile-time error if users try to define it directly. This library will automatically define this macro when users define all <computeroutput><macroname alt="BOOST_CONTRACT_NO_INVARIANTS">BOOST_CONTRACT_NO_INVARIANTS</macroname></computeroutput>, <computeroutput><macroname alt="BOOST_CONTRACT_NO_POSTCONDITIONS">BOOST_CONTRACT_NO_POSTCONDITIONS</macroname></computeroutput>, and <computeroutput><macroname alt="BOOST_CONTRACT_NO_EXCEPTS">BOOST_CONTRACT_NO_EXCEPTS</macroname></computeroutput>. Users can manually program <computeroutput>#ifndef</computeroutput> statements in their code using this macro to completely disable compilation of contracts for constructors or use the macros defined in <computeroutput>boost/contract_macro.hpp</computeroutput> (recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).</para><para><note><para>Constructor preconditions are checked separately by <computeroutput><classname alt="boost::contract::constructor_precondition">boost::contract::constructor_precondition</classname></computeroutput> so they are disabled by <computeroutput><macroname alt="BOOST_CONTRACT_NO_PRECONDITIONS">BOOST_CONTRACT_NO_PRECONDITIONS</macroname></computeroutput> instead.</para>
694 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.constructors"> Constructors</link>, <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
695 Disable Contract Compilation</link> </para>
697 </para></description></macro>
698 <macro name="BOOST_CONTRACT_NO_DESTRUCTORS"><purpose>Automatically defined by this library when contracts are not checked for destructors. </purpose><description><para>This macro is not a configuration macro and this library will generate a compile-time error if users try to define it directly. This library will automatically define this macro when users define all <computeroutput><macroname alt="BOOST_CONTRACT_NO_INVARIANTS">BOOST_CONTRACT_NO_INVARIANTS</macroname></computeroutput>, <computeroutput><macroname alt="BOOST_CONTRACT_NO_POSTCONDITIONS">BOOST_CONTRACT_NO_POSTCONDITIONS</macroname></computeroutput>, and <computeroutput><macroname alt="BOOST_CONTRACT_NO_EXCEPTS">BOOST_CONTRACT_NO_EXCEPTS</macroname></computeroutput>. Users can manually program <computeroutput>#ifndef</computeroutput> statements in their code using this macro to completely disable compilation of contracts for destructors or use the macros defined in <computeroutput>boost/contract_macro.hpp</computeroutput> (recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.destructors"> Destructors</link>, <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
699 Disable Contract Compilation</link> </para>
701 </para></description></macro>
702 <macro name="BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS"><purpose>Automatically defined by this library when contracts are not checked for public functions. </purpose><description><para>This macro is not a configuration macro and this library will generate a compile-time error if users try to define it directly. This library will automatically define this macro when users define all <computeroutput><macroname alt="BOOST_CONTRACT_NO_INVARIANTS">BOOST_CONTRACT_NO_INVARIANTS</macroname></computeroutput>, <computeroutput><macroname alt="BOOST_CONTRACT_NO_PRECONDITIONS">BOOST_CONTRACT_NO_PRECONDITIONS</macroname></computeroutput>, <computeroutput><macroname alt="BOOST_CONTRACT_NO_POSTCONDITIONS">BOOST_CONTRACT_NO_POSTCONDITIONS</macroname></computeroutput>, and <computeroutput><macroname alt="BOOST_CONTRACT_NO_EXCEPTS">BOOST_CONTRACT_NO_EXCEPTS</macroname></computeroutput>. Users can manually program <computeroutput>#ifndef</computeroutput> statements in their code using this macro to completely disable compilation of contracts for public functions or use the macros defined in <computeroutput>boost/contract_macro.hpp</computeroutput> (recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.public_functions"> Public Functions</link>, <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
703 Disable Contract Compilation</link> </para>
705 </para></description></macro>
706 <macro name="BOOST_CONTRACT_NO_FUNCTIONS"><purpose>Automatically defined by this library when contracts are not checked for non-member, private, or protected functions. </purpose><description><para>This macro is not a configuration macro and this library will generate a compile-time error if users try to define it directly. This library will automatically define this macro when users define all <computeroutput><macroname alt="BOOST_CONTRACT_NO_PRECONDITIONS">BOOST_CONTRACT_NO_PRECONDITIONS</macroname></computeroutput>, <computeroutput><macroname alt="BOOST_CONTRACT_NO_POSTCONDITIONS">BOOST_CONTRACT_NO_POSTCONDITIONS</macroname></computeroutput>, and <computeroutput><macroname alt="BOOST_CONTRACT_NO_EXCEPTS">BOOST_CONTRACT_NO_EXCEPTS</macroname></computeroutput>. Users can manually program <computeroutput>#ifndef</computeroutput> statements in their code using this macro to completely disable compilation of contracts for non-member, private and protected functions, or use the macros defined in <computeroutput>boost/contract_macro.hpp</computeroutput> (recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).</para><para>This macro is also used when contracts are not checked for private or protected functions, lambda functions, code blocks, loops, etc.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.non_member_functions"> Non-Member Functions</link>, <link linkend="boost_contract.advanced.private_and_protected_functions">
707 Private and Protected Functions</link>, <link linkend="boost_contract.advanced.lambdas__loops__code_blocks__and__constexpr__">
708 Lambdas, Loops, Code Blocks</link>, <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
709 Disable Contract Compilation</link> </para>
711 </para></description></macro>
712 <macro name="BOOST_CONTRACT_NO_CONDITIONS"><purpose>Automatically defined by this library when contracts are not checked for preconditions, postconditions, exceptions guarantees, and class invariants (excluding implementation checks). </purpose><description><para>This macro is not a configuration macro and this library will generate a compile-time error if users try to define it directly. This library will automatically define this macro when users define all <computeroutput><macroname alt="BOOST_CONTRACT_NO_PRECONDITIONS">BOOST_CONTRACT_NO_PRECONDITIONS</macroname></computeroutput>, <computeroutput><macroname alt="BOOST_CONTRACT_NO_POSTCONDITIONS">BOOST_CONTRACT_NO_POSTCONDITIONS</macroname></computeroutput>, <computeroutput><macroname alt="BOOST_CONTRACT_NO_EXCEPTS">BOOST_CONTRACT_NO_EXCEPTS</macroname></computeroutput>, and <computeroutput><macroname alt="BOOST_CONTRACT_NO_INVARIANTS">BOOST_CONTRACT_NO_INVARIANTS</macroname></computeroutput>. Users can manually program <computeroutput>#ifndef</computeroutput> statements in their code using this macro to completely disable compilation of contracts within specifications (so excluding implementation checks which are contracts within implementations instead), or use the macros defined in <computeroutput>boost/contract_macro.hpp</computeroutput> (recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
713 Disable Contract Compilation</link> </para>
715 </para></description></macro>
716 <macro name="BOOST_CONTRACT_NO_ALL"><purpose>Automatically defined by this library when contracts are not checked at all (neither for specifications nor for implementations). </purpose><description><para>This macro is not a configuration macro and this library will generate a compile-time error if users try to define it directly. This library will automatically define this macro when users define all <computeroutput><macroname alt="BOOST_CONTRACT_NO_INVARIANTS">BOOST_CONTRACT_NO_INVARIANTS</macroname></computeroutput>, <computeroutput><macroname alt="BOOST_CONTRACT_NO_PRECONDITIONS">BOOST_CONTRACT_NO_PRECONDITIONS</macroname></computeroutput>, <computeroutput><macroname alt="BOOST_CONTRACT_NO_POSTCONDITIONS">BOOST_CONTRACT_NO_POSTCONDITIONS</macroname></computeroutput>, <computeroutput><macroname alt="BOOST_CONTRACT_NO_EXCEPTS">BOOST_CONTRACT_NO_EXCEPTS</macroname></computeroutput>, and <computeroutput><macroname alt="BOOST_CONTRACT_NO_CHECKS">BOOST_CONTRACT_NO_CHECKS</macroname></computeroutput>. For example, users can manually program <computeroutput>#ifndef</computeroutput> statements in their code using this macro to avoid including the <computeroutput>boost/contract.hpp</computeroutput> header all together:</para><para><programlisting language="c++">#include <boost/contract/core/config.hpp>
717 #ifndef BOOST_CONTRACT_NO_ALL
718 #include <boost/contract.hpp>
720 </programlisting></para><para>Or, use the <computeroutput>boost/contract_macro.hpp</computeroutput> header and related macros instead (because the <computeroutput>boost/contract_macro.hpp</computeroutput> header is already optimized to not include other headers from this library when contracts are not checked, but recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
721 Disable Contract Compilation</link> </para>
723 </para></description></macro>
725 <header name="boost/contract/core/constructor_precondition.hpp">
726 <para>Program preconditions for constructors. </para><namespace name="boost">
727 <namespace name="contract">
728 <class name="constructor_precondition"><template>
729 <template-type-parameter name="Class"><purpose><para>The class type of the constructor for which preconditions are being programmed. </para></purpose></template-type-parameter>
730 </template><purpose>Program preconditions for constructors. </purpose><description><para>This class must be the very first base of the class declaring the constructor for which preconditions are programmed (that way constructor arguments can be checked by preconditions even before they are used to initialize other base classes):</para><para><programlisting language="c++">class u
731 #define BASES private boost::contract::constructor_precondition<u>, \
735 friend class boost::contract::access;
737 typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types;
741 explicit u(unsigned x) :
742 boost::contract::constructor_precondition<u>([&] {
743 BOOST_CONTRACT_ASSERT(x != 0);
753 </programlisting></para><para>User-defined classes should inherit privately from this class (to not alter the public interface of user-defined classes). In addition, this class should never be declared as a virtual base (because virtual bases are initialized only once across the entire inheritance hierarchy preventing preconditions of other base classes from being checked).</para><para>This class cannot be used this way in a <computeroutput>union</computeroutput> because unions cannot have base classes in C++. Instead, this class is used in a <computeroutput>union</computeroutput> to declare a local object within the constructor definition just before <computeroutput><functionname alt="boost::contract::constructor">boost::contract::constructor</functionname></computeroutput> is used (see <link linkend="boost_contract.extras.unions"> Unions</link>).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.constructors"> Constructors</link></para>
756 </para></description><method-group name="public member functions">
758 <constructor><purpose>Construct this object without specifying constructor preconditions. </purpose><description><para>This is implicitly called for those constructors of the contracted class that do not specify preconditions.</para><para><note><para>The implementation of this library is optimized so that calling this default constructor should amount to negligible compile-time and run-time overheads (likely to be optimized away completely by most compilers). </para>
760 </para></description></constructor>
761 <constructor specifiers="explicit"><template>
762 <template-type-parameter name="F"/>
763 </template><parameter name="f"><paramtype>F const &</paramtype><description><para>Nullary functor called by this library to check constructor preconditions <computeroutput>f()</computeroutput>. Assertions within this functor call are usually programmed using <computeroutput><macroname alt="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</macroname></computeroutput>, but any exception thrown by a call to this functor indicates a contract failure (and will result in this library calling <computeroutput><functionname alt="boost::contract::precondition_failure">boost::contract::precondition_failure</functionname></computeroutput>). This functor should capture variables by (constant) value, or better by (constant) reference to avoid extra copies. </para></description></parameter><purpose>Construct this object specifying constructor preconditions. </purpose><description><para>
764 </para></description></constructor>
808 <header name="boost/contract/core/exception.hpp">
809 <para>Handle contract assertion failures. </para><namespace name="boost">
810 <namespace name="contract">
811 <class name="assertion_failure"><inherit access="public">std::exception</inherit><inherit access="public">boost::contract::exception</inherit><purpose>Exception typically used to report a contract assertion failure. </purpose><description><para>This exception is thrown by code expanded by <computeroutput><macroname alt="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</macroname></computeroutput> (but it can also be thrown by user code programmed manually without that macro). This exception is typically used to report contract assertion failures because it contains detailed information about the file name, line number, and source code of the asserted condition (so it can be used by this library to provide detailed error messages when handling contract assertion failures).</para><para>However, any other exception can be used to report a contract assertion failure (including user-defined exceptions). This library will call the appropriate contract failure handler function ( <computeroutput><functionname alt="boost::contract::precondition_failure">boost::contract::precondition_failure</functionname></computeroutput>, etc.) when this or any other exception is thrown while checking contracts (by default, these failure handler functions print an error message to <computeroutput>std::cerr</computeroutput> and terminate the program, but they can be customized to take any other action).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_"> No Macros</link> </para>
813 </para></description><method-group name="public member functions">
814 <method name="what" cv="const" specifiers="virtual"><type>char const *</type><purpose>String describing the failed assertion. </purpose><description><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11).</para><para>
815 </para></description><returns><para>A string formatted similarly to the following: <computeroutput>assertion "`code()`" failed: file "`file()`", line `line()`</computeroutput> (where `` indicate execution quotes). File, line, and code will be omitted from this string if they were not specified when constructing this object. </para>
817 <method name="file" cv="const"><type>char const *</type><purpose>Name of the file containing the assertion. </purpose><description><para>
818 </para></description><returns><para>File name as specified at construction (or <computeroutput>""</computeroutput> if no file was specified). </para>
820 <method name="line" cv="const"><type>unsigned long</type><purpose>Number of the line containing the assertion. </purpose><description><para>
821 </para></description><returns><para>Line number as specified at construction (or <computeroutput>0</computeroutput> if no line number was specified). </para>
823 <method name="code" cv="const"><type>char const *</type><purpose>Text listing the source code of the assertion condition. </purpose><description><para>
824 </para></description><returns><para>Assertion condition source code as specified at construction (or <computeroutput>""</computeroutput> if no source code text was specified). </para>
827 <constructor specifiers="explicit"><parameter name="file"><paramtype>char const *</paramtype><default>""</default><description><para>Name of the file containing the assertion (usually set using <computeroutput>__FILE__</computeroutput>). </para></description></parameter><parameter name="line"><paramtype>unsigned long</paramtype><default>0</default><description><para>Number of the line containing the assertion (usually set using <computeroutput>__LINE__</computeroutput>). </para></description></parameter><parameter name="code"><paramtype>char const *</paramtype><default>""</default><description><para>Text listing the source code of the assertion condition. </para></description></parameter><purpose>Construct this object with file name, line number, and source code text of an assertion condition (all optional). </purpose><description><para>This constructor can also be used to specify no information (default constructor), or to specify only file name and line number but not source code text (because of the parameter default values).</para><para>
828 </para></description></constructor>
829 <constructor specifiers="explicit"><parameter name="code"><paramtype>char const *</paramtype><description><para>Text listing the source code of the assertion condition. </para></description></parameter><purpose>Construct this object only with the source code text of the assertion condition. </purpose><description><para>
830 </para></description></constructor>
831 <destructor><purpose>Destruct this object. </purpose><description><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11). </para></description></destructor>
832 </class><class name="bad_virtual_result_cast"><inherit access="public">std::bad_cast</inherit><inherit access="public">boost::contract::exception</inherit><purpose>Exception thrown when inconsistent return values are passed to overridden virtual public functions. </purpose><description><para>This exception is thrown when programmers pass to this library return value parameters for public function overrides in derived classes that are not consistent with the return type parameter passed for the virtual public function being overridden from the base classes. This allows this library to give more descriptive error messages in such cases of misuse.</para><para>This exception is internally thrown by this library and programmers should not need to throw it from user code.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.public_function_overrides__subcontracting_">
833 Public Function Overrides</link> </para>
835 </para></description><method-group name="public member functions">
836 <method name="what" cv="const" specifiers="virtual"><type>char const *</type><purpose>Description for this error (containing both from- and to- type names). </purpose><description><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11). </para></description></method>
838 <constructor specifiers="explicit"><parameter name="from_type_name"><paramtype>char const *</paramtype><description><para>Name of the from-type (source of the cast). </para></description></parameter><parameter name="to_type_name"><paramtype>char const *</paramtype><description><para>Name of the to-type (destination of the cast). </para></description></parameter><purpose>Construct this object with the name of the from- and to- result types. </purpose><description><para>
839 </para></description></constructor>
840 <destructor><purpose>Destruct this object. </purpose><description><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11). </para></description></destructor>
841 </class><class name="exception"><purpose>Public base class for all exceptions directly thrown by this library. </purpose><description><para>This class does not inherit from <computeroutput>std::exception</computeroutput> because exceptions deriving from this class will do that (inheriting from <computeroutput>std::exception</computeroutput>, <computeroutput>std::bad_cast</computeroutput>, etc.).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <computeroutput><classname alt="boost::contract::assertion_failure">boost::contract::assertion_failure</classname></computeroutput>, <computeroutput><classname alt="boost::contract::bad_virtual_result_cast">boost::contract::bad_virtual_result_cast</classname></computeroutput>, etc. </para>
843 </para></description><method-group name="public member functions">
845 <destructor><purpose>Destruct this object. </purpose><description><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11). </para></description></destructor>
846 </class><enum name="from"><enumvalue name="from_constructor"><purpose>Assertion failed when checking contracts for constructors. </purpose></enumvalue><enumvalue name="from_destructor"><purpose>Assertion failed when checking contracts for destructors . </purpose></enumvalue><enumvalue name="from_function"><purpose>Assertion failed when checking contracts for functions (members or not, public or not). </purpose></enumvalue><purpose>Indicate the kind of operation where the contract assertion failed. </purpose><description><para>This is passed as a parameter to the assertion failure handler functions. For example, it might be necessary to know in which operation an assertion failed to make sure exceptions are never thrown from destructors, not even when contract failure handlers are programmed by users to throw exceptions instead of terminating the program.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link> </para>
848 </para></description></enum>
849 <typedef name="from_failure_handler"><purpose>Type of assertion failure handler functions (with <computeroutput>from</computeroutput> parameter). </purpose><description><para>Assertion failure handler functions specified by this type must be functors returning <computeroutput>void</computeroutput> and taking a single parameter of type <computeroutput><enumname alt="boost::contract::from">boost::contract::from</enumname></computeroutput>. For example, this is used to specify contract failure handlers for class invariants, preconditions, postconditions, and exception guarantees.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link> </para>
851 </para></description><type>boost::function< void(from)></type></typedef>
852 <typedef name="failure_handler"><purpose>Type of assertion failure handler functions (without <computeroutput>from</computeroutput> parameter). </purpose><description><para>Assertion failure handler functions specified by this type must be nullary functors returning <computeroutput>void</computeroutput>. For example, this is used to specify contract failure handlers for implementation checks.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link> </para>
854 </para></description><type>boost::function< void()></type></typedef>
873 <function name="set_check_failure"><type>failure_handler const &</type><parameter name="f"><paramtype>failure_handler const &</paramtype><description><para>New failure handler functor to set.</para></description></parameter><purpose>Set failure handler for implementation checks. </purpose><description><para>Set a new failure handler and returns it.</para><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11).</para><para>
875 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.advanced.implementation_checks"> Implementation Checks</link> </para>
877 </para></description><returns><para>Same failure handler functor <computeroutput>f</computeroutput> passed as parameter (e.g., for concatenating function calls).</para>
878 </returns></function>
879 <function name="get_check_failure"><type>failure_handler</type><purpose>Return failure handler currently set for implementation checks. </purpose><description><para>This is often called only internally by this library.</para><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11).</para><para>
880 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.advanced.implementation_checks"> Implementation Checks</link> </para>
882 </para></description><returns><para>A copy of the failure handler currently set.</para>
883 </returns></function>
884 <function name="check_failure"><type>void</type><purpose>Call failure handler for implementation checks. </purpose><description><para>This is often called only internally by this library.</para><para><emphasis role="bold">Throws:</emphasis> This can throw in case programmers specify a failure handler that throws exceptions on implementation check failures (not the default).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.advanced.implementation_checks"> Implementation Checks</link> </para>
886 </para></description></function>
887 <function name="set_precondition_failure"><type>from_failure_handler const &</type><parameter name="f"><paramtype>from_failure_handler const &</paramtype><description><para>New failure handler functor to set.</para></description></parameter><purpose>Set failure handler for preconditions. </purpose><description><para>Set a new failure handler and returns it.</para><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11).</para><para>
889 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.tutorial.preconditions"> Preconditions</link> </para>
891 </para></description><returns><para>Same failure handler functor <computeroutput>f</computeroutput> passed as parameter (e.g., for concatenating function calls).</para>
892 </returns></function>
893 <function name="get_precondition_failure"><type>from_failure_handler</type><purpose>Return failure handler currently set for preconditions. </purpose><description><para>This is often called only internally by this library.</para><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11).</para><para>
894 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.tutorial.preconditions"> Preconditions</link> </para>
896 </para></description><returns><para>A copy of the failure handler currently set.</para>
897 </returns></function>
898 <function name="precondition_failure"><type>void</type><parameter name="where"><paramtype>from</paramtype><description><para>Operation that failed the contract assertion (when this function is called by this library, this parameter will never be <computeroutput>from_destructor</computeroutput> because destructors do not have preconditions).</para></description></parameter><purpose>Call failure handler for preconditions. </purpose><description><para>This is often called only internally by this library.</para><para><emphasis role="bold">Throws:</emphasis> This can throw in case programmers specify a failure handler that throws exceptions on contract assertion failures (not the default).</para><para>
899 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.tutorial.preconditions"> Preconditions</link> </para>
901 </para></description></function>
902 <function name="set_postcondition_failure"><type>from_failure_handler const &</type><parameter name="f"><paramtype>from_failure_handler const &</paramtype><description><para>New failure handler functor to set.</para></description></parameter><purpose>Set failure handler for postconditions. </purpose><description><para>Set a new failure handler and returns it.</para><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11).</para><para>
904 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.tutorial.postconditions"> Postconditions</link> </para>
906 </para></description><returns><para>Same failure handler functor <computeroutput>f</computeroutput> passed as parameter (e.g., for concatenating function calls).</para>
907 </returns></function>
908 <function name="get_postcondition_failure"><type>from_failure_handler</type><purpose>Return failure handler currently set for postconditions. </purpose><description><para>This is often called only internally by this library.</para><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11).</para><para>
909 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.tutorial.postconditions"> Postconditions</link> </para>
911 </para></description><returns><para>A copy of the failure handler currently set.</para>
912 </returns></function>
913 <function name="postcondition_failure"><type>void</type><parameter name="where"><paramtype>from</paramtype><description><para>Operation that failed the contract assertion (e.g., this might be useful to program failure handler functors that never throw from destructors, not even when they are programmed by users to throw exceptions instead of terminating the program).</para></description></parameter><purpose>Call failure handler for postconditions. </purpose><description><para>This is often called only internally by this library.</para><para><emphasis role="bold">Throws:</emphasis> This can throw in case programmers specify a failure handler that throws exceptions on contract assertion failures (not the default).</para><para>
914 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.tutorial.postconditions"> Postconditions</link> </para>
916 </para></description></function>
917 <function name="set_except_failure"><type>from_failure_handler const &</type><parameter name="f"><paramtype>from_failure_handler const &</paramtype><description><para>New failure handler functor to set.</para></description></parameter><purpose>Set failure handler for exception guarantees. </purpose><description><para>Set a new failure handler and returns it.</para><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11).</para><para>
919 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.tutorial.exception_guarantees"> Exception Guarantees</link> </para>
921 </para></description><returns><para>Same failure handler functor <computeroutput>f</computeroutput> passed as parameter (e.g., for concatenating function calls).</para>
922 </returns></function>
923 <function name="get_except_failure"><type>from_failure_handler</type><purpose>Return failure handler currently set for exception guarantees. </purpose><description><para>This is often called only internally by this library.</para><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11).</para><para>
924 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.tutorial.exception_guarantees"> Exception Guarantees</link> </para>
926 </para></description><returns><para>A copy of the failure handler currently set.</para>
927 </returns></function>
928 <function name="except_failure"><type>void</type><parameter name="where"><paramtype>from</paramtype><description><para>Operation that failed the contract assertion.</para></description></parameter><purpose>Call failure handler for exception guarantees. </purpose><description><para>This is often called only internally by this library.</para><para><emphasis role="bold">Throws:</emphasis> This can throw in case programmers specify a failure handler that throws exceptions on contract assertion failures (not the default), however:</para><para><warning><para>When this failure handler is called there is already an active exception (the one that caused the exception guarantees to be checked in the first place). Therefore, programming this failure handler to throw yet another exception will force C++ to automatically terminate the program.</para>
931 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.tutorial.exception_guarantees"> Exception Guarantees</link> </para>
933 </para></description></function>
934 <function name="set_old_failure"><type>from_failure_handler const &</type><parameter name="f"><paramtype>from_failure_handler const &</paramtype><description><para>New failure handler functor to set.</para></description></parameter><purpose>Set failure handler for old values copied at body. </purpose><description><para>Set a new failure handler and returns it.</para><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11).</para><para>
936 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.advanced.old_values_copied_at_body"> Old Values Copied at Body</link> </para>
938 </para></description><returns><para>Same failure handler functor <computeroutput>f</computeroutput> passed as parameter (e.g., for concatenating function calls).</para>
939 </returns></function>
940 <function name="get_old_failure"><type>from_failure_handler</type><purpose>Return failure handler currently set for old values copied at body. </purpose><description><para>This is often called only internally by this library.</para><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11).</para><para>
941 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.advanced.old_values_copied_at_body"> Old Values Copied at Body</link> </para>
943 </para></description><returns><para>A copy of the failure handler currently set.</para>
944 </returns></function>
945 <function name="old_failure"><type>void</type><parameter name="where"><paramtype>from</paramtype><description><para>Operation that failed the old value copy (e.g., this might be useful to program failure handler functors that never throw from destructors, not even when they are programmed by users to throw exceptions instead of terminating the program).</para></description></parameter><purpose>Call failure handler for old values copied at body. </purpose><description><para>This is often called only internally by this library.</para><para><emphasis role="bold">Throws:</emphasis> This can throw in case programmers specify a failure handler that throws exceptions on contract assertion failures (not the default).</para><para>
946 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.advanced.old_values_copied_at_body"> Old Values Copied at Body</link> </para>
948 </para></description></function>
949 <function name="set_entry_invariant_failure"><type>from_failure_handler const &</type><parameter name="f"><paramtype>from_failure_handler const &</paramtype><description><para>New failure handler functor to set.</para></description></parameter><purpose>Set failure handler for class invariants at entry. </purpose><description><para>Set a new failure handler and returns it.</para><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11).</para><para>
951 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.tutorial.class_invariants"> Class Invariants</link>, <link linkend="boost_contract.extras.volatile_public_functions">
952 Volatile Public Functions</link> </para>
954 </para></description><returns><para>Same failure handler functor <computeroutput>f</computeroutput> passed as parameter (e.g., for concatenating function calls).</para>
955 </returns></function>
956 <function name="get_entry_invariant_failure"><type>from_failure_handler</type><purpose>Return failure handler currently set for class invariants at entry. </purpose><description><para>This is often called only internally by this library.</para><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11).</para><para>
957 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.tutorial.class_invariants"> Class Invariants</link>, <link linkend="boost_contract.extras.volatile_public_functions">
958 Volatile Public Functions</link> </para>
960 </para></description><returns><para>A copy of the failure handler currently set.</para>
961 </returns></function>
962 <function name="entry_invariant_failure"><type>void</type><parameter name="where"><paramtype>from</paramtype><description><para>Operation that failed the contract assertion (e.g., this might be useful to program failure handler functors that never throw from destructors, not even when they are programmed by users to throw exceptions instead of terminating the program).</para></description></parameter><purpose>Call failure handler for class invariants at entry. </purpose><description><para>This is often called only internally by this library.</para><para><emphasis role="bold">Throws:</emphasis> This can throw in case programmers specify a failure handler that throws exceptions on contract assertion failures (not the default).</para><para>
963 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.tutorial.class_invariants"> Class Invariants</link>, <link linkend="boost_contract.extras.volatile_public_functions">
964 Volatile Public Functions</link> </para>
966 </para></description></function>
967 <function name="set_exit_invariant_failure"><type>from_failure_handler const &</type><parameter name="f"><paramtype>from_failure_handler const &</paramtype><description><para>New failure handler functor to set.</para></description></parameter><purpose>Set failure handler for class invariants at exit. </purpose><description><para>Set a new failure handler and returns it.</para><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11).</para><para>
969 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.tutorial.class_invariants"> Class Invariants</link>, <link linkend="boost_contract.extras.volatile_public_functions">
970 Volatile Public Functions</link> </para>
972 </para></description><returns><para>Same failure handler functor <computeroutput>f</computeroutput> passed as parameter (e.g., for concatenating function calls).</para>
973 </returns></function>
974 <function name="get_exit_invariant_failure"><type>from_failure_handler</type><purpose>Return failure handler currently set for class invariants at exit. </purpose><description><para>This is often called only internally by this library.</para><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11).</para><para>
975 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.tutorial.class_invariants"> Class Invariants</link>, <link linkend="boost_contract.extras.volatile_public_functions">
976 Volatile Public Functions</link> </para>
978 </para></description><returns><para>A copy of the failure handler currently set.</para>
979 </returns></function>
980 <function name="exit_invariant_failure"><type>void</type><parameter name="where"><paramtype>from</paramtype><description><para>Operation that failed the contract assertion (e.g., this might be useful to program failure handler functors that never throw from destructors, not even when they are programmed by users to throw exceptions instead of terminating the program).</para></description></parameter><purpose>Call failure handler for class invariants at exit. </purpose><description><para>This is often called only internally by this library.</para><para><emphasis role="bold">Throws:</emphasis> This can throw in case programmers specify a failure handler that throws exceptions on contract assertion failures (not the default).</para><para>
981 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.tutorial.class_invariants"> Class Invariants</link>, <link linkend="boost_contract.extras.volatile_public_functions">
982 Volatile Public Functions</link> </para>
984 </para></description></function>
985 <function name="set_invariant_failure"><type>from_failure_handler const &</type><parameter name="f"><paramtype>from_failure_handler const &</paramtype><description><para>New failure handler functor to set for both entry and exit invariants.</para></description></parameter><purpose>Set failure handler for class invariants (at both entry and exit). </purpose><description><para>This is provided for convenience and it is equivalent to call both <computeroutput><functionname alt="boost::contract::set_entry_invariant_failure">boost::contract::set_entry_invariant_failure</functionname></computeroutput> and <computeroutput><functionname alt="boost::contract::set_exit_invariant_failure">boost::contract::set_exit_invariant_failure</functionname></computeroutput> with the same functor parameter <computeroutput>f</computeroutput>.</para><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11).</para><para>
987 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.tutorial.class_invariants"> Class Invariants</link>, <link linkend="boost_contract.extras.volatile_public_functions">
988 Volatile Public Functions</link> </para>
990 </para></description><returns><para>Same failure handler functor <computeroutput>f</computeroutput> passed as parameter (e.g., for concatenating function calls).</para>
991 </returns></function>
995 <header name="boost/contract/core/specify.hpp">
996 <para>Specify preconditions, old values copied at body, postconditions, and exception guarantees. </para><para>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. </para><namespace name="boost">
997 <namespace name="contract">
998 <class name="specify_except"><purpose>Allow to specify exception guarantees. </purpose><description><para>Allow to specify the functor this library will call to check exception guarantees. This object is internally constructed by the library when users specify contracts calling <computeroutput><functionname alt="boost::contract::function">boost::contract::function</functionname></computeroutput> and similar functions (that is why this class does not have a public constructor).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.exception_guarantees"> Exception Guarantees</link> </para>
1000 </para></description><method-group name="public member functions">
1001 <method name="except"><type><classname>specify_nothing</classname></type><template>
1002 <template-type-parameter name="F"/>
1003 </template><parameter name="f"><paramtype>F const &</paramtype><description><para>Nullary functor called by this library to check exception guarantees <computeroutput>f()</computeroutput>. Assertions within this functor are usually programmed using <computeroutput><macroname alt="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</macroname></computeroutput>, but any exception thrown by a call to this functor indicates a contract assertion failure (and will result in this library calling <computeroutput><functionname alt="boost::contract::except_failure">boost::contract::except_failure</functionname></computeroutput>). This functor should capture variables by (constant) references (to access the values they will have at function exit).</para></description></parameter><purpose>Allow to specify exception guarantees. </purpose><description><para>
1005 </para></description><returns><para>After exception guarantees have been specified, the object returned by this function does not allow to specify any additional contract. </para>
1008 <destructor><purpose>Destruct this object. </purpose><description><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept(false)</computeroutput> since C++11 to allow users to program failure handlers that throw exceptions on contract assertion failures (not the default, see <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__">
1009 Throw on Failure</link>). </para></description></destructor>
1010 </class><class name="specify_nothing"><purpose>Used to prevent setting other contract conditions after exception guarantees. </purpose><description><para>This class has no member function so it is used to prevent specifying additional functors to check any other contract. This object is internally constructed by the library when users specify contracts calling <computeroutput><functionname alt="boost::contract::function">boost::contract::function</functionname></computeroutput> and similar functions (that is why this class does not have a public constructor).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial"> Tutorial</link> </para>
1012 </para></description><method-group name="public member functions">
1014 <destructor><purpose>Destruct this object. </purpose><description><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept(false)</computeroutput> since C++11 to allow users to program failure handlers that throw exceptions on contract assertion failures (not the default, see <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__">
1015 Throw on Failure</link>). </para></description></destructor>
1016 </class><class name="specify_old_postcondition_except"><template>
1017 <template-type-parameter name="VirtualResult"><default>void</default><purpose><para>Return type of the enclosing function declaring the contract if that is either a virtual or an overriding public function, otherwise this is always <computeroutput>void</computeroutput>. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.) </para></purpose></template-type-parameter>
1018 </template><purpose>Allow to specify old values copied at body, postconditions, and exception guarantees. </purpose><description><para>Allow to specify functors this library will call to copy old values at body, check postconditions, and check exception guarantees. This object is internally constructed by the library when users specify contracts calling <computeroutput><functionname alt="boost::contract::function">boost::contract::function</functionname></computeroutput> and similar functions (that is why this class does not have a public constructor).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.old_values_copied_at_body"> Old Values Copied at Body</link>, <link linkend="boost_contract.tutorial.postconditions"> Postconditions</link>, <link linkend="boost_contract.tutorial.exception_guarantees"> Exception Guarantees</link></para>
1021 </para></description><method-group name="public member functions">
1022 <method name="old"><type><classname>specify_postcondition_except</classname>< VirtualResult ></type><template>
1023 <template-type-parameter name="F"/>
1024 </template><parameter name="f"><paramtype>F const &</paramtype><description><para>Nullary functor called by this library <computeroutput>f()</computeroutput> to assign old value copies just before the body is executed but after entry invariants (when they apply) and preconditions are checked. Old value pointers within this functor call are usually assigned using <computeroutput><macroname alt="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</macroname></computeroutput>. Any exception thrown by a call to this functor will result in this library calling <computeroutput><functionname alt="boost::contract::old_failure">boost::contract::old_failure</functionname></computeroutput> (because old values could not be copied to check postconditions and exception guarantees). This functor should capture old value pointers by references so they can be assigned (all other variables needed to evaluate old value expressions can be captured by (constant) value, or better by (constant) reference to avoid extra copies).</para></description></parameter><purpose>Allow to specify old values copied at body. </purpose><description><para>It should often be sufficient to initialize old value pointers as soon as they are declared, without using this function (see <link linkend="boost_contract.advanced.old_values_copied_at_body"> Old Values Copied at Body</link>).</para><para>
1026 </para></description><returns><para>After old values copied at body have been specified, the object returned by this function allows to optionally specify postconditions and exception guarantees. </para>
1028 <method name="postcondition"><type><classname>specify_except</classname></type><template>
1029 <template-type-parameter name="F"/>
1030 </template><parameter name="f"><paramtype>F const &</paramtype><description><para>Functor called by this library to check postconditions <computeroutput>f()</computeroutput> or <computeroutput>f(result)</computeroutput>. Assertions within this functor are usually programmed using <computeroutput><macroname alt="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</macroname></computeroutput>, but any exception thrown by a call to this functor indicates a contract assertion failure (and will result in this library calling <computeroutput><functionname alt="boost::contract::postcondition_failure">boost::contract::postcondition_failure</functionname></computeroutput>). This functor should capture variables by (constant) references (to access the values they will have at function exit). This functor must be a nullary functor <computeroutput>f()</computeroutput> if <computeroutput>VirtualResult</computeroutput> is <computeroutput>void</computeroutput>, otherwise it must be a unary functor <computeroutput>f(result)</computeroutput> accepting the return value <computeroutput>result</computeroutput> as a parameter of type <computeroutput>VirtualResult const&</computeroutput> (to avoid extra copies of the return value, or of type <computeroutput>VirtualResult</computeroutput> or <computeroutput>VirtualResult const</computeroutput> if extra copies of the return value are irrelevant).</para></description></parameter><purpose>Allow to specify postconditions. </purpose><description><para>
1032 </para></description><returns><para>After postconditions have been specified, the object returned by this function allows to optionally specify exception guarantees. </para>
1034 <method name="except"><type><classname>specify_nothing</classname></type><template>
1035 <template-type-parameter name="F"/>
1036 </template><parameter name="f"><paramtype>F const &</paramtype><description><para>Nullary functor called by this library to check exception guarantees <computeroutput>f()</computeroutput>. Assertions within this functor are usually programmed using <computeroutput><macroname alt="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</macroname></computeroutput>, but any exception thrown by a call to this functor indicates a contract assertion failure (and will result in this library calling <computeroutput><functionname alt="boost::contract::except_failure">boost::contract::except_failure</functionname></computeroutput>). This functor should capture variables by (constant) references (to access the values they will have at function exit).</para></description></parameter><purpose>Allow to specify exception guarantees. </purpose><description><para>
1038 </para></description><returns><para>After exception guarantees have been specified, the object returned by this function does not allow to specify any additional contract. </para>
1041 <destructor><purpose>Destruct this object. </purpose><description><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept(false)</computeroutput> since C++11 to allow users to program failure handlers that throw exceptions on contract assertion failures (not the default, see <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__">
1042 Throw on Failure</link>). </para></description></destructor>
1043 </class><class name="specify_postcondition_except"><template>
1044 <template-type-parameter name="VirtualResult"><default>void</default><purpose><para>Return type of the enclosing function declaring the contract if that is either a virtual or an overriding public function, otherwise this is always <computeroutput>void</computeroutput>. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.) </para></purpose></template-type-parameter>
1045 </template><purpose>Allow to specify postconditions or exception guarantees. </purpose><description><para>Allow to specify functors this library will call to check postconditions or exception guarantees. This object is internally constructed by the library when users specify contracts calling <computeroutput><functionname alt="boost::contract::function">boost::contract::function</functionname></computeroutput> and similar functions (that is why this class does not have a public constructor).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.postconditions"> Postconditions</link>, <link linkend="boost_contract.tutorial.exception_guarantees"> Exception Guarantees</link></para>
1048 </para></description><method-group name="public member functions">
1049 <method name="postcondition"><type><classname>specify_except</classname></type><template>
1050 <template-type-parameter name="F"/>
1051 </template><parameter name="f"><paramtype>F const &</paramtype><description><para>Functor called by this library to check postconditions <computeroutput>f()</computeroutput> or <computeroutput>f(result)</computeroutput>. Assertions within this functor are usually programmed using <computeroutput><macroname alt="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</macroname></computeroutput>, but any exception thrown by a call to this functor indicates a contract assertion failure (and will result in this library calling <computeroutput><functionname alt="boost::contract::postcondition_failure">boost::contract::postcondition_failure</functionname></computeroutput>). This functor should capture variables by (constant) references (to access the values they will have at function exit). This functor must be a nullary functor <computeroutput>f()</computeroutput> if <computeroutput>VirtualResult</computeroutput> is <computeroutput>void</computeroutput>, otherwise it must be a unary functor <computeroutput>f(result)</computeroutput> accepting the return value <computeroutput>result</computeroutput> as a parameter of type <computeroutput>VirtualResult const&</computeroutput> (to avoid extra copies of the return value, or of type <computeroutput>VirtualResult</computeroutput> or <computeroutput>VirtualResult const</computeroutput> if extra copies of the return value are irrelevant).</para></description></parameter><purpose>Allow to specify postconditions. </purpose><description><para>
1053 </para></description><returns><para>After postconditions have been specified, the object returned by this function allows to optionally specify exception guarantees. </para>
1055 <method name="except"><type><classname>specify_nothing</classname></type><template>
1056 <template-type-parameter name="F"/>
1057 </template><parameter name="f"><paramtype>F const &</paramtype><description><para>Nullary functor called by this library to check exception guarantees <computeroutput>f()</computeroutput>. Assertions within this functor are usually programmed using <computeroutput><macroname alt="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</macroname></computeroutput>, but any exception thrown by a call to this functor indicates a contract assertion failure (and will result in this library calling <computeroutput><functionname alt="boost::contract::except_failure">boost::contract::except_failure</functionname></computeroutput>). This functor should capture variables by (constant) references (to access the values they will have at function exit).</para></description></parameter><purpose>Allow to specify exception guarantees. </purpose><description><para>
1059 </para></description><returns><para>After exception guarantees have been specified, the object returned by this function does not allow to specify any additional contract. </para>
1062 <destructor><purpose>Destruct this object. </purpose><description><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept(false)</computeroutput> since C++11 to allow users to program failure handlers that throw exceptions on contract assertion failures (not the default, see <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__">
1063 Throw on Failure</link>). </para></description></destructor>
1064 </class><class name="specify_precondition_old_postcondition_except"><template>
1065 <template-type-parameter name="VirtualResult"><default>void</default><purpose><para>Return type of the enclosing function declaring the contract if that is either a virtual or an overriding public function, otherwise this is always <computeroutput>void</computeroutput>. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.) </para></purpose></template-type-parameter>
1066 </template><purpose>Allow to specify preconditions, old values copied at body, postconditions, and exception guarantees. </purpose><description><para>Allow to specify functors this library will call to check preconditions, copy old values at body, check postconditions, and check exception guarantees. This object is internally constructed by the library when users specify contracts calling <computeroutput><functionname alt="boost::contract::function">boost::contract::function</functionname></computeroutput> and similar functions (that is why this class does not have a public constructor).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.preconditions"> Preconditions</link>, <link linkend="boost_contract.advanced.old_values_copied_at_body"> Old Values Copied at Body</link>, <link linkend="boost_contract.tutorial.postconditions"> Postconditions</link>, <link linkend="boost_contract.tutorial.exception_guarantees"> Exception Guarantees</link></para>
1069 </para></description><method-group name="public member functions">
1070 <method name="precondition"><type><classname>specify_old_postcondition_except</classname>< VirtualResult ></type><template>
1071 <template-type-parameter name="F"/>
1072 </template><parameter name="f"><paramtype>F const &</paramtype><description><para>Nullary functor called by this library to check preconditions <computeroutput>f()</computeroutput>. Assertions within this functor are usually programmed using <computeroutput><macroname alt="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</macroname></computeroutput>, but any exception thrown by a call to this functor indicates a contract assertion failure (and will result in this library calling <computeroutput><functionname alt="boost::contract::precondition_failure">boost::contract::precondition_failure</functionname></computeroutput>). This functor should capture variables by (constant) value, or better by (constant) reference (to avoid extra copies).</para></description></parameter><purpose>Allow to specify preconditions. </purpose><description><para>
1074 </para></description><returns><para>After preconditions have been specified, the object returned by this function allows to optionally specify old values copied at body, postconditions, and exception guarantees. </para>
1076 <method name="old"><type><classname>specify_postcondition_except</classname>< VirtualResult ></type><template>
1077 <template-type-parameter name="F"/>
1078 </template><parameter name="f"><paramtype>F const &</paramtype><description><para>Nullary functor called by this library <computeroutput>f()</computeroutput> to assign old value copies just before the body is executed but after entry invariants (when they apply) and preconditions are checked. Old value pointers within this functor call are usually assigned using <computeroutput><macroname alt="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</macroname></computeroutput>. Any exception thrown by a call to this functor will result in this library calling <computeroutput><functionname alt="boost::contract::old_failure">boost::contract::old_failure</functionname></computeroutput> (because old values could not be copied to check postconditions and exception guarantees). This functor should capture old value pointers by references so they can be assigned (all other variables needed to evaluate old value expressions can be captured by (constant) value, or better by (constant) reference to avoid extra copies).</para></description></parameter><purpose>Allow to specify old values copied at body. </purpose><description><para>It should often be sufficient to initialize old value pointers as soon as they are declared, without using this function (see <link linkend="boost_contract.advanced.old_values_copied_at_body"> Old Values Copied at Body</link>).</para><para>
1080 </para></description><returns><para>After old values copied at body have been specified, the object returned by this functions allows to optionally specify postconditions and exception guarantees. </para>
1082 <method name="postcondition"><type><classname>specify_except</classname></type><template>
1083 <template-type-parameter name="F"/>
1084 </template><parameter name="f"><paramtype>F const &</paramtype><description><para>Functor called by this library to check postconditions <computeroutput>f()</computeroutput> or <computeroutput>f(result)</computeroutput>. Assertions within this functor are usually programmed using <computeroutput><macroname alt="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</macroname></computeroutput>, but any exception thrown by a call to this functor indicates a contract assertion failure (and will result in this library calling <computeroutput><functionname alt="boost::contract::postcondition_failure">boost::contract::postcondition_failure</functionname></computeroutput>). This functor should capture variables by (constant) references (to access the values they will have at function exit). This functor must be a nullary functor <computeroutput>f()</computeroutput> if <computeroutput>VirtualResult</computeroutput> is <computeroutput>void</computeroutput>, otherwise it must be a unary functor <computeroutput>f(result)</computeroutput> accepting the return value <computeroutput>result</computeroutput> as a parameter of type <computeroutput>VirtualResult const&</computeroutput> (to avoid extra copies of the return value, or of type <computeroutput>VirtualResult</computeroutput> or <computeroutput>VirtualResult const</computeroutput> if extra copies of the return value are irrelevant).</para></description></parameter><purpose>Allow to specify postconditions. </purpose><description><para>
1086 </para></description><returns><para>After postconditions have been specified, the object returned by this function allows to optionally specify exception guarantees. </para>
1088 <method name="except"><type><classname>specify_nothing</classname></type><template>
1089 <template-type-parameter name="F"/>
1090 </template><parameter name="f"><paramtype>F const &</paramtype><description><para>Nullary functor called by this library to check exception guarantees <computeroutput>f()</computeroutput>. Assertions within this functor are usually programmed using <computeroutput><macroname alt="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</macroname></computeroutput>, but any exception thrown by a call to this functor indicates a contract assertion failure (and will result in this library calling <computeroutput><functionname alt="boost::contract::except_failure">boost::contract::except_failure</functionname></computeroutput>). This functor should capture variables by (constant) references (to access the values they will have at function exit).</para></description></parameter><purpose>Allow to specify exception guarantees. </purpose><description><para>
1092 </para></description><returns><para>After exception guarantees have been specified, the object returned by this function does not allow to specify any additional contract. </para>
1095 <destructor><purpose>Destruct this object. </purpose><description><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept(false)</computeroutput> since C++11 to allow users to program failure handlers that throw exceptions on contract assertion failures (not the default, see <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__">
1096 Throw on Failure</link>). </para></description></destructor>
1140 <header name="boost/contract/core/virtual.hpp">
1141 <para>Handle virtual public functions with contracts (for subcontracting). </para><namespace name="boost">
1142 <namespace name="contract">
1143 <class name="virtual_"><purpose>Type of extra function parameter to handle contracts for virtual public functions (for subcontracting). </purpose><description><para>Virtual public functions (and therefore also public function overrides) declaring contracts using this library must specify an extra function parameter at the very end of their parameter list. This parameter must be a pointer to this class and it must have default value <computeroutput>0</computeroutput> or <computeroutput>nullptr</computeroutput> (this extra parameter is often named <computeroutput>v</computeroutput> in this documentation, but any name can be used):</para><para><programlisting language="c++">class u {
1145 virtual void f(int x, boost::contract::virtual_* v = 0) { // Declare `v`.
1146 ... // Contract declaration (which will use `v`) and function body.
1151 </programlisting></para><para>In practice this extra parameter does not alter the calling interface of the enclosing function declaring the contract because it is always the very last parameter and it has a default value (so it can always be omitted when users call the function). This extra parameter must be passed to <computeroutput><functionname alt="boost::contract::public_function">boost::contract::public_function</functionname></computeroutput>, <computeroutput><macroname alt="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</macroname></computeroutput>, and all other operations of this library that accept a pointer to <computeroutput><classname alt="boost::contract::virtual_">boost::contract::virtual_</classname></computeroutput>. A part from that, this class is not intended to be directly used by programmers (and that is why this class does not have any public member and it is not copyable).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.virtual_public_functions"> Virtual Public Functions</link>, <link linkend="boost_contract.tutorial.public_function_overrides__subcontracting_">
1152 Public Function Overrides</link> </para>
1154 </para></description></class>
1197 <header name="boost/contract/destructor.hpp">
1198 <para>Program contracts for destructors. </para><namespace name="boost">
1199 <namespace name="contract">
1205 <function name="destructor"><type><classname>specify_old_postcondition_except</classname></type><template>
1206 <template-type-parameter name="Class"><purpose><para>The type of the class containing the destructor declaring the contract. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.)</para></purpose></template-type-parameter>
1207 </template><parameter name="obj"><paramtype>Class *</paramtype><description><para>The object <computeroutput>this</computeroutput> from the scope of the enclosing destructor declaring the contract. (Destructors check all class invariants, including static and volatile invariants, see <link linkend="boost_contract.tutorial.class_invariants">
1208 Class Invariants</link> and <link linkend="boost_contract.extras.volatile_public_functions">
1209 Volatile Public Functions</link>).</para></description></parameter><purpose>Program contracts for destructors. </purpose><description><para>This is used to specify postconditions, exception guarantees, old value copies at body, and check class invariants for destructors (destructors cannot have preconditions, see <link linkend="boost_contract.contract_programming_overview.destructor_calls"> Destructor Calls</link>):</para><para><programlisting language="c++">class u {
1210 friend class boost::contract::access;
1212 void invariant() const { // Optional (as for static and volatile).
1213 BOOST_CONTRACT_ASSERT(...);
1219 boost::contract::old_ptr<old_type> old_var;
1220 boost::contract::check c = boost::contract::destructor(this)
1221 // No `.precondition` (destructors have no preconditions).
1222 .old([&] { // Optional.
1223 old_var = BOOST_CONTRACT_OLDOF(old_expr);
1226 .postcondition([&] { // Optional.
1227 BOOST_CONTRACT_ASSERT(...);
1230 .except([&] { // Optional.
1231 BOOST_CONTRACT_ASSERT(...);
1236 ... // Destructor body.
1241 </programlisting></para><para>For optimization, this can be omitted for destructors that do not have postconditions and exception guarantees, within classes that have no invariants.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.destructors"> Destructors</link></para>
1246 </para></description><returns><para>The result of this function must be assigned to a variable of type <computeroutput><classname alt="boost::contract::check">boost::contract::check</classname></computeroutput> declared explicitly (i.e., without using C++11 <computeroutput>auto</computeroutput> declarations) and locally just before the code of the destructor body (otherwise this library will generate a run-time error, see <computeroutput><macroname alt="BOOST_CONTRACT_ON_MISSING_CHECK_DECL">BOOST_CONTRACT_ON_MISSING_CHECK_DECL</macroname></computeroutput>). </para>
1247 </returns></function>
1285 <header name="boost/contract/function.hpp">
1286 <para>Program contracts for (non-public) functions. </para><namespace name="boost">
1287 <namespace name="contract">
1294 <function name="function"><type><classname>specify_precondition_old_postcondition_except</classname></type><purpose>Program contracts for non-member, private and protected functions. </purpose><description><para>This is used to specify preconditions, postconditions, exception guarantees, and old value copies at body for non-member, private and protected functions (these functions never check class invariants, see <link linkend="boost_contract.contract_programming_overview.function_calls"> Function Calls</link>):</para><para><programlisting language="c++">void f(...) {
1295 boost::contract::old_ptr<old_type> old_var;
1296 boost::contract::check c = boost::contract::function()
1297 .precondition([&] { // Optional.
1298 BOOST_CONTRACT_ASSERT(...);
1301 .old([&] { // Optional.
1302 old_var = BOOST_CONTRACT_OLDOF(old_expr);
1305 .postcondition([&] { // Optional.
1306 BOOST_CONTRACT_ASSERT(...);
1309 .except([&] { // Optional.
1310 BOOST_CONTRACT_ASSERT(...);
1315 ... // Function body.
1317 </programlisting></para><para>This can be used also to program contracts in implementation code for lambda functions, loops, and arbitrary blocks of code. For optimization, this can be omitted for code that does not have preconditions, postconditions, and exception guarantees.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.non_member_functions"> Non-Member Functions</link>, <link linkend="boost_contract.advanced.private_and_protected_functions">
1318 Private and Protected Functions</link>, <link linkend="boost_contract.advanced.lambdas__loops__code_blocks__and__constexpr__">
1319 Lambdas, Loops, Code Blocks</link></para>
1322 </para></description><returns><para>The result of this function must be assigned to a variable of type <computeroutput><classname alt="boost::contract::check">boost::contract::check</classname></computeroutput> declared explicitly (i.e., without using C++11 <computeroutput>auto</computeroutput> declarations) and locally just before the code of the function body (otherwise this library will generate a run-time error, see <computeroutput><macroname alt="BOOST_CONTRACT_ON_MISSING_CHECK_DECL">BOOST_CONTRACT_ON_MISSING_CHECK_DECL</macroname></computeroutput>). </para>
1323 </returns></function>
1360 <header name="boost/contract/old.hpp">
1361 <para>Handle old values. </para><namespace name="boost">
1362 <namespace name="contract">
1363 <struct name="is_old_value_copyable"><template>
1364 <template-type-parameter name="T"/>
1365 </template><inherit access="public">boost::is_copy_constructible< T ></inherit><purpose>Trait to check if an old value type can be copied or not. </purpose><description><para>By default, this unary boolean meta-function is equivalent to <computeroutput>boost::is_copy_constructible<T></computeroutput> but programmers can chose to specialize it for user-defined types (in general some kind of specialization is also needed on compilers that do not support C++11, see <ulink url="http://www.boost.org/doc/libs/release/libs/type_traits/doc/html/boost_typetraits/reference/is_copy_constructible.html"><computeroutput>boost::is_copy_constructible</computeroutput></ulink>):</para><para><programlisting language="c++">class u; // Some user-defined type for which old values shall not be copied.
1367 namespace boost { namespace contract {
1368 template<> // Specialization to not copy old values of type `u`.
1369 struct is_old_value_copyable<u> : boost::false_type {};
1371 </programlisting></para><para>A given old value type <computeroutput>T</computeroutput> is copied only if <computeroutput>boost::contract::is_old_value_copyable<T>::value</computeroutput> is <computeroutput>true</computeroutput>. A copyable old value type <computeroutput>V</computeroutput> is always copied using <computeroutput>boost::contract::old_value_copy<V></computeroutput>. A non-copyable old value type <computeroutput>W</computeroutput> generates a compile-time error when <computeroutput>boost::contract::old_ptr<W></computeroutput> is dereferenced, but instead leaves <computeroutput>boost::contract::old_ptr_if_copyable<W></computeroutput> always null (without generating compile-time errors).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.old_value_requirements__templates_">
1372 Old Value Requirements</link> </para>
1374 </para></description></struct><class name="old_pointer"><purpose>Convert old value copies into old value pointers. </purpose><description><para>This class is usually only implicitly used by this library and it does not explicitly appear in user code (that is why this class does not have public constructors, etc.). </para></description><method-group name="public member functions">
1375 <method name="conversion-operator"><type>old_ptr_if_copyable< T ></type><template>
1376 <template-type-parameter name="T"><purpose><para>Type of the pointed old value. The old value pointer will always be null if this type is not copyable (see <computeroutput><classname alt="boost::contract::is_old_value_copyable">boost::contract::is_old_value_copyable</classname></computeroutput>), but this library will not generate a compile-time error. </para></purpose></template-type-parameter>
1377 </template><purpose>Convert this object to an actual old value pointer for which the old value type <computeroutput>T</computeroutput> might or not be copyable. </purpose><description><para>For example, this is implicitly called when assigning or initializing old value pointers of type <computeroutput><classname alt="boost::contract::old_ptr_if_copyable">boost::contract::old_ptr_if_copyable</classname></computeroutput>.</para><para>
1378 </para></description></method>
1379 <method name="conversion-operator"><type>old_ptr< T ></type><template>
1380 <template-type-parameter name="T"><purpose><para>Type of the pointed old value. This type must be copyable (see <computeroutput><classname alt="boost::contract::is_old_value_copyable">boost::contract::is_old_value_copyable</classname></computeroutput>), otherwise this library will generate a compile-time error when the old value pointer is dereferenced. </para></purpose></template-type-parameter>
1381 </template><purpose>Convert this object to an actual old value pointer for which the old value type <computeroutput>T</computeroutput> must be copyable. </purpose><description><para>For example, this is implicitly called when assigning or initializing old value pointers of type <computeroutput><classname alt="boost::contract::old_ptr">boost::contract::old_ptr</classname></computeroutput>.</para><para>
1382 </para></description></method>
1384 </class><class name="old_ptr"><template>
1385 <template-type-parameter name="T"><purpose><para>Type of the pointed old value. This type must be copyable (i.e., <computeroutput>boost::contract::is_old_value_copyable<T>::value</computeroutput> must be <computeroutput>true</computeroutput>), otherwise this pointer will always be null and this library will generate a compile-time error when the pointer is dereferenced. </para></purpose></template-type-parameter>
1386 </template><purpose>Old value pointer that requires the pointed old value type to be copyable. </purpose><description><para>This pointer can be set to point an actual old value copy using either <computeroutput><macroname alt="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</macroname></computeroutput> or <computeroutput><functionname alt="boost::contract::make_old">boost::contract::make_old</functionname></computeroutput> (that is why this class does not have public non-default constructors):</para><para><programlisting language="c++">class u {
1388 virtual void f(..., boost::contract::virtual_* v = 0) {
1389 boost::contract::old_ptr<old_type> old_var = // For copyable `old_type`.
1390 BOOST_CONTRACT_OLDOF(v, old_expr);
1396 </programlisting></para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.old_values"> Old Values</link></para>
1399 </para></description><typedef name="element_type"><purpose>Pointed old value type. </purpose><type>T</type></typedef>
1400 <method-group name="public member functions">
1401 <method name="operator *" cv="const"><type>T const &</type><purpose>Dereference this old value pointer. </purpose><description><para>This will generate a run-time error if this pointer is null and a compile-time error if the pointed type <computeroutput>T</computeroutput> is not copyable (i.e., if <computeroutput>boost::contract::is_old_value_copyable<T>::value</computeroutput> is <computeroutput>false</computeroutput>).</para><para>
1402 </para></description><returns><para>The pointed old value. Contract assertions should not change the state of the program so this member function is <computeroutput>const</computeroutput> and it returns the old value as a reference to a constant object (see <link linkend="boost_contract.contract_programming_overview.constant_correctness">
1403 Constant Correctness</link>). </para>
1405 <method name="operator->" cv="const"><type>T const *</type><purpose>Structure-dereference this old value pointer. </purpose><description><para>This will generate a compile-time error if the pointed type <computeroutput>T</computeroutput> is not copyable (i.e., if <computeroutput>boost::contract::is_old_value_copyable<T>::value</computeroutput> is <computeroutput>false</computeroutput>).</para><para>
1406 </para></description><returns><para>A pointer to the old value (null if this old value pointer is null). Contract assertions should not change the state of the program so this member function is <computeroutput>const</computeroutput> and it returns the old value as a pointer to a constant object (see <link linkend="boost_contract.contract_programming_overview.constant_correctness">
1407 Constant Correctness</link>). </para>
1409 <method name="conversion-operator" cv="const" specifiers="explicit"><type>bool</type><purpose>Query if this old value pointer is null or not (safe-bool operator). </purpose><description><para>(This is implemented using safe-bool emulation on compilers that do not support C++11 explicit type conversion operators.)</para><para>
1410 </para></description><returns><para>True if this pointer is not null, false otherwise. </para>
1413 <constructor><purpose>Construct this old value pointer as null. </purpose></constructor>
1414 </class><class name="old_ptr_if_copyable"><template>
1415 <template-type-parameter name="T"><purpose><para>Type of the pointed old value. If this type is not copyable (i.e., <computeroutput>boost::contract::is_old_value_copyable<T>::value</computeroutput> is <computeroutput>false</computeroutput>), this pointer will always be null (but this library will not generate a compile-time error when this pointer is dereferenced). </para></purpose></template-type-parameter>
1416 </template><purpose>Old value pointer that does not require the pointed old value type to be copyable. </purpose><description><para>This pointer can be set to point to an actual old value copy using either <computeroutput><macroname alt="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</macroname></computeroutput> or <computeroutput><functionname alt="boost::contract::make_old">boost::contract::make_old</functionname></computeroutput>:</para><para><programlisting language="c++">template<typename T> // Type `T` might or not be copyable.
1419 virtual void f(..., boost::contract::virtual_* v = 0) {
1420 boost::contract::old_ptr_if_copyable<T> old_var =
1421 BOOST_CONTRACT_OLDOF(v, old_expr);
1423 if(old_var) ... // Always null for non-copyable types.
1429 </programlisting></para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.old_value_requirements__templates_">
1430 Old Value Requirements</link></para>
1433 </para></description><typedef name="element_type"><purpose>Pointed old value type. </purpose><type>T</type></typedef>
1434 <method-group name="public member functions">
1435 <method name="operator *" cv="const"><type>T const &</type><purpose>Dereference this old value pointer. </purpose><description><para>This will generate a run-time error if this pointer is null, but no compile-time error is generated if the pointed type <computeroutput>T</computeroutput> is not copyable (i.e., if <computeroutput>boost::contract::is_old_value_copyable<T>::value</computeroutput> is <computeroutput>false</computeroutput>).</para><para>
1436 </para></description><returns><para>The pointed old value. Contract assertions should not change the state of the program so this member function is <computeroutput>const</computeroutput> and it returns the old value as a reference to a constant object (see <link linkend="boost_contract.contract_programming_overview.constant_correctness">
1437 Constant Correctness</link>). </para>
1439 <method name="operator->" cv="const"><type>T const *</type><purpose>Structure-dereference this old value pointer. </purpose><description><para>This will return null but will not generate a compile-time error if the pointed type <computeroutput>T</computeroutput> is not copyable (i.e., if <computeroutput>boost::contract::is_old_value_copyable<T>::value</computeroutput> is <computeroutput>false</computeroutput>).</para><para>
1440 </para></description><returns><para>A pointer to the old value (null if this old value pointer is null). Contract assertions should not change the state of the program so this member function is <computeroutput>const</computeroutput> and it returns the old value as a pointer to a constant object (see <link linkend="boost_contract.contract_programming_overview.constant_correctness">
1441 Constant Correctness</link>). </para>
1443 <method name="conversion-operator" cv="const" specifiers="explicit"><type>bool</type><purpose>Query if this old value pointer is null or not (safe-bool operator). </purpose><description><para>(This is implemented using safe-bool emulation on compilers that do not support C++11 explicit type conversion operators.)</para><para>
1444 </para></description><returns><para>True if this pointer is not null, false otherwise. </para>
1447 <constructor><purpose>Construct this old value pointer as null. </purpose></constructor>
1448 <constructor><parameter name="other"><paramtype><classname>old_ptr</classname>< T > const &</paramtype><description><para>Old value pointer that requires the old value type to be copyable. </para></description></parameter><purpose>Construct this old value pointer from an old value pointer that requires the old value type to be copyable. </purpose><description><para>Ownership of the pointed value object is transferred to this pointer. This constructor is implicitly called by this library when assigning an object of this type using <computeroutput><macroname alt="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</macroname></computeroutput> (this constructor is usually not explicitly called by user code).</para><para>
1449 </para></description></constructor>
1450 </class><class name="old_value"><purpose>Convert user-specified expressions to old values. </purpose><description><para>This class is usually only implicitly used by this library and it does not explicitly appear in user code.</para><para>On older compilers that cannot correctly deduce the <computeroutput><classname alt="boost::contract::is_old_value_copyable">boost::contract::is_old_value_copyable</classname></computeroutput> trait used in the declaration of this class, programmers can manually specialize that trait to make sure that only old value types that are copyable are actually copied.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.old_value_requirements__templates_">
1451 Old Value Requirements</link> </para>
1453 </para></description><method-group name="public member functions">
1455 <constructor><template>
1456 <template-type-parameter name="T"><purpose><para>Old value type. </para></purpose></template-type-parameter>
1457 </template><parameter name="old"><paramtype>T const &</paramtype><description><para>Old value to be copied.</para></description></parameter><parameter name=""><paramtype>typename boost::enable_if< <classname>boost::contract::is_old_value_copyable</classname>< T > >::type *</paramtype><default>0</default></parameter><purpose>Construct this object from the specified old value when the old value type is copy constructible. </purpose><description><para>The specified old value <computeroutput>old</computeroutput> is copied (one time only) using <computeroutput><classname alt="boost::contract::old_value_copy">boost::contract::old_value_copy</classname></computeroutput>, in which case the related old value pointer will not be null (but no copy is made if postconditions and exception guarantees are not being checked, see <computeroutput><macroname alt="BOOST_CONTRACT_NO_OLDS">BOOST_CONTRACT_NO_OLDS</macroname></computeroutput>).</para><para>
1459 </para></description></constructor>
1460 <constructor><template>
1461 <template-type-parameter name="T"><purpose><para>Old value type. </para></purpose></template-type-parameter>
1462 </template><parameter name="old"><paramtype>T const &</paramtype><description><para>Old value (that will not be copied in this case).</para></description></parameter><parameter name=""><paramtype>typename boost::disable_if< <classname>boost::contract::is_old_value_copyable</classname>< T > >::type *</paramtype><default>0</default></parameter><purpose>Construct this object from the specified old value when the old value type is not copyable. </purpose><description><para>The specified old value <computeroutput>old</computeroutput> cannot be copied in this case so it is not copied and the related old value pointer will always be null (thus calls to this constructor have no effect and they will likely be optimized away by most compilers).</para><para>
1464 </para></description></constructor>
1465 </class><struct name="old_value_copy"><template>
1466 <template-type-parameter name="T"/>
1467 </template><purpose>Trait to copy an old value. </purpose><description><para>By default, the implementation of this trait uses <computeroutput>T's</computeroutput> copy constructor to make one single copy of the specified value. However, programmers can specialize this trait to copy old values using user-specific operations different from <computeroutput>T's</computeroutput> copy constructor. The default implementation of this trait is equivalent to:</para><para><programlisting language="c++">template<typename T>
1468 class old_value_copy {
1470 explicit old_value_copy(T const& old) :
1471 old_(old) // One single copy of value using T's copy constructor.
1474 T const& old() const { return old_; }
1477 T const old_; // The old value copy.
1479 </programlisting></para><para>This library will instantiate and use this trait only on old value types <computeroutput>T</computeroutput> that are copyable (i.e., for which <computeroutput>boost::contract::is_old_value_copyable<T>::value</computeroutput> is <computeroutput>true</computeroutput>).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.old_value_requirements__templates_">
1480 Old Value Requirements</link> </para>
1482 </para></description><method-group name="public member functions">
1483 <method name="old" cv="const"><type>T const &</type><purpose>Return a (constant) reference to the old value that was copied. </purpose><description><para>Contract assertions should not change the state of the program so the old value copy is returned as <computeroutput>const</computeroutput> (see <link linkend="boost_contract.contract_programming_overview.constant_correctness">
1484 Constant Correctness</link>). </para></description></method>
1486 <constructor specifiers="explicit"><parameter name="old"><paramtype>T const &</paramtype><description><para>The old value to copy. </para></description></parameter><purpose>Construct this object by making one single copy of the specified old value. </purpose><description><para>This is the only operation within this library that actually copies old values. This ensures this library makes one and only one copy of an old value (if they actually need to be copied, see <computeroutput><macroname alt="BOOST_CONTRACT_NO_OLDS">BOOST_CONTRACT_NO_OLDS</macroname></computeroutput>).</para><para>
1487 </para></description></constructor>
1495 <function name="null_old"><type><classname>old_value</classname></type><purpose>Return a "null" old value. </purpose><description><para>The related old value pointer will also be null. This function is usually only called by the code expanded by <computeroutput><macroname alt="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</macroname></computeroutput>.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_"> No Macros</link></para>
1498 </para></description><returns><para>Null old value. </para>
1499 </returns></function>
1500 <function name="make_old"><type><classname>old_pointer</classname></type><parameter name="old"><paramtype><classname>old_value</classname> const &</paramtype><description><para>Old value which is usually implicitly constructed from the user old value expression to be copied (use the ternary operator <computeroutput>?:</computeroutput> to completely avoid to evaluate the old value expression when <computeroutput>boost::contract::copy_old()</computeroutput> is <computeroutput>false</computeroutput>).</para></description></parameter><purpose>Make an old value pointer (but not for virtual public functions and public functions overrides). </purpose><description><para>The related old value pointer will not be null if the specified old value was actually copied. This function is usually only called by code expanded by <computeroutput>BOOST_CONTRACT_OLDOF(old_expr)</computeroutput> as in:</para><para><programlisting language="c++">boost::contract::make_old(boost::contract::copy_old() ? old_expr :
1501 boost::contract::null_old())
1502 </programlisting></para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_"> No Macros</link></para>
1506 </para></description><returns><para>Old value pointer (usually implicitly converted to either <computeroutput><classname alt="boost::contract::old_ptr">boost::contract::old_ptr</classname></computeroutput> or <computeroutput><classname alt="boost::contract::old_ptr_if_copyable">boost::contract::old_ptr_if_copyable</classname></computeroutput> in user code). </para>
1507 </returns></function>
1508 <function name="make_old"><type><classname>old_pointer</classname></type><parameter name="v"><paramtype><classname>virtual_</classname> *</paramtype><description><para>The trailing parameter of type <computeroutput><classname alt="boost::contract::virtual_">boost::contract::virtual_</classname></computeroutput><computeroutput>*</computeroutput> and default value <computeroutput>0</computeroutput> from the enclosing virtual or overriding public function declaring the contract. </para></description></parameter><parameter name="old"><paramtype><classname>old_value</classname> const &</paramtype><description><para>Old value which is usually implicitly constructed from the user old value expression to be copied (use the ternary operator <computeroutput>?:</computeroutput> to completely avoid to evaluate the old value expression when <computeroutput>boost::contract::copy_old(v)</computeroutput> is <computeroutput>false</computeroutput>).</para></description></parameter><purpose>Make an old value pointer (for virtual public functions and public functions overrides). </purpose><description><para>The related old value pointer will not be null if the specified old value was actually copied. This function is usually only called by code expanded by <computeroutput>BOOST_CONTRACT_OLDOF(v, old_expr)</computeroutput> as in:</para><para><programlisting language="c++">boost::contract::make_old(v, boost::contract::copy_old(v) ? old_expr :
1509 boost::contract::null_old())
1510 </programlisting></para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_"> No Macros</link></para>
1514 </para></description><returns><para>Old value pointer (usually implicitly converted to either <computeroutput><classname alt="boost::contract::old_ptr">boost::contract::old_ptr</classname></computeroutput> or <computeroutput><classname alt="boost::contract::old_ptr_if_copyable">boost::contract::old_ptr_if_copyable</classname></computeroutput> in user code). </para>
1515 </returns></function>
1516 <function name="copy_old"><type>bool</type><purpose>Query if old values need to be copied (but not for virtual public functions and public function overrides). </purpose><description><para>For example, this function always returns false when both postconditions and exception guarantees are not being checked (see <computeroutput><macroname alt="BOOST_CONTRACT_NO_OLDS">BOOST_CONTRACT_NO_OLDS</macroname></computeroutput>). This function is usually only called by the code expanded by <computeroutput><macroname alt="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</macroname></computeroutput>.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_"> No Macros</link></para>
1519 </para></description><returns><para>True if old values need to be copied, false otherwise. </para>
1520 </returns></function>
1521 <function name="copy_old"><type>bool</type><parameter name="v"><paramtype><classname>virtual_</classname> *</paramtype><description><para>The trailing parameter of type <computeroutput><classname alt="boost::contract::virtual_">boost::contract::virtual_</classname></computeroutput><computeroutput>*</computeroutput> and default value <computeroutput>0</computeroutput> from the enclosing virtual or overriding public function declaring the contract.</para></description></parameter><purpose>Query if old values need to be copied (for virtual public functions and public function overrides). </purpose><description><para>For example, this function always returns false when both postconditions and exception guarantees are not being checked (see <computeroutput><macroname alt="BOOST_CONTRACT_NO_OLDS">BOOST_CONTRACT_NO_OLDS</macroname></computeroutput>). In addition, this function returns false when overridden functions are being called subsequent times by this library to support subcontracting. This function is usually only called by the code expanded by <computeroutput><macroname alt="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</macroname></computeroutput>.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_"> No Macros</link></para>
1525 </para></description><returns><para>True if old values need to be copied, false otherwise. </para>
1526 </returns></function>
1557 <macro name="BOOST_CONTRACT_OLDOF" kind="functionlike"><macro-parameter name="..."/><purpose>Macro typically used to copy an old value expression and assign it to an old value pointer. </purpose><description><para>The expression expanded by this macro should be assigned to an old value pointer of type <computeroutput><classname alt="boost::contract::old_ptr">boost::contract::old_ptr</classname></computeroutput> or <computeroutput><classname alt="boost::contract::old_ptr_if_copyable">boost::contract::old_ptr_if_copyable</classname></computeroutput>. This is an overloaded variadic macro and it can be used in the following different ways.</para><para>1. From within virtual public functions and public functions overrides:</para><para><programlisting language="c++">BOOST_CONTRACT_OLDOF(v, old_expr)
1558 </programlisting></para><para>2. From all other operations:</para><para><programlisting language="c++">BOOST_CONTRACT_OLDOF(old_expr)
1559 </programlisting></para><para>Where:</para><para><itemizedlist>
1560 <listitem><para><computeroutput><emphasis role="bold">v</emphasis></computeroutput> is the extra parameter of type <computeroutput><classname alt="boost::contract::virtual_">boost::contract::virtual_</classname></computeroutput><computeroutput>*</computeroutput> and default value <computeroutput>0</computeroutput> from the enclosing virtual public function or public function overrides declaring the contract. </para>
1562 <listitem><para><computeroutput><emphasis role="bold">old_expr</emphasis></computeroutput> is the expression to be evaluated and copied into the old value pointer. (This is not a variadic macro parameter so any comma it might contain must be protected by round parenthesis and <computeroutput>BOOST_CONTRACT_OLDOF(v, (old_expr))</computeroutput> will always work.)</para>
1565 On compilers that do not support variadic macros, programmers can manually copy old value expressions without using this macro (see <link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_"> No Macros</link>).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.old_values"> Old Values</link> </para>
1567 </para></description></macro>
1569 <header name="boost/contract/override.hpp">
1570 <para>Handle public function overrides (for subcontracting). </para><macro name="BOOST_CONTRACT_NAMED_OVERRIDE" kind="functionlike"><macro-parameter name="type_name"><description><para>Name of the override type trait this macro will declare. (This is not a variadic macro parameter but it should never contain commas because it is an identifier.) </para></description></macro-parameter><macro-parameter name="func_name"><description><para>Function name of the public function override. This macro is called just once even if the function name is overloaded (the same override type trait is used for all overloaded functions with the same name, see <link linkend="boost_contract.advanced.function_overloads">
1571 Function Overloads</link>). (This is not a variadic macro parameter but it should never contain commas because it is an identifier.) </para></description></macro-parameter><purpose>Declare an override type trait with an arbitrary name. </purpose><description><para>Declare the override type trait named <computeroutput>type_name</computeroutput> to pass as an explicit template parameter to <computeroutput><functionname alt="boost::contract::public_function">boost::contract::public_function</functionname></computeroutput> for public function overrides.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.named_overrides"> Named Overrides</link></para>
1574 </para></description></macro>
1575 <macro name="BOOST_CONTRACT_OVERRIDE" kind="functionlike"><macro-parameter name="func_name"><description><para>Function name of the public function override. This macro is called just once even if the function name is overloaded (the same override type trait is used for all overloaded functions with the same name, see <link linkend="boost_contract.advanced.function_overloads"> Function Overloads</link>). (This is not a variadic macro parameter but it should never contain any comma because it is an identifier.) </para></description></macro-parameter><purpose>Declare an override type trait named <computeroutput>override_<emphasis>func_name</emphasis></computeroutput>. </purpose><description><para>Declare the override type trait named <computeroutput>override_<emphasis>func_name</emphasis></computeroutput> to pass as an explicit template parameter to <computeroutput><functionname alt="boost::contract::public_function">boost::contract::public_function</functionname></computeroutput> for public function overrides. Use <computeroutput><macroname alt="BOOST_CONTRACT_NAMED_OVERRIDE">BOOST_CONTRACT_NAMED_OVERRIDE</macroname></computeroutput> to generate an override type trait with a name different than <computeroutput>override_<emphasis>func_name</emphasis></computeroutput> (usually not needed).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.public_function_overrides__subcontracting_">
1576 Public Function Overrides</link></para>
1579 </para></description></macro>
1580 <macro name="BOOST_CONTRACT_OVERRIDES" kind="functionlike"><macro-parameter name="..."><description><para>A comma separated list of one or more function names of public function overrides. (Each function name should never contain commas because it is an identifier.) </para></description></macro-parameter><purpose>Declare multiple override type traits at once naming them <computeroutput>override_...</computeroutput> (for convenience). </purpose><description><para>This variadic macro is provided for convenience as <computeroutput>BOOST_CONTRACT_OVERRIDES(f_1, f_2, ..., f_n)</computeroutput> expands to code equivalent to:</para><para><programlisting language="c++">BOOST_CONTRACT_OVERRIDE(f_1)
1581 BOOST_CONTRACT_OVERRIDE(f_2)
1583 BOOST_CONTRACT_OVERRIDE(f_n)
1584 </programlisting></para><para>On compilers that do not support variadic macros, the override type traits can be equivalently programmed one-by-one calling <computeroutput><macroname alt="BOOST_CONTRACT_OVERRIDE">BOOST_CONTRACT_OVERRIDE</macroname></computeroutput> for each function name as shown above.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.public_function_overrides__subcontracting_">
1585 Public Function Overrides</link></para>
1588 </para></description></macro>
1590 <header name="boost/contract/public_function.hpp">
1591 <para>Program contracts for public functions (including subcontracting). </para><para>The different overloads handle public functions that are static, virtual void, virtual non-void, overriding void, and overriding non-void. </para><namespace name="boost">
1592 <namespace name="contract">
1605 <function name="public_function"><type><classname>specify_precondition_old_postcondition_except</classname></type><template>
1606 <template-type-parameter name="Class"><purpose><para>The type of the class containing the static public function declaring the contract. This template parameter must be explicitly specified for static public functions (because they have no object <computeroutput>this</computeroutput> so there is no function argument from which this type template parameter can be automatically deduced by C++).</para></purpose></template-type-parameter>
1607 </template><purpose>Program contracts for static public functions. </purpose><description><para>This is used to specify preconditions, postconditions, exception guarantees, old value copies at body, and check static class invariants for static public functions:</para><para><programlisting language="c++">class u {
1608 friend class boost::contract::access;
1610 static void static_invariant() { // Optional (as for non-static).
1611 BOOST_CONTRACT_ASSERT(...);
1616 static void f(...) {
1617 boost::contract::old_ptr<old_type> old_var;
1618 boost::contract::check c = boost::contract::public_function<u>()
1619 .precondition([&] { // Optional.
1620 BOOST_CONTRACT_ASSERT(...);
1623 .old([&] { // Optional.
1624 old_var = BOOST_CONTRACT_OLDOF(old_expr);
1627 .postcondition([&] { // Optional.
1628 BOOST_CONTRACT_ASSERT(...);
1631 .except([&] { // Optional.
1632 BOOST_CONTRACT_ASSERT(...);
1637 ... // Function body.
1642 </programlisting></para><para>For optimization, this can be omitted for static public functions that do not have preconditions, postconditions and exception guarantees, within classes that have no static invariants.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.static_public_functions"> Static Public Functions</link></para>
1646 </para></description><returns><para>The result of this function must be assigned to a variable of type <computeroutput><classname alt="boost::contract::check">boost::contract::check</classname></computeroutput> declared explicitly (i.e., without using C++11 <computeroutput>auto</computeroutput> declarations) and locally just before the code of the static public function body (otherwise this library will generate a run-time error, see <computeroutput><macroname alt="BOOST_CONTRACT_ON_MISSING_CHECK_DECL">BOOST_CONTRACT_ON_MISSING_CHECK_DECL</macroname></computeroutput>). </para>
1647 </returns></function>
1648 <function name="public_function"><type><classname>specify_precondition_old_postcondition_except</classname></type><template>
1649 <template-type-parameter name="Class"><purpose><para>The type of the class containing the public function declaring the contract. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.)</para></purpose></template-type-parameter>
1650 </template><parameter name="obj"><paramtype>Class *</paramtype><description><para>The object <computeroutput>this</computeroutput> from the scope of the enclosing public function declaring the contract. This object might be mutable, <computeroutput>const</computeroutput>, <computeroutput>volatile</computeroutput>, or <computeroutput>const volatile</computeroutput> depending on the cv-qualifier of the enclosing function (volatile public functions will check volatile class invariants, see <link linkend="boost_contract.extras.volatile_public_functions">
1651 Volatile Public Functions</link>).</para></description></parameter><purpose>Program contracts for public functions that are not static, not virtual, and do not not override. </purpose><description><para>This is used to specify preconditions, postconditions, exception guarantees, old value copies at body, and check class invariants for public functions that are not static, not virtual, and do not override:</para><para><programlisting language="c++">class u {
1652 friend class boost::contract::access;
1654 void invariant() const { // Optional (as for static and volatile).
1655 BOOST_CONTRACT_ASSERT(...);
1661 boost::contract::old_ptr<old_type> old_var;
1662 boost::contract::check c = boost::contract::public_function(this)
1663 .precondition([&] { // Optional.
1664 BOOST_CONTRACT_ASSERT(...);
1667 .old([&] { // Optional.
1668 old_var = BOOST_CONTRACT_OLDOF(old_expr);
1671 .postcondition([&] { // Optional.
1672 BOOST_CONTRACT_ASSERT(...);
1675 .except([&] { // Optional.
1676 BOOST_CONTRACT_ASSERT(...);
1681 ... // Function body.
1686 </programlisting></para><para>For optimization, this can be omitted for public functions that do not have preconditions, postconditions and exception guarantees, within classes that have no invariants.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.public_functions"> Public Functions</link></para>
1691 </para></description><returns><para>The result of this function must be assigned to a variable of type <computeroutput><classname alt="boost::contract::check">boost::contract::check</classname></computeroutput> declared explicitly (i.e., without using C++11 <computeroutput>auto</computeroutput> declarations) and locally just before the code of the public function body (otherwise this library will generate a run-time error, see <computeroutput><macroname alt="BOOST_CONTRACT_ON_MISSING_CHECK_DECL">BOOST_CONTRACT_ON_MISSING_CHECK_DECL</macroname></computeroutput>). </para>
1692 </returns></function>
1693 <function name="public_function"><type><classname>specify_precondition_old_postcondition_except</classname></type><template>
1694 <template-type-parameter name="Class"><purpose><para>The type of the class containing the virtual public function declaring the contract. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.)</para></purpose></template-type-parameter>
1695 </template><parameter name="v"><paramtype><classname>virtual_</classname> *</paramtype><description><para>The trailing parameter of type <computeroutput><classname alt="boost::contract::virtual_">boost::contract::virtual_</classname></computeroutput><computeroutput>*</computeroutput> and default value <computeroutput>0</computeroutput> from the enclosing virtual public function. </para></description></parameter><parameter name="obj"><paramtype>Class *</paramtype><description><para>The object <computeroutput>this</computeroutput> from the scope of the enclosing virtual public function declaring the contract. This object might be mutable, <computeroutput>const</computeroutput>, <computeroutput>volatile</computeroutput>, or <computeroutput>const volatile</computeroutput> depending on the cv-qualifier of the enclosing function (volatile public functions will check volatile class invariants, see <link linkend="boost_contract.extras.volatile_public_functions">
1696 Volatile Public Functions</link>).</para></description></parameter><purpose>Program contracts for void virtual public functions that do not override. </purpose><description><para>This is used to specify preconditions, postconditions, exception guarantees, old value copies at body, and check class invariants for public functions that are virtual, do not override, and return <computeroutput>void:</computeroutput> </para><para><programlisting language="c++">class u {
1697 friend class boost::contract::access;
1699 void invariant() const { // Optional (as for static and volatile).
1700 BOOST_CONTRACT_ASSERT(...);
1705 void f(..., boost::contract::virtual_* v = 0) {
1706 boost::contract::old_ptr<old_type> old_var;
1707 boost::contract::check c = boost::contract::public_function(v, this)
1708 .precondition([&] { // Optional.
1709 BOOST_CONTRACT_ASSERT(...);
1712 .old([&] { // Optional.
1713 old_var = BOOST_CONTRACT_OLDOF(v, old_expr);
1716 .postcondition([&] { // Optional.
1717 BOOST_CONTRACT_ASSERT(...);
1720 .except([&] { // Optional.
1721 BOOST_CONTRACT_ASSERT(...);
1726 ... // Function body.
1731 </programlisting></para><para>A virtual public function should always call <computeroutput><functionname alt="boost::contract::public_function">boost::contract::public_function</functionname></computeroutput> otherwise this library will not be able to correctly use it for subcontracting.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.virtual_public_functions"> Virtual Public Functions</link></para>
1736 </para></description><returns><para>The result of this function must be assigned to a variable of type <computeroutput><classname alt="boost::contract::check">boost::contract::check</classname></computeroutput> declared explicitly (i.e., without using C++11 <computeroutput>auto</computeroutput> declarations) and locally just before the code of the public function body (otherwise this library will generate a run-time error, see <computeroutput><macroname alt="BOOST_CONTRACT_ON_MISSING_CHECK_DECL">BOOST_CONTRACT_ON_MISSING_CHECK_DECL</macroname></computeroutput>). </para>
1737 </returns></function>
1738 <function name="public_function"><type><classname>specify_precondition_old_postcondition_except</classname>< VirtualResult ></type><template>
1739 <template-type-parameter name="VirtualResult"><purpose><para>This type must be the same as, or compatible with, the return type of the enclosing virtual public function declaring the contract (this library might not be able to generate a compile-time error if these types mismatch, but in general that will cause run-time errors or undefined behaviour). Alternatively, <computeroutput>boost::optional<<emphasis>return-type</emphasis>></computeroutput> can also be used (see <link linkend="boost_contract.advanced.optional_return_values">
1740 Optional Return Values</link>). (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.) </para></purpose></template-type-parameter>
1741 <template-type-parameter name="Class"><purpose><para>The type of the class containing the virtual public function declaring the contract. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.)</para></purpose></template-type-parameter>
1742 </template><parameter name="v"><paramtype><classname>virtual_</classname> *</paramtype><description><para>The trailing parameter of type <computeroutput><classname alt="boost::contract::virtual_">boost::contract::virtual_</classname></computeroutput><computeroutput>*</computeroutput> and default value <computeroutput>0</computeroutput> from the enclosing virtual public function. </para></description></parameter><parameter name="r"><paramtype>VirtualResult &</paramtype><description><para>A reference to the return value of the enclosing virtual public function declaring the contract. This is usually a local variable declared by the enclosing virtual public function just before the contract, but programmers must set it to the actual value being returned by the function at each <computeroutput>return</computeroutput> statement. </para></description></parameter><parameter name="obj"><paramtype>Class *</paramtype><description><para>The object <computeroutput>this</computeroutput> from the scope of the enclosing virtual public function declaring the contract. This object might be mutable, <computeroutput>const</computeroutput>, <computeroutput>volatile</computeroutput>, or <computeroutput>const volatile</computeroutput> depending on the cv-qualifier of the enclosing function (volatile public functions will check volatile class invariants, see <link linkend="boost_contract.extras.volatile_public_functions">
1743 Volatile Public Functions</link>).</para></description></parameter><purpose>Program contracts for non-void virtual public functions that do not override. </purpose><description><para>This is used to specify preconditions, postconditions, exception guarantees, old value copies at body, and check class invariants for public functions that are virtual, do not override, and do not return <computeroutput>void:</computeroutput> </para><para><programlisting language="c++">class u {
1744 friend class boost::contract::access;
1746 void invariant() const { // Optional (as for static and volatile).
1747 BOOST_CONTRACT_ASSERT(...);
1752 t f(..., boost::contract::virtual_* v = 0) {
1754 boost::contract::old_ptr<old_type> old_var;
1755 boost::contract::check c = boost::contract::public_function(
1757 .precondition([&] { // Optional.
1758 BOOST_CONTRACT_ASSERT(...);
1761 .old([&] { // Optional.
1762 old_var = BOOST_CONTRACT_OLDOF(v, old_expr);
1765 .postcondition([&] (t const& result) { // Optional.
1766 BOOST_CONTRACT_ASSERT(...);
1769 .except([&] { // Optional.
1770 BOOST_CONTRACT_ASSERT(...);
1775 ... // Function body (use `return result = return_expr`).
1780 </programlisting></para><para>A virtual public function should always call <computeroutput><functionname alt="boost::contract::public_function">boost::contract::public_function</functionname></computeroutput> otherwise this library will not be able to correctly use it for subcontracting.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.virtual_public_functions"> Virtual Public Functions</link></para>
1785 </para></description><returns><para>The result of this function must be assigned to a variable of type <computeroutput><classname alt="boost::contract::check">boost::contract::check</classname></computeroutput> declared explicitly (i.e., without using C++11 <computeroutput>auto</computeroutput> declarations) and locally just before the code of the public function body (otherwise this library will generate a run-time error, see <computeroutput><macroname alt="BOOST_CONTRACT_ON_MISSING_CHECK_DECL">BOOST_CONTRACT_ON_MISSING_CHECK_DECL</macroname></computeroutput>). </para>
1786 </returns></function>
1787 <function name="public_function"><type><classname>specify_precondition_old_postcondition_except</classname></type><template>
1788 <template-type-parameter name="Override"><purpose><para>The type trait <computeroutput>override_<emphasis>function-name</emphasis></computeroutput> declared using the <computeroutput><macroname alt="BOOST_CONTRACT_OVERRIDE">BOOST_CONTRACT_OVERRIDE</macroname></computeroutput> or related macros. This template parameter must be explicitly specified (because there is no function argument from which it can be automatically deduced by C++). </para></purpose></template-type-parameter>
1789 <template-type-parameter name="F"><purpose><para>The function pointer type of the enclosing public function override declaring the contract. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.) </para></purpose></template-type-parameter>
1790 <template-type-parameter name="Class"><purpose><para>The type of the class containing the virtual public function declaring the contract. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.) </para></purpose></template-type-parameter>
1791 <template-nontype-parameter name="Args"><type>typename...</type><purpose><para>The types of all parameters passed to the enclosing public function override declaring the contract, but excluding the trailing parameter type <computeroutput><classname alt="boost::contract::virtual_">boost::contract::virtual_</classname>*</computeroutput>. On compilers that do not support variadic templates, this library internally implements this function using preprocessor meta-programming (in this case, the maximum number of supported arguments is defined by <computeroutput><macroname alt="BOOST_CONTRACT_MAX_ARGS">BOOST_CONTRACT_MAX_ARGS</macroname></computeroutput>). (Usually these template parameters are automatically deduced by C++ and they do not need to be explicitly specified by programmers.)</para></purpose></template-nontype-parameter>
1792 </template><parameter name="v"><paramtype><classname>virtual_</classname> *</paramtype><description><para>The trailing parameter of type <computeroutput><classname alt="boost::contract::virtual_">boost::contract::virtual_</classname></computeroutput><computeroutput>*</computeroutput> and default value <computeroutput>0</computeroutput> from the enclosing public function override. </para></description></parameter><parameter name="f"><paramtype>F</paramtype><description><para>A pointer to the enclosing public function override declaring the contract (but see <link linkend="boost_contract.advanced.function_overloads">
1793 Function Overloads</link>). </para></description></parameter><parameter name="obj"><paramtype>Class *</paramtype><description><para>The object <computeroutput>this</computeroutput> from the scope of the enclosing public function override declaring the contract. This object might be mutable, <computeroutput>const</computeroutput>, <computeroutput>volatile</computeroutput>, or <computeroutput>const volatile</computeroutput> depending on the cv-qualifier of the enclosing function (volatile public functions will check volatile class invariants, see <link linkend="boost_contract.extras.volatile_public_functions">
1794 Volatile Public Functions</link>). </para></description></parameter><parameter name="args"><paramtype>Args &...</paramtype><description><para>All arguments passed to the enclosing public function override declaring the contract (by reference and in the order they appear in the enclosing function declaration), but excluding the trailing argument <computeroutput>v</computeroutput>.</para></description></parameter><purpose>Program contracts for void public functions overrides (virtual or not). </purpose><description><para>This is used to specify preconditions, postconditions, exception guarantees, old value copies at body, and check class invariants for public function overrides (virtual or not) that return <computeroutput>void:</computeroutput> </para><para><programlisting language="c++">class u
1795 #define BASES private boost::contract::constructor_precondition<u>, \
1799 friend class boost::contract::access;
1801 typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types;
1804 void invariant() const { // Optional (as for static and volatile).
1805 BOOST_CONTRACT_ASSERT(...);
1809 BOOST_CONTRACT_OVERRIDES(f)
1812 // Override from `b::f`.
1813 void f(t_1 a_1, ..., t_n a_n, boost::contract::virtual_* v = 0) {
1814 boost::contract::old_ptr<old_type> old_var;
1815 boost::contract::check c = boost::contract::public_function<
1816 override_f>(v, &u::f, this, a_1, ..., a_n)
1817 .precondition([&] { // Optional.
1818 BOOST_CONTRACT_ASSERT(...);
1821 .old([&] { // Optional.
1822 old_var = BOOST_CONTRACT_OLDOF(v, old_expr);
1825 .postcondition([&] { // Optional.
1826 BOOST_CONTRACT_ASSERT(...);
1829 .except([&] { // Optional.
1830 BOOST_CONTRACT_ASSERT(...);
1835 ... // Function body.
1840 </programlisting></para><para>A public function override should always call <computeroutput><functionname alt="boost::contract::public_function">boost::contract::public_function</functionname></computeroutput> otherwise this library will not be able to correctly use it for subcontracting.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.public_function_overrides__subcontracting_">
1841 Public Function Overrides</link></para>
1846 </para></description><returns><para>The result of this function must be assigned to a variable of type <computeroutput><classname alt="boost::contract::check">boost::contract::check</classname></computeroutput> declared explicitly (i.e., without using C++11 <computeroutput>auto</computeroutput> declarations) and locally just before the code of the public function body (otherwise this library will generate a run-time error, see <computeroutput><macroname alt="BOOST_CONTRACT_ON_MISSING_CHECK_DECL">BOOST_CONTRACT_ON_MISSING_CHECK_DECL</macroname></computeroutput>). </para>
1847 </returns></function>
1848 <function name="public_function"><type><classname>specify_precondition_old_postcondition_except</classname>< VirtualResult ></type><template>
1849 <template-type-parameter name="Override"><purpose><para>The type trait <computeroutput>override_<emphasis>function-name</emphasis></computeroutput> declared using the <computeroutput><macroname alt="BOOST_CONTRACT_OVERRIDE">BOOST_CONTRACT_OVERRIDE</macroname></computeroutput> or related macros. This template parameter must be explicitly specified (because there is no function argument from which it can be automatically deduced by C++). </para></purpose></template-type-parameter>
1850 <template-type-parameter name="VirtualResult"><purpose><para>This type must be the same as, or compatible with, the return type of the enclosing public function override declaring the contract (this library might not be able to generate a compile-time error if these types mismatch, but in general that will cause run-time errors or undefined behaviour). Alternatively, <computeroutput>boost::optional<<emphasis>return-type</emphasis>></computeroutput> can also be used (see <link linkend="boost_contract.advanced.optional_return_values">
1851 Optional Return Values</link>). (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.) </para></purpose></template-type-parameter>
1852 <template-type-parameter name="F"><purpose><para>The function pointer type of the enclosing public function override declaring the contract. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.) </para></purpose></template-type-parameter>
1853 <template-type-parameter name="Class"><purpose><para>The type of the class containing the virtual public function declaring the contract. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.) </para></purpose></template-type-parameter>
1854 <template-nontype-parameter name="Args"><type>typename...</type><purpose><para>The types of all parameters passed to the enclosing public function override declaring the contract, but excluding the trailing parameter type <computeroutput><classname alt="boost::contract::virtual_">boost::contract::virtual_</classname>*</computeroutput>. On compilers that do not support variadic templates, this library internally implements this function using preprocessor meta-programming (in this case, the maximum number of supported arguments is defined by <computeroutput><macroname alt="BOOST_CONTRACT_MAX_ARGS">BOOST_CONTRACT_MAX_ARGS</macroname></computeroutput>). (Usually these template parameters are automatically deduced by C++ and they do not need to be explicitly specified by programmers.)</para></purpose></template-nontype-parameter>
1855 </template><parameter name="v"><paramtype><classname>virtual_</classname> *</paramtype><description><para>The trailing parameter of type <computeroutput><classname alt="boost::contract::virtual_">boost::contract::virtual_</classname></computeroutput><computeroutput>*</computeroutput> and default value <computeroutput>0</computeroutput> from the enclosing public function override. </para></description></parameter><parameter name="r"><paramtype>VirtualResult &</paramtype><description><para>A reference to the return value of the enclosing public function override declaring the contract. This is usually a local variable declared by the enclosing public function override just before the contract, but programmers must set it to the actual value being returned by the function at each <computeroutput>return</computeroutput> statement. </para></description></parameter><parameter name="f"><paramtype>F</paramtype><description><para>A pointer to the enclosing public function override declaring the contract (but see <link linkend="boost_contract.advanced.function_overloads">
1856 Function Overloads</link>). </para></description></parameter><parameter name="obj"><paramtype>Class *</paramtype><description><para>The object <computeroutput>this</computeroutput> from the scope of the enclosing public function override declaring the contract. This object might be mutable, <computeroutput>const</computeroutput>, <computeroutput>volatile</computeroutput>, or <computeroutput>const volatile</computeroutput> depending on the cv-qualifier of the enclosing function (volatile public functions will check volatile class invariants, see <link linkend="boost_contract.extras.volatile_public_functions">
1857 Volatile Public Functions</link>). </para></description></parameter><parameter name="args"><paramtype>Args &...</paramtype><description><para>All arguments passed to the enclosing public function override declaring the contract (by reference and in the order they appear in the enclosing function declaration), but excluding the trailing argument <computeroutput>v</computeroutput>.</para></description></parameter><purpose>Program contracts for non-void public functions overrides (virtual or not). </purpose><description><para>This is used to specify preconditions, postconditions, exception guarantees, old value copies at body, and check class invariants for public function overrides (virtual or not) that do not return <computeroutput>void:</computeroutput> </para><para><programlisting language="c++">class u
1858 #define BASES private boost::contract::constructor_precondition<u>, \
1862 friend class boost::contract::access;
1864 typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types;
1867 void invariant() const { // Optional (as for static and volatile).
1868 BOOST_CONTRACT_ASSERT(...);
1872 BOOST_CONTRACT_OVERRIDES(f)
1875 // Override from `b::f`.
1876 t f(t_1 a_1, ..., t_n a_n, boost::contract::virtual_* v = 0) {
1878 boost::contract::old_ptr<old_type> old_var;
1879 boost::contract::check c = boost::contract::public_function<
1880 override_f>(v, result, &u::f, this, a_1, ..., a_n)
1881 .precondition([&] { // Optional.
1882 BOOST_CONTRACT_ASSERT(...);
1885 .old([&] { // Optional.
1886 old_var = BOOST_CONTRACT_OLDOF(v, old_expr);
1889 .postcondition([&] (t const& result) { // Optional.
1890 BOOST_CONTRACT_ASSERT(...);
1893 .except([&] { // Optional.
1894 BOOST_CONTRACT_ASSERT(...);
1899 ... // Function body (use `return result = return_expr`).
1904 </programlisting></para><para>A public function override should always call <computeroutput><functionname alt="boost::contract::public_function">boost::contract::public_function</functionname></computeroutput> otherwise this library will not be able to correctly use it for subcontracting.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.public_function_overrides__subcontracting_">
1905 Public Function Overrides</link></para>
1910 </para></description><returns><para>The result of this function must be assigned to a variable of type <computeroutput><classname alt="boost::contract::check">boost::contract::check</classname></computeroutput> declared explicitly (i.e., without using C++11 <computeroutput>auto</computeroutput> declarations) and locally just before the code of the public function body (otherwise this library will generate a run-time error, see <computeroutput><macroname alt="BOOST_CONTRACT_ON_MISSING_CHECK_DECL">BOOST_CONTRACT_ON_MISSING_CHECK_DECL</macroname></computeroutput>). </para>
1911 </returns></function>
1937 <header name="boost/contract_macro.hpp">
1938 <para>Allow to disable contracts to completely remove their compile-time and run-time overhead. </para><para>This header automatically includes all header files <computeroutput>boost/contract/*.hpp</computeroutput> necessary to use its macros.</para><para>Almost all the macros defined in this header file are variadic macros. On compilers that do not support variadic macros, programmers can manually code <computeroutput>#ifndef BOOST_CONTRACT_NO_...</computeroutput> statements instead (see <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
1939 Disable Contract Compilation</link>). </para><macro name="BOOST_CONTRACT_PRECONDITION" kind="functionlike"><macro-parameter name="..."/><purpose>Program preconditions that can be completely disabled at compile-time. </purpose><description><para><computeroutput>BOOST_CONTRACT_PRECONDITION(f)</computeroutput> expands to code equivalent to the following (note that no code is generated when <computeroutput><macroname alt="BOOST_CONTRACT_NO_PRECONDITIONS">BOOST_CONTRACT_NO_PRECONDITIONS</macroname></computeroutput> is defined):</para><para><programlisting language="c++">#ifndef BOOST_CONTRACT_NO_PRECONDITIONS
1942 </programlisting></para><para>Where:</para><para><itemizedlist>
1943 <listitem><para><computeroutput><emphasis role="bold">f</emphasis></computeroutput> is the nullay functor called by this library to check preconditions <computeroutput>f()</computeroutput>. Assertions within this functor are usually programmed using <computeroutput><macroname alt="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</macroname></computeroutput>, but any exception thrown by a call to this functor indicates a contract assertion failure (and will result in this library calling <computeroutput><functionname alt="boost::contract::precondition_failure">boost::contract::precondition_failure</functionname></computeroutput>). This functor should capture variables by (constant) value, or better by (constant) reference (to avoid extra copies). (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.)</para>
1946 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
1947 Disable Contract Compilation</link>, <link linkend="boost_contract.tutorial.preconditions"> Preconditions</link> </para>
1949 </para></description></macro>
1950 <macro name="BOOST_CONTRACT_POSTCONDITION" kind="functionlike"><macro-parameter name="..."/><purpose>Program postconditions that can be completely disabled at compile-time. </purpose><description><para><computeroutput>BOOST_CONTRACT_POSTCONDITION(f)</computeroutput> expands to code equivalent to the following (note that no code is generated when <computeroutput><macroname alt="BOOST_CONTRACT_NO_POSTCONDITIONS">BOOST_CONTRACT_NO_POSTCONDITIONS</macroname></computeroutput> is defined):</para><para><programlisting language="c++">#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
1953 </programlisting></para><para>Where:</para><para><itemizedlist>
1954 <listitem><para><computeroutput><emphasis role="bold">f</emphasis></computeroutput> is the functor called by this library to check postconditions <computeroutput>f()</computeroutput> or <computeroutput>f(result)</computeroutput>. Assertions within this functor are usually programmed using <computeroutput><macroname alt="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</macroname></computeroutput>, but any exception thrown by a call to this functor indicates a contract assertion failure (and will result in this library calling <computeroutput><functionname alt="boost::contract::postcondition_failure">boost::contract::postcondition_failure</functionname></computeroutput>). This functor should capture variables by (constant) references (to access the values they will have at function exit). This functor takes the return value (preferably by <computeroutput>const&</computeroutput>) <computeroutput>result</computeroutput> as its one single parameter <computeroutput>f(result)</computeroutput> but only for virtual public functions and public functions overrides, otherwise it takes no parameter <computeroutput>f()</computeroutput>. (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.)</para>
1957 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
1958 Disable Contract Compilation</link>, <link linkend="boost_contract.tutorial.postconditions"> Postconditions</link> </para>
1960 </para></description></macro>
1961 <macro name="BOOST_CONTRACT_EXCEPT" kind="functionlike"><macro-parameter name="..."/><purpose>Program exception guarantees that can be completely disabled at compile-time. </purpose><description><para><computeroutput>BOOST_CONTRACT_EXCEPT(f)</computeroutput> expands to code equivalent to the following (note that no code is generated when <computeroutput><macroname alt="BOOST_CONTRACT_NO_EXCEPTS">BOOST_CONTRACT_NO_EXCEPTS</macroname></computeroutput> is defined):</para><para><programlisting language="c++">#ifndef BOOST_CONTRACT_NO_EXCEPTS
1964 </programlisting></para><para>Where:</para><para><itemizedlist>
1965 <listitem><para><computeroutput><emphasis role="bold">f</emphasis></computeroutput> is the nullary functor called by this library to check exception guarantees <computeroutput>f()</computeroutput>. Assertions within this functor are usually programmed using <computeroutput><macroname alt="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</macroname></computeroutput>, but any exception thrown by a call to this functor indicates a contract assertion failure (and will result in this library calling <computeroutput><functionname alt="boost::contract::except_failure">boost::contract::except_failure</functionname></computeroutput>). This functor should capture variables by (constant) references (to access the values they will have at function exit). (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.)</para>
1968 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
1969 Disable Contract Compilation</link>, <link linkend="boost_contract.tutorial.exception_guarantees"> Exception Guarantees</link> </para>
1971 </para></description></macro>
1972 <macro name="BOOST_CONTRACT_OLD" kind="functionlike"><macro-parameter name="..."/><purpose>Program old value copies at body that can be completely disabled at compile-time. </purpose><description><para><computeroutput>BOOST_CONTRACT_OLD(f)</computeroutput> expands to code equivalent to the following (note that no code is generated when <computeroutput><macroname alt="BOOST_CONTRACT_NO_OLDS">BOOST_CONTRACT_NO_OLDS</macroname></computeroutput> is defined):</para><para><programlisting language="c++">#ifndef BOOST_CONTRACT_NO_OLDS
1975 </programlisting></para><para>Where:</para><para><itemizedlist>
1976 <listitem><para><computeroutput><emphasis role="bold">f</emphasis></computeroutput> is the nullary functor called by this library <computeroutput>f()</computeroutput> to assign old value copies just before the body is execute but after entry invariants (when they apply) and preconditions are checked. Old value pointers within this functor call are usually assigned using <computeroutput><macroname alt="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</macroname></computeroutput>. Any exception thrown by a call to this functor will result in this library calling <computeroutput><functionname alt="boost::contract::old_failure">boost::contract::old_failure</functionname></computeroutput> (because old values could not be copied to check postconditions and exception guarantees). This functor should capture old value pointers by references so they can be assigned (all other variables needed to evaluate old value expressions can be captured by (constant) value, or better by (constant) reference to avoid extra copies). (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.)</para>
1979 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
1980 Disable Contract Compilation</link>, <link linkend="boost_contract.advanced.old_values_copied_at_body">
1981 Old Values Copied at Body</link> </para>
1983 </para></description></macro>
1984 <macro name="BOOST_CONTRACT_OLD_PTR" kind="functionlike"><macro-parameter name="..."/><purpose>Program old values that can be completely disabled at compile-time for old value types that are required to be copyable. </purpose><description><para>This is used to program old value copies for copyable types:</para><para><programlisting language="c++">class u {
1987 BOOST_CONTRACT_OLD_PTR(old_type_a)(old_var_a); // Null...
1988 BOOST_CONTRACT_OLD_PTR(old_type_b)(old_var_b, old_expr_b); // Set.
1989 BOOST_CONTRACT_PUBLIC_FUNCTION(this)
1991 BOOST_CONTRACT_OLD([&] {
1992 old_var_a = BOOST_CONTRACT_OLDOF(old_expr_a); // ...set.
1998 ... // Function body.
2001 virtual void g(..., boost::contract::virtual_* v = 0) {
2002 BOOST_CONTRACT_OLD_PTR(old_type_a)(old_var_a); // No `v`
2003 BOOST_CONTRACT_OLD_PTR(old_type_b)(v, old_var_b, old_expr_b); // `v`
2004 BOOST_CONTRACT_PUBLIC_FUNCTION(v, this)
2006 BOOST_CONTRACT_OLD([&] {
2007 old_var_a = BOOST_CONTRACT_OLDOF(v, old_expr_a); // `v`
2013 ... // Function body.
2018 </programlisting></para><para>This is an overloaded variadic macro and it can be used in the following different ways (note that no code is generated when <computeroutput><macroname alt="BOOST_CONTRACT_NO_OLDS">BOOST_CONTRACT_NO_OLDS</macroname></computeroutput> is defined).</para><para>1. <computeroutput>BOOST_CONTRACT_OLD_PTR(old_type)(old_var)</computeroutput> expands to code equivalent to the following (this leaves the old value pointer null):</para><para><programlisting language="c++">#ifndef BOOST_CONTRACT_NO_OLDS
2019 // This declaration does not need to use `v`.
2020 boost::contract::old_ptr<old_type> old_var
2022 </programlisting></para><para>2. <computeroutput>BOOST_CONTRACT_OLD_PTR(old_type)(old_var, old_expr)</computeroutput> expands to code equivalent to the following (this initializes the pointer to the old value copy, but not to be used for virtual public functions and public function overrides):</para><para><programlisting language="c++">#ifndef BOOST_CONTRACT_NO_OLDS
2023 boost::contract::old_ptr<old_type> old_var =
2024 BOOST_CONTRACT_OLDOF(old_expr)
2026 </programlisting></para><para>3. <computeroutput>BOOST_CONTRACT_OLD_PTR(old_type)(v, old_var, old_expr)</computeroutput> expands to code equivalent to the following (this initializes the pointer to the old value copy for virtual public functions and public function overrides):</para><para><programlisting language="c++">#ifndef BOOST_CONTRACT_NO_OLDS
2027 boost::contract::old_ptr<old_type> old_var =
2028 BOOST_CONTRACT_OLDOF(v, old_expr)
2030 </programlisting></para><para>Where:</para><para><itemizedlist>
2031 <listitem><para><computeroutput><emphasis role="bold">old_type</emphasis></computeroutput> is the type of the pointed old value. This type must be copyable (i.e., <computeroutput>boost::contract::is_old_value_copyable<old_type>::value</computeroutput> is <computeroutput>true</computeroutput>), otherwise this pointer will always be null and this library will generate a compile-time error when the pointer is dereferenced (see <computeroutput><macroname alt="BOOST_CONTRACT_OLD_PTR_IF_COPYABLE">BOOST_CONTRACT_OLD_PTR_IF_COPYABLE</macroname></computeroutput>). (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.) (Rationale: Template parameters like this one are specified to this library macro interface using their own set of parenthesis <computeroutput>SOME_MACRO(template_params)(other_params)</computeroutput>.) </para>
2033 <listitem><para><computeroutput><emphasis role="bold">v</emphasis></computeroutput> is the extra training parameter of type <computeroutput><classname alt="boost::contract::virtual_">boost::contract::virtual_</classname></computeroutput><computeroutput>*</computeroutput> and default value <computeroutput>0</computeroutput> from the enclosing virtual public function or public function override declaring the contract. (This is not a variadic macro parameter but it should never contain commas because it is an identifier.) </para>
2035 <listitem><para><computeroutput><emphasis role="bold">old_var</emphasis></computeroutput> is the name of the old value pointer variable. (This is not a variadic macro parameter but it should never contain commas because it is an identifier.) </para>
2037 <listitem><para><computeroutput><emphasis role="bold">old_expr</emphasis></computeroutput> is the expression to be evaluated and copied in the old value pointer. (This is not a variadic macro parameter so any comma it might contain must be protected by round parenthesis and <computeroutput>BOOST_CONTRACT_OLD_PTR(old_type)(v, old_var, (old_expr))</computeroutput> will always work.)</para>
2040 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
2041 Disable Contract Compilation</link>, <link linkend="boost_contract.tutorial.old_values"> Old Values</link> </para>
2043 </para></description></macro>
2044 <macro name="BOOST_CONTRACT_OLD_PTR_IF_COPYABLE" kind="functionlike"><macro-parameter name="..."/><purpose>Program old values that can be completely disabled at compile-time for old value types that are not required to be copyable. </purpose><description><para>This is used to program old value copies for types that might or might not be copyable:</para><para><programlisting language="c++">template<typename T> // Type `T` might or not be copyable.
2048 BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(old_type_a)(old_var_a);
2049 BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(old_type_b)(old_var_b,
2051 BOOST_CONTRACT_PUBLIC_FUNCTION(this)
2053 BOOST_CONTRACT_OLD([&] {
2054 old_var_a = BOOST_CONTRACT_OLDOF(old_expr_a);
2057 ... // In postconditions or exception guarantees:
2058 if(old_var_a) ... // Always null for non-copyable types.
2059 if(old_var_b) ... // Always null for non-copyable types.
2063 ... // Function body.
2066 virtual void g(..., boost::contract::virtual_* v = 0) {
2067 BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(old_type_a)(old_var_a);
2068 BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(old_type_b)(v, old_var_b,
2070 BOOST_CONTRACT_PUBLIC_FUNCTION(v, this)
2072 BOOST_CONTRACT_OLD([&] {
2073 old_var_a = BOOST_CONTRACT_OLDOF(v, old_expr_a);
2076 ... // In postconditions or exception guarantees:
2077 if(old_var_a) ... // Always null for non-copyable types.
2078 if(old_var_b) ... // Always null for non-copyable types.
2082 ... // Function body.
2087 </programlisting></para><para>This is an overloaded variadic macro and it can be used in the following different ways (note that no code is generated when <computeroutput><macroname alt="BOOST_CONTRACT_NO_OLDS">BOOST_CONTRACT_NO_OLDS</macroname></computeroutput> is defined).</para><para>1. <computeroutput>BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(old_type)(old_var)</computeroutput> expands to code equivalent to the following (this leaves the old value pointer null):</para><para><programlisting language="c++">#ifndef BOOST_CONTRACT_NO_OLDS
2088 // This declaration does not need to use `v`.
2089 boost::contract::old_ptr_if_copyable<old_type> old_var
2091 </programlisting></para><para>2. <computeroutput>BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(old_type)(old_var, old_expr)</computeroutput> expands to code equivalent to the following (this initializes the pointer to the old value copy, but not to be used for virtual public functions and public function overrides):</para><para><programlisting language="c++">#ifndef BOOST_CONTRACT_NO_OLDS
2092 boost::contract::old_ptr_if_copyable<old_type> old_var =
2093 BOOST_CONTRACT_OLDOF(old_expr)
2095 </programlisting></para><para>3. <computeroutput>BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(old_type)(v, old_var, old_expr)</computeroutput> expands to code equivalent to the following (this initializes the pointer to the old value copy for virtual public functions and public function overrides):</para><para><programlisting language="c++">#ifndef BOOST_CONTRACT_NO_OLDS
2096 boost::contract::old_ptr_if_copyable<old_type> old_var =
2097 BOOST_CONTRACT_OLDOF(v, old_expr)
2099 </programlisting></para><para>Where:</para><para><itemizedlist>
2100 <listitem><para><computeroutput><emphasis role="bold">old_type</emphasis></computeroutput> is the type of the pointed old value. If this type is not copyable (i.e., <computeroutput>boost::contract::is_old_value_copyable<old_type>::value</computeroutput> is <computeroutput>false</computeroutput>), this pointer will always be null, but this library will not generate a compile-time error when this pointer is dereferenced (see <computeroutput><macroname alt="BOOST_CONTRACT_OLD_PTR">BOOST_CONTRACT_OLD_PTR</macroname></computeroutput>). (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.) </para>
2102 <listitem><para><computeroutput><emphasis role="bold">v</emphasis></computeroutput> is the extra trailing parameter of type <computeroutput><classname alt="boost::contract::virtual_">boost::contract::virtual_</classname></computeroutput><computeroutput>*</computeroutput> and default value <computeroutput>0</computeroutput> from the enclosing virtual public function or public function override declaring the contract. (This is not a variadic macro parameter but it should never contain commas because it is an identifier.) </para>
2104 <listitem><para><computeroutput><emphasis role="bold">old_var</emphasis></computeroutput> is the name of the old value pointer variable. (This is not a variadic macro parameter but it should never contain commas because it is an identifier.) </para>
2106 <listitem><para><computeroutput><emphasis role="bold">old_expr</emphasis></computeroutput> is the expression to be evaluated and copied in the old value pointer. (This is not a variadic macro parameter so any comma it might contain must be protected by round parenthesis and <computeroutput>BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(old_type)(v, old_var, (old_expr))</computeroutput> will always work.)</para>
2109 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
2110 Disable Contract Compilation</link>, <link linkend="boost_contract.extras.old_value_requirements__templates_">
2111 Old Value Requirements</link> </para>
2113 </para></description></macro>
2114 <macro name="BOOST_CONTRACT_INVARIANT" kind="functionlike"><macro-parameter name="..."/><purpose>Program (constant) class invariants that can be completely disabled at compile-time. </purpose><description><para><computeroutput>BOOST_CONTRACT_INVARIANT</computeroutput>({ ... }) expands to code equivalent to the following (note that no code is generated when <computeroutput><macroname alt="BOOST_CONTRACT_NO_INVARIANTS">BOOST_CONTRACT_NO_INVARIANTS</macroname></computeroutput> is defined):</para><para><programlisting language="c++">#ifndef BOOST_CONTRACT_NO_INVARIANTS
2115 void BOOST_CONTRACT_INVARIANT_FUNC() const {
2119 </programlisting></para><para>Where:</para><para><itemizedlist>
2120 <listitem><para><emphasis role="bold">{ ... }</emphasis> is the definition of the function that checks class invariants for public functions that are not static and not volatile (see <computeroutput><macroname alt="BOOST_CONTRACT_STATIC_INVARIANT">BOOST_CONTRACT_STATIC_INVARIANT</macroname></computeroutput> and <computeroutput><macroname alt="BOOST_CONTRACT_INVARIANT_VOLATILE">BOOST_CONTRACT_INVARIANT_VOLATILE</macroname></computeroutput>). The curly parenthesis are mandatory (rationale: this is so the syntax of this macro resembles mote the syntax of the lambda functions usually used to specify preconditions, etc.). Assertions within this function are usually programmed using <computeroutput><macroname alt="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</macroname></computeroutput>, but any exception thrown by a call to this function indicates a contract assertion failure (and will result in this library calling either <computeroutput><functionname alt="boost::contract::entry_invariant_failure">boost::contract::entry_invariant_failure</functionname></computeroutput> or <computeroutput><functionname alt="boost::contract::exit_invariant_failure">boost::contract::exit_invariant_failure</functionname></computeroutput>). (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.)</para>
2123 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
2124 Disable Contract Compilation</link>, <link linkend="boost_contract.tutorial.class_invariants"> Class Invariants</link> </para>
2126 </para></description></macro>
2127 <macro name="BOOST_CONTRACT_INVARIANT_VOLATILE" kind="functionlike"><macro-parameter name="..."/><purpose>Program volatile class invariants that can be completely disabled at compile-time. </purpose><description><para><computeroutput>BOOST_CONTRACT_INVARIANT_VOLATILE</computeroutput>({ ... }) expands to code equivalent to the following (note that no code is generated when <computeroutput><macroname alt="BOOST_CONTRACT_NO_INVARIANTS">BOOST_CONTRACT_NO_INVARIANTS</macroname></computeroutput> is defined):</para><para><programlisting language="c++">#ifndef BOOST_CONTRACT_NO_INVARIANTS
2128 void BOOST_CONTRACT_INVARIANT_FUNC() const volatile {
2132 </programlisting></para><para>Where:</para><para><itemizedlist>
2133 <listitem><para><emphasis role="bold">{ ... }</emphasis> is the definition of the function that checks class invariants for volatile public functions (see <computeroutput><macroname alt="BOOST_CONTRACT_INVARIANT">BOOST_CONTRACT_INVARIANT</macroname></computeroutput> and <computeroutput><macroname alt="BOOST_CONTRACT_STATIC_INVARIANT">BOOST_CONTRACT_STATIC_INVARIANT</macroname></computeroutput>). The curly parenthesis are mandatory. Assertions within this function are usually programmed using <computeroutput><macroname alt="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</macroname></computeroutput>, but any exception thrown by a call to this function indicates a contract assertion failure (and will result in this library calling either <computeroutput><functionname alt="boost::contract::entry_invariant_failure">boost::contract::entry_invariant_failure</functionname></computeroutput> or <computeroutput><functionname alt="boost::contract::exit_invariant_failure">boost::contract::exit_invariant_failure</functionname></computeroutput>). (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.)</para>
2136 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
2137 Disable Contract Compilation</link>, <link linkend="boost_contract.extras.volatile_public_functions">
2138 Volatile Public Functions</link> </para>
2140 </para></description></macro>
2141 <macro name="BOOST_CONTRACT_STATIC_INVARIANT" kind="functionlike"><macro-parameter name="..."/><purpose>Program static class invariants that can be completely disabled at compile-time. </purpose><description><para><computeroutput>BOOST_CONTRACT_STATIC_INVARIANT</computeroutput>({ ... }) expands to code equivalent to the following (note that no code is generated when <computeroutput><macroname alt="BOOST_CONTRACT_NO_INVARIANTS">BOOST_CONTRACT_NO_INVARIANTS</macroname></computeroutput> is defined):</para><para><programlisting language="c++">#ifndef BOOST_CONTRACT_NO_INVARIANTS
2142 static void BOOST_CONTRACT_STATIC_INVARIANT_FUNC() {
2146 </programlisting></para><para>Where:</para><para><itemizedlist>
2147 <listitem><para><emphasis role="bold">{ ... }</emphasis> is the definition of the function that checks class invariants for static public functions (see <computeroutput><macroname alt="BOOST_CONTRACT_INVARIANT">BOOST_CONTRACT_INVARIANT</macroname></computeroutput> and <computeroutput><macroname alt="BOOST_CONTRACT_INVARIANT_VOLATILE">BOOST_CONTRACT_INVARIANT_VOLATILE</macroname></computeroutput>). The curly parenthesis are mandatory. Assertions within this function are usually programmed using <computeroutput><macroname alt="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</macroname></computeroutput>, but any exception thrown by a call to this function indicates a contract assertion failure (and will result in this library calling either <computeroutput><functionname alt="boost::contract::entry_invariant_failure">boost::contract::entry_invariant_failure</functionname></computeroutput> or <computeroutput><functionname alt="boost::contract::exit_invariant_failure">boost::contract::exit_invariant_failure</functionname></computeroutput>). (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.)</para>
2150 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
2151 Disable Contract Compilation</link>, <link linkend="boost_contract.tutorial.class_invariants"> Class Invariants</link> </para>
2153 </para></description></macro>
2154 <macro name="BOOST_CONTRACT_CONSTRUCTOR" kind="functionlike"><macro-parameter name="..."/><purpose>Program contracts that can be completely disabled at compile-time for constructors. </purpose><description><para>This is used together with <computeroutput><macroname alt="BOOST_CONTRACT_POSTCONDITION">BOOST_CONTRACT_POSTCONDITION</macroname></computeroutput>, <computeroutput><macroname alt="BOOST_CONTRACT_EXCEPT">BOOST_CONTRACT_EXCEPT</macroname></computeroutput>, and <computeroutput><macroname alt="BOOST_CONTRACT_OLD">BOOST_CONTRACT_OLD</macroname></computeroutput> to specify postconditions, exception guarantees, and old value copies at body that can be completely disabled at compile-time for constructors (see <computeroutput><macroname alt="BOOST_CONTRACT_CONSTRUCTOR_PRECONDITION">BOOST_CONTRACT_CONSTRUCTOR_PRECONDITION</macroname></computeroutput> to specify preconditions for constructors):</para><para><programlisting language="c++">class u {
2155 friend class boost::contract::access;
2157 BOOST_CONTRACT_INVARIANT({ // Optional (as for static and volatile).
2158 BOOST_CONTRACT_ASSERT(...);
2164 BOOST_CONTRACT_OLD_PTR(old_type)(old_var);
2165 BOOST_CONTRACT_CONSTRUCTOR(this)
2166 // No `PRECONDITION` (use `CONSTRUCTOR_PRECONDITION` if needed).
2167 BOOST_CONTRACT_OLD([&] { // Optional.
2168 old_var = BOOST_CONTRACT_OLDOF(old_epxr);
2171 BOOST_CONTRACT_POSTCONDITION([&] { // Optional.
2172 BOOST_CONTRACT_ASSERT(...);
2175 BOOST_CONTRACT_EXCEPT([&] { // Optional.
2176 BOOST_CONTRACT_ASSERT(...);
2179 ; // Trailing `;` is required.
2181 ... // Constructor body.
2186 </programlisting></para><para>For optimization, this can be omitted for constructors that do not have postconditions and exception guarantees, within classes that have no invariants.</para><para><computeroutput>BOOST_CONTRACT_CONSTRUCTOR(obj)</computeroutput> expands to code equivalent to the following (note that no code is generated when <computeroutput><macroname alt="BOOST_CONTRACT_NO_CONSTRUCTORS">BOOST_CONTRACT_NO_CONSTRUCTORS</macroname></computeroutput> is defined):</para><para><programlisting language="c++">#ifndef BOOST_CONTRACT_NO_CONSTRUCTORS
2187 boost::contract::check internal_var =
2188 boost::contract::constructor(obj)
2190 </programlisting></para><para>Where:</para><para><itemizedlist>
2191 <listitem><para><computeroutput><emphasis role="bold">obj</emphasis></computeroutput> is the object <computeroutput>this</computeroutput> from the scope of the enclosing constructor declaring the contract. Constructors check all class invariants, including static and volatile invariants (see <computeroutput><macroname alt="BOOST_CONTRACT_INVARIANT">BOOST_CONTRACT_INVARIANT</macroname></computeroutput>, <computeroutput><macroname alt="BOOST_CONTRACT_STATIC_INVARIANT">BOOST_CONTRACT_STATIC_INVARIANT</macroname></computeroutput>, and <computeroutput><macroname alt="BOOST_CONTRACT_INVARIANT_VOLATILE">BOOST_CONTRACT_INVARIANT_VOLATILE</macroname></computeroutput>). (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.) </para>
2193 <listitem><para><computeroutput><emphasis role="bold">internal_var</emphasis></computeroutput> is a variable name internally generated by this library (this name is unique but only on different line numbers so this macro cannot be expanded multiple times on the same line).</para>
2196 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
2197 Disable Contract Compilation</link>, <link linkend="boost_contract.tutorial.constructors"> Constructors</link> </para>
2199 </para></description></macro>
2200 <macro name="BOOST_CONTRACT_CONSTRUCTOR_PRECONDITION" kind="functionlike"><macro-parameter name="..."/><purpose>Program preconditions that can be disabled at compile-time for constructors. </purpose><description><para>This is used together with <computeroutput><macroname alt="BOOST_CONTRACT_CONSTRUCTOR">BOOST_CONTRACT_CONSTRUCTOR</macroname></computeroutput> to specify contracts for constructors. Constructors that do not have preconditions do not use this macro. When at least one of the class constructors uses this macro, <computeroutput><classname alt="boost::contract::constructor_precondition">boost::contract::constructor_precondition</classname></computeroutput> must be the first and private base of the class declaring the constructor for which preconditions are programmed:</para><para><programlisting language="c++">class u
2201 #define BASES private boost::contract::constructor_precondition<u>, \
2205 friend class boost::contract::access;
2207 typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types;
2213 explicit u(unsigned x) :
2214 BOOST_CONTRACT_CONSTRUCTOR_PRECONDITION(u)([&] {
2215 BOOST_CONTRACT_ASSERT(x != 0);
2224 </programlisting></para><para><computeroutput>BOOST_CONTRACT_CONSTRUCTOR_PRECONDITION(class_type)(f)</computeroutput> expands to code equivalent to the following (note that when <computeroutput><macroname alt="BOOST_CONTRACT_NO_PRECONDITIONS">BOOST_CONTRACT_NO_PRECONDITIONS</macroname></computeroutput> is defined, this macro trivially expands to a default constructor call that is internally implemented to do nothing so this should have minimal to no overhead):</para><para><programlisting language="c++">// Guarded only by NO_PRECONDITIONS (and not also by NO_CONSTRUCTORS)
2225 // because for constructor's preconditions (not for postconditions, etc.).
2226 #ifndef BOOST_CONTRACT_NO_PRECONDITIONS
2227 boost::contract::constructor_precondition<class_type>(f)
2228 #else // No-op call (likely optimized away, minimal to no overhead).
2229 boost::contract::constructor_precondition<class_type>()
2231 </programlisting></para><para>Where:</para><para><itemizedlist>
2232 <listitem><para><computeroutput><emphasis role="bold">class_type</emphasis></computeroutput> is the type of the class containing the constructor for which preconditions are being programmed. (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.) </para>
2234 <listitem><para><computeroutput><emphasis role="bold">f</emphasis></computeroutput> is the nullary functor called by this library to check constructor preconditions <computeroutput>f()</computeroutput>. Assertions within this functor call are usually programmed using <computeroutput><macroname alt="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</macroname></computeroutput>, but any exception thrown by a call to this functor indicates a contract failure (and will result in this library calling <computeroutput><functionname alt="boost::contract::precondition_failure">boost::contract::precondition_failure</functionname></computeroutput>). This functor should capture variables by (constant) value, or better by (constant) reference to avoid extra copies. (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.)</para>
2237 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
2238 Disable Contract Compilation</link>, <link linkend="boost_contract.tutorial.constructors"> Constructors</link> </para>
2240 </para></description></macro>
2241 <macro name="BOOST_CONTRACT_DESTRUCTOR" kind="functionlike"><macro-parameter name="..."/><purpose>Program contracts that can be completely disabled at compile-time for destructors. </purpose><description><para>This is used together with <computeroutput><macroname alt="BOOST_CONTRACT_POSTCONDITION">BOOST_CONTRACT_POSTCONDITION</macroname></computeroutput>, <computeroutput><macroname alt="BOOST_CONTRACT_EXCEPT">BOOST_CONTRACT_EXCEPT</macroname></computeroutput>, and <computeroutput><macroname alt="BOOST_CONTRACT_OLD">BOOST_CONTRACT_OLD</macroname></computeroutput> to specify postconditions, exception guarantees, and old value copies at body that can be completely disabled at compile-time for destructors (destructors cannot have preconditions, see <link linkend="boost_contract.contract_programming_overview.destructor_calls"> Destructor Calls</link>):</para><para><programlisting language="c++">class u {
2242 friend class boost::contract::access;
2244 BOOST_CONTRACT_INVARIANT({ // Optional (as for static and volatile).
2245 BOOST_CONTRACT_ASSERT(...);
2251 BOOST_CONTRACT_OLD_PTR(old_type)(old_var);
2252 BOOST_CONTRACT_DESTRUCTOR(this)
2253 // No `PRECONDITION` (destructors have no preconditions).
2254 BOOST_CONTRACT_OLD([&] { // Optional.
2255 old_var = BOOST_CONTRACT_OLDOF(old_expr);
2258 BOOST_CONTRACT_POSTCONDITION([&] { // Optional.
2259 BOOST_CONTRACT_ASSERT(...);
2262 BOOST_CONTRACT_EXCEPT([&] { // Optional.
2263 BOOST_CONTRACT_ASSERT(...);
2266 ; // Trailing `;` is required.
2268 ... // Destructor body.
2273 </programlisting></para><para>For optimization, this can be omitted for destructors that do not have postconditions and exception guarantees, within classes that have no invariants.</para><para><computeroutput>BOOST_CONTRACT_DESTRUCTOR(obj)</computeroutput> expands to code equivalent to the following (note that no code is generated when <computeroutput><macroname alt="BOOST_CONTRACT_NO_DESTRUCTORS">BOOST_CONTRACT_NO_DESTRUCTORS</macroname></computeroutput> is defined):</para><para><programlisting language="c++">#ifndef BOOST_CONTRACT_NO_DESTRUCTORS
2274 boost::contract::check internal_var =
2275 boost::contract::destructor(obj)
2277 </programlisting></para><para>Where:</para><para><itemizedlist>
2278 <listitem><para><computeroutput><emphasis role="bold">obj</emphasis></computeroutput> is the object <computeroutput>this</computeroutput> from the scope of the enclosing destructor declaring the contract. Destructors check all class invariants, including static and volatile invariants (see <link linkend="boost_contract.tutorial.class_invariants">
2279 Class Invariants</link> and <link linkend="boost_contract.extras.volatile_public_functions">
2280 Volatile Public Functions</link>). (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.) </para>
2282 <listitem><para><computeroutput><emphasis role="bold">internal_var</emphasis></computeroutput> is a variable name internally generated by this library (this name is unique but only on different line numbers so this macro cannot be expanded multiple times on the same line).</para>
2285 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
2286 Disable Contract Compilation</link>, <link linkend="boost_contract.tutorial.destructors"> Destructors</link> </para>
2288 </para></description></macro>
2289 <macro name="BOOST_CONTRACT_FUNCTION" kind="functionlike"><macro-parameter name=""/><purpose>Program contracts that can be completely disabled at compile-time for (non-public) functions. </purpose><description><para>This is used together with <computeroutput><macroname alt="BOOST_CONTRACT_PRECONDITION">BOOST_CONTRACT_PRECONDITION</macroname></computeroutput>, <computeroutput><macroname alt="BOOST_CONTRACT_POSTCONDITION">BOOST_CONTRACT_POSTCONDITION</macroname></computeroutput>, <computeroutput><macroname alt="BOOST_CONTRACT_EXCEPT">BOOST_CONTRACT_EXCEPT</macroname></computeroutput>, and <computeroutput><macroname alt="BOOST_CONTRACT_OLD">BOOST_CONTRACT_OLD</macroname></computeroutput> to specify preconditions, postconditions, exception guarantees, and old value copies at body that can be completely disabled at compile-time for (non-public) functions:</para><para><programlisting language="c++">void f(...) {
2290 BOOST_CONTRACT_OLD_PTR(old_type)(old_var);
2291 BOOST_CONTRACT_FUNCTION()
2292 BOOST_CONTRACT_PRECONDITION([&] { // Optional.
2293 BOOST_CONTRACT_ASSERT(...);
2296 BOOST_CONTRACT_OLD([&] { // Optional.
2297 old_var = BOOST_CONTRACT_OLDOF(old_expr);
2300 BOOST_CONTRACT_POSTCONDITION([&] { // Optional.
2301 BOOST_CONTRACT_ASSERT(...);
2304 BOOST_CONTRACT_EXCEPT([&] { // Optional.
2305 BOOST_CONTRACT_ASSERT(...);
2308 ; // Trailing `;` is required.
2310 ... // Function body.
2312 </programlisting></para><para>This can be used to program contracts for non-member functions but also for private and protected functions, lambda functions, loops, arbitrary blocks of code, etc. For optimization, this can be omitted for code that does not have preconditions, postconditions, and exception guarantees.</para><para><computeroutput>BOOST_CONTRACT_FUNCTION()</computeroutput> expands to code equivalent to the following (note that no code is generated when <computeroutput><macroname alt="BOOST_CONTRACT_NO_FUNCTIONS">BOOST_CONTRACT_NO_FUNCTIONS</macroname></computeroutput> is defined):</para><para><programlisting language="c++">#ifndef BOOST_CONTRACT_NO_FUNCTIONS
2313 boost::contract::check internal_var =
2314 boost::contract::function()
2316 </programlisting></para><para>Where:</para><para><itemizedlist>
2317 <listitem><para><computeroutput><emphasis role="bold">internal_var</emphasis></computeroutput> is a variable name internally generated by this library (this name is unique but only on different line numbers so this macro cannot be expanded multiple times on the same line).</para>
2320 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
2321 Disable Contract Compilation</link>, <link linkend="boost_contract.tutorial.non_member_functions"> Non-Member Functions</link>, <link linkend="boost_contract.advanced.private_and_protected_functions">
2322 Private and Protected Functions</link>, <link linkend="boost_contract.advanced.lambdas__loops__code_blocks__and__constexpr__">
2323 Lambdas, Loops, Code Blocks</link> </para>
2325 </para></description></macro>
2326 <macro name="BOOST_CONTRACT_STATIC_PUBLIC_FUNCTION" kind="functionlike"><macro-parameter name="..."/><purpose>Program contracts that can be completely disabled at compile-time for static public functions. </purpose><description><para>This is used together with <computeroutput><macroname alt="BOOST_CONTRACT_PRECONDITION">BOOST_CONTRACT_PRECONDITION</macroname></computeroutput>, <computeroutput><macroname alt="BOOST_CONTRACT_POSTCONDITION">BOOST_CONTRACT_POSTCONDITION</macroname></computeroutput>, <computeroutput><macroname alt="BOOST_CONTRACT_EXCEPT">BOOST_CONTRACT_EXCEPT</macroname></computeroutput>, and <computeroutput><macroname alt="BOOST_CONTRACT_OLD">BOOST_CONTRACT_OLD</macroname></computeroutput> to specify preconditions, postconditions, exception guarantees, and old value copies at body that can be completely disabled at compile-time for static public functions:</para><para><programlisting language="c++">class u {
2327 friend class boost::contract::access;
2329 BOOST_CONTRACT_STATIC_INVARIANT({ // Optional (as for non-static).
2330 BOOST_CONTRACT_ASSERT(...);
2335 static void f(...) {
2336 BOOST_CONTRACT_OLD_PTR(old_type)(old_var);
2337 BOOST_CONTRACT_PUBLIC_FUNCTION(u)
2338 BOOST_CONTRACT_PRECONDITION([&] { // Optional.
2339 BOOST_CONTRACT_ASSERT(...);
2342 BOOST_CONTRACT_OLD([&] { // Optional.
2343 old_var = BOOST_CONTRACT_OLDOF(old_expr);
2346 BOOST_CONTRACT_POSTCONDITION([&] { // Optional.
2347 BOOST_CONTRACT_ASSERT(...);
2350 BOOST_CONTRACT_EXCEPT([&] { // Optional.
2351 BOOST_CONTRACT_ASSERT(...);
2354 ; // Trailing `;` is required.
2356 ... // Function body.
2361 </programlisting></para><para>For optimization, this can be omitted for static public functions that do not have preconditions, postconditions and exception guarantees, within classes that have no static invariants.</para><para><computeroutput>BOOST_CONTRACT_STATIC_PUBLIC_FUNCTION(class_type)</computeroutput> expands to code equivalent to the following (note that no code is generated when <computeroutput><macroname alt="BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS">BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS</macroname></computeroutput> is defined):</para><para><programlisting language="c++">#ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS
2362 boost::contract::check internal_var =
2363 boost::contract::public_function<class_type>()
2365 </programlisting></para><para>Where:</para><para><itemizedlist>
2366 <listitem><para><computeroutput><emphasis role="bold">class_type</emphasis></computeroutput> is the type of the class containing the static public function declaring the contract. (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.) </para>
2368 <listitem><para><computeroutput><emphasis role="bold">internal_var</emphasis></computeroutput> is a variable name internally generated by this library (this name is unique but only on different line numbers so this macro cannot be expanded multiple times on the same line).</para>
2371 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
2372 Disable Contract Compilation</link>, <link linkend="boost_contract.tutorial.static_public_functions"> Static Public Functions</link> </para>
2374 </para></description></macro>
2375 <macro name="BOOST_CONTRACT_PUBLIC_FUNCTION" kind="functionlike"><macro-parameter name="..."/><purpose>Program contracts that can be completely disabled at compile-time for non-static public functions that do not override. </purpose><description><para>This is used together with <computeroutput><macroname alt="BOOST_CONTRACT_PRECONDITION">BOOST_CONTRACT_PRECONDITION</macroname></computeroutput>, <computeroutput><macroname alt="BOOST_CONTRACT_POSTCONDITION">BOOST_CONTRACT_POSTCONDITION</macroname></computeroutput>, <computeroutput><macroname alt="BOOST_CONTRACT_EXCEPT">BOOST_CONTRACT_EXCEPT</macroname></computeroutput>, and <computeroutput><macroname alt="BOOST_CONTRACT_OLD">BOOST_CONTRACT_OLD</macroname></computeroutput> to specify preconditions, postconditions, exception guarantees, and old value copies at body that can be completely disabled at compile-time for non-static public functions (virtual or not, void or not) that do not override:</para><para><programlisting language="c++">class u {
2376 friend class boost::contract::access;
2378 BOOST_CONTRACT_INVARIANT({ // Optional (as for static and volatile).
2379 BOOST_CONTRACT_ASSERT(...);
2384 // Non-virtual (same if void).
2387 BOOST_CONTRACT_OLD_PTR(old_type)(old_var);
2388 BOOST_CONTRACT_PUBLIC_FUNCTION(this)
2389 BOOST_CONTRACT_PRECONDITION([&] { // Optional.
2390 BOOST_CONTRACT_ASSERT(...);
2393 BOOST_CONTRACT_OLD([&] { // Optional.
2394 old_var = BOOST_CONTRACT_OLDOF(old_expr);
2397 BOOST_CONTRACT_POSTCONDITION([&] { // Optional.
2398 BOOST_CONTRACT_ASSERT(...);
2401 BOOST_CONTRACT_EXCEPT([&] { // Optional.
2402 BOOST_CONTRACT_ASSERT(...);
2405 ; // Trailing `;` is required.
2407 ... // Function body (use `return result = return_expr`).
2410 // Virtual and void.
2411 virtual void g(..., boost::contract::virtual_* v = 0) {
2412 BOOST_CONTRACT_OLD_PTR(old_type)(old_var);
2413 BOOST_CONTRACT_PUBLIC_FUNCTION(v, this)
2415 BOOST_CONTRACT_OLD([&] { // Optional.
2416 old_var = BOOST_CONTRACT_OLDOF(v, old_expr);
2420 ; // Trailing `;` is required.
2422 ... // Function body.
2425 // Virtual and non-void.
2426 virtual t h(..., boost::contract::virtual_* v = 0) {
2428 BOOST_CONTRACT_OLD_PTR(old_type)(old_var);
2429 BOOST_CONTRACT_PUBLIC_FUNCTION(v, result, this)
2431 BOOST_CONTRACT_OLD([&] { // Optional.
2432 old_var = BOOST_CONTRACT_OLDOF(v, old_expr);
2435 BOOST_CONTRACT_POSTCONDITION([&] (t const& result) { // Optional
2436 BOOST_CONTRACT_ASSERT(...);
2440 ; // Trailing `;` is required.
2442 ... // Function body (use `return result = return_expr`).
2447 </programlisting></para><para>For optimization, this can be omitted for non-virtual public functions that do not have preconditions, postconditions and exception guarantees, within classes that have no invariants. Virtual public functions should always use <computeroutput><macroname alt="BOOST_CONTRACT_PUBLIC_FUNCTION">BOOST_CONTRACT_PUBLIC_FUNCTION</macroname></computeroutput> otherwise this library will not be able to correctly use them for subcontracting.</para><para>This is an overloaded variadic macro and it can be used in the following different ways (note that no code is generated when <computeroutput><macroname alt="BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS">BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS</macroname></computeroutput> is defined).</para><para>1. <computeroutput>BOOST_CONTRACT_PUBLIC_FUNCTION(obj)</computeroutput> expands to code equivalent to the following (for non-virtual public functions that are not static and do not override, returning void or not):</para><para><programlisting language="c++">#ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS
2448 boost::contract::check internal_var =
2449 boost::contract::public_function(obj)
2451 </programlisting></para><para>2. <computeroutput>BOOST_CONTRACT_PUBLIC_FUNCTION(v, obj)</computeroutput> expands to code equivalent to the following (for virtual public functions that do not override, returning void):</para><para><programlisting language="c++">#ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS
2452 boost::contract::check internal_var =
2453 boost::contract::public_function(v, obj)
2455 </programlisting></para><para>3. <computeroutput>BOOST_CONTRACT_PUBLIC_FUNCTION(v, r, obj)</computeroutput> expands to code equivalent to the following (for virtual public functions that do not override, not returning void):</para><para><programlisting language="c++">#ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS
2456 boost::contract::check internal_var =
2457 boost::contract::public_function(v, r, obj)
2459 </programlisting></para><para>Where (these are all variadic macro parameters so they can contain commas not protected by round parenthesis):</para><para><itemizedlist>
2460 <listitem><para><computeroutput><emphasis role="bold">v</emphasis></computeroutput> is the extra parameter of type <computeroutput><classname alt="boost::contract::virtual_">boost::contract::virtual_</classname></computeroutput><computeroutput>*</computeroutput> and default value <computeroutput>0</computeroutput> from the enclosing virtual public function declaring the contract. </para>
2462 <listitem><para><computeroutput><emphasis role="bold">r</emphasis></computeroutput> is a reference to the return value of the enclosing virtual public function declaring the contract. This is usually a local variable declared by the enclosing virtual public function just before the contract, but programmers must set it to the actual value being returned by the function at each <computeroutput>return</computeroutput> statement. </para>
2464 <listitem><para><computeroutput><emphasis role="bold">obj</emphasis></computeroutput> is the object <computeroutput>this</computeroutput> from the scope of the enclosing public function declaring the contract. This object might be mutable, <computeroutput>const</computeroutput>, <computeroutput>volatile</computeroutput>, or <computeroutput>const volatile</computeroutput> depending on the cv-qualifier of the enclosing function (volatile public functions will check volatile class invariants, see <link linkend="boost_contract.extras.volatile_public_functions">
2465 Volatile Public Functions</link>). </para>
2467 <listitem><para><computeroutput><emphasis role="bold">internal_var</emphasis></computeroutput> is a variable name internally generated by this library (this name is unique but only on different line numbers so this macro cannot be expanded multiple times on the same line).</para>
2470 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
2471 Disable Contract Compilation</link>, <link linkend="boost_contract.tutorial.public_functions"> Public Functions</link>, <link linkend="boost_contract.tutorial.virtual_public_functions">
2472 Virtual Public Functions</link> </para>
2474 </para></description></macro>
2475 <macro name="BOOST_CONTRACT_PUBLIC_FUNCTION_OVERRIDE" kind="functionlike"><macro-parameter name="..."/><purpose>Program contracts that can be completely disabled at compile-time for public function overrides. </purpose><description><para>This is used together with <computeroutput><macroname alt="BOOST_CONTRACT_PRECONDITION">BOOST_CONTRACT_PRECONDITION</macroname></computeroutput>, <computeroutput><macroname alt="BOOST_CONTRACT_POSTCONDITION">BOOST_CONTRACT_POSTCONDITION</macroname></computeroutput>, <computeroutput><macroname alt="BOOST_CONTRACT_EXCEPT">BOOST_CONTRACT_EXCEPT</macroname></computeroutput>, and <computeroutput><macroname alt="BOOST_CONTRACT_OLD">BOOST_CONTRACT_OLD</macroname></computeroutput> to specify preconditions, postconditions, exception guarantees, and old value copies at body that can be completely disabled at compile-time for public function overrides (virtual or not):</para><para><programlisting language="c++">class u
2476 #define BASES private boost::contract::constructor_precondition<u>, \
2480 friend class boost::contract::access;
2482 typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types;
2485 BOOST_CONTRACT_INVARIANT({ // Optional (as for static and volatile).
2486 BOOST_CONTRACT_ASSERT(...);
2490 BOOST_CONTRACT_OVERRIDES(f, g)
2493 // Override from `b::f`, and void.
2494 void f(t_1 a_1, ..., t_n a_n, boost::contract::virtual_* v = 0) {
2495 BOOST_CONTRACT_OLD_PTR(old_type)(old_var);
2496 BOOST_CONTRACT_PUBLIC_FUNCTION_OVERRIDE(override_f)(
2497 v, &u::f, this, a_1, ..., a_n)
2498 BOOST_CONTRACT_PRECONDITION([&] { // Optional.
2499 BOOST_CONTRACT_ASSERT(...);
2502 BOOST_CONTRACT_OLD([&] { // Optional.
2503 old_var = BOOST_CONTRACT_OLDOF(v, old_expr);
2506 BOOST_CONTRACT_POSTCONDITION([&] { // Optional.
2507 BOOST_CONTRACT_ASSERT(...);
2510 BOOST_CONTRACT_EXCEPT([&] { // Optional.
2511 BOOST_CONTRACT_ASSERT(...);
2514 ; // Trailing `;` is required.
2516 ... // Function body.
2519 // Override from `b::g`, and void.
2520 t g(t_1 a_1, ..., t_n a_n, boost::contract::virtual_* v = 0) {
2522 BOOST_CONTRACT_OLD_PTR(old_type)(old_var);
2523 BOOST_CONTRACT_PUBLIC_FUNCTION_OVERRIDE(override_g)(
2524 v, result, &u::g, this, a_1, ..., a_n)
2526 BOOST_CONTRACT_OLD([&] { // Optional.
2527 old_var = BOOST_CONTRACT_OLDOF(v, old_expr);
2530 BOOST_CONTRACT_POSTCONDITION([&] (t const& result) { // Optional
2531 BOOST_CONTRACT_ASSERT(...);
2535 ; // Trailing `;` is required.
2537 ... // Function body (use `return result = return_expr`).
2542 </programlisting></para><para>Public function overrides should always use <computeroutput><macroname alt="BOOST_CONTRACT_PUBLIC_FUNCTION_OVERRIDE">BOOST_CONTRACT_PUBLIC_FUNCTION_OVERRIDE</macroname></computeroutput> otherwise this library will not be able to correctly use it for subcontracting.</para><para>This is an overloaded variadic macro and it can be used in the following different ways (note that no code is generated when <computeroutput><macroname alt="BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS">BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS</macroname></computeroutput> is defined).</para><para>1. <computeroutput>BOOST_CONTRACT_PUBLIC_FUNCTION_OVERRIDE(override_type)(v, f, obj, ...)</computeroutput> expands to code equivalent to the following (for public function overrides that return void):</para><para><programlisting language="c++">#ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS
2543 boost::contract::check internal_var = boost::contract::
2544 public_function<override_type>(v, f, obj, ...)
2546 </programlisting></para><para>2. <computeroutput>BOOST_CONTRACT_PUBLIC_FUNCTION_OVERRIDE(override_type)(v, r, f, obj, ...)</computeroutput> expands to code equivalent to the following (for public function overrides that do not return void):</para><para><programlisting language="c++">#ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS
2547 boost::contract::check internal_var = boost::contract::
2548 public_function<override_type>(v, r, f, obj, ...)
2550 </programlisting></para><para>Where (these are all variadic macro parameters so they can contain commas not protected by round parenthesis):</para><para><itemizedlist>
2551 <listitem><para><computeroutput><emphasis role="bold">override_type</emphasis></computeroutput> is the type <computeroutput>override_<emphasis>function-name</emphasis></computeroutput> declared using the <computeroutput><macroname alt="BOOST_CONTRACT_OVERRIDE">BOOST_CONTRACT_OVERRIDE</macroname></computeroutput> or related macros. </para>
2553 <listitem><para><computeroutput><emphasis role="bold">v</emphasis></computeroutput> is the extra parameter of type <computeroutput><classname alt="boost::contract::virtual_">boost::contract::virtual_</classname></computeroutput><computeroutput>*</computeroutput> and default value <computeroutput>0</computeroutput> from the enclosing virtual public function declaring the contract. </para>
2555 <listitem><para><computeroutput><emphasis role="bold">r</emphasis></computeroutput> is a reference to the return value of the enclosing virtual public function declaring the contract. This is usually a local variable declared by the enclosing virtual public function just before the contract, but programmers must set it to the actual value being returned by the function at each <computeroutput>return</computeroutput> statement. </para>
2557 <listitem><para><computeroutput><emphasis role="bold">f</emphasis></computeroutput> is a pointer to the enclosing public function override declaring the contract. </para>
2559 <listitem><para><computeroutput><emphasis role="bold">obj</emphasis></computeroutput> is the object <computeroutput>this</computeroutput> from the scope of the enclosing public function declaring the contract. This object might be mutable, <computeroutput>const</computeroutput>, <computeroutput>volatile</computeroutput>, or <computeroutput>const volatile</computeroutput> depending on the cv-qualifier of the enclosing function (volatile public functions will check volatile class invariants, see <link linkend="boost_contract.extras.volatile_public_functions">
2560 Volatile Public Functions</link>). </para>
2562 <listitem><para><computeroutput><emphasis role="bold">...</emphasis></computeroutput> is a variadic macro parameter listing all the arguments passed to the enclosing public function override declaring the contract (by reference and in the order they appear in the enclosing function declaration), but excluding the trailing argument <computeroutput>v</computeroutput>. </para>
2564 <listitem><para><computeroutput><emphasis role="bold">internal_var</emphasis></computeroutput> is a variable name internally generated by this library (this name is unique but only on different line numbers so this macro cannot be expanded multiple times on the same line).</para>
2567 <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
2568 Disable Contract Compilation</link>, <link linkend="boost_contract.tutorial.public_function_overrides__subcontracting_">
2569 Public Function Overrides</link> </para>
2571 </para></description></macro>
2573 </library-reference>