1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Macro BOOST_CONTRACT_OLD_PTR_IF_COPYABLE</title> 5<link rel="stylesheet" href="../../../../doc/src/boostbook.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="index.html" title="Chapter 1. Boost.Contract 1.0.0"> 8<link rel="up" href="reference.html#header.boost.contract_macro_hpp" title="Header <boost/contract_macro.hpp>"> 9<link rel="prev" href="BOOST_CONTRACT_OLD_PTR.html" title="Macro BOOST_CONTRACT_OLD_PTR"> 10<link rel="next" href="BOOST_CONTRACT_INVARIANT.html" title="Macro BOOST_CONTRACT_INVARIANT"> 11</head> 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13<table cellpadding="2" width="100%"><tr> 14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../boost.png"></td> 15<td align="center"><a href="../../../../index.html">Home</a></td> 16<td align="center"><a href="../../../../libs/libraries.htm">Libraries</a></td> 17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 19<td align="center"><a href="../../../../more/index.htm">More</a></td> 20</tr></table> 21<hr> 22<div class="spirit-nav"> 23<a accesskey="p" href="BOOST_CONTRACT_OLD_PTR.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="reference.html#header.boost.contract_macro_hpp"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="BOOST_CONTRACT_INVARIANT.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="refentry"> 26<a name="BOOST_CO_idm46268584486544"></a><div class="titlepage"></div> 27<div class="refnamediv"> 28<h2><span class="refentrytitle">Macro BOOST_CONTRACT_OLD_PTR_IF_COPYABLE</span></h2> 29<p>BOOST_CONTRACT_OLD_PTR_IF_COPYABLE — Program old values that can be completely disabled at compile-time for old value types that are not required to be copyable. </p> 30</div> 31<h2 xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv-title">Synopsis</h2> 32<div xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv"><pre class="synopsis"><span class="comment">// In header: <<a class="link" href="reference.html#header.boost.contract_macro_hpp" title="Header <boost/contract_macro.hpp>">boost/contract_macro.hpp</a>> 33 34</span>BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(...)</pre></div> 35<div class="refsect1"> 36<a name="idm45988675613968"></a><h2>Description</h2> 37<p>This is used to program old value copies for types that might or might not be copyable:</p> 38<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">></span> <span class="comment">// Type `T` might or not be copyable.</span> 39<span class="keyword">class</span> <span class="identifier">u</span> <span class="special">{</span> 40<span class="keyword">public</span><span class="special">:</span> 41 <span class="keyword">void</span> <span class="identifier">f</span><span class="special">(</span><span class="special">...</span><span class="special">)</span> <span class="special">{</span> 42 <span class="identifier">BOOST_CONTRACT_OLD_PTR_IF_COPYABLE</span><span class="special">(</span><span class="identifier">old_type_a</span><span class="special">)</span><span class="special">(</span><span class="identifier">old_var_a</span><span class="special">)</span><span class="special">;</span> 43 <span class="identifier">BOOST_CONTRACT_OLD_PTR_IF_COPYABLE</span><span class="special">(</span><span class="identifier">old_type_b</span><span class="special">)</span><span class="special">(</span><span class="identifier">old_var_b</span><span class="special">,</span> 44 <span class="identifier">old_expr_b</span><span class="special">)</span><span class="special">;</span> 45 <span class="identifier">BOOST_CONTRACT_PUBLIC_FUNCTION</span><span class="special">(</span><span class="keyword">this</span><span class="special">)</span> 46 <span class="special">...</span> 47 <span class="identifier">BOOST_CONTRACT_OLD</span><span class="special">(</span><span class="special">[</span><span class="special">&</span><span class="special">]</span> <span class="special">{</span> 48 <span class="identifier">old_var_a</span> <span class="special">=</span> <span class="identifier">BOOST_CONTRACT_OLDOF</span><span class="special">(</span><span class="identifier">old_expr_a</span><span class="special">)</span><span class="special">;</span> 49 <span class="special">...</span> 50 <span class="special">}</span><span class="special">)</span> 51 <span class="special">...</span> <span class="comment">// In postconditions or exception guarantees:</span> 52 <span class="keyword">if</span><span class="special">(</span><span class="identifier">old_var_a</span><span class="special">)</span> <span class="special">...</span> <span class="comment">// Always null for non-copyable types.</span> 53 <span class="keyword">if</span><span class="special">(</span><span class="identifier">old_var_b</span><span class="special">)</span> <span class="special">...</span> <span class="comment">// Always null for non-copyable types.</span> 54 <span class="special">...</span> 55 <span class="special">;</span> 56 57 <span class="special">...</span> <span class="comment">// Function body.</span> 58 <span class="special">}</span> 59 60 <span class="keyword">virtual</span> <span class="keyword">void</span> <span class="identifier">g</span><span class="special">(</span><span class="special">...</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">contract</span><span class="special">::</span><span class="identifier">virtual_</span><span class="special">*</span> <span class="identifier">v</span> <span class="special">=</span> <span class="number">0</span><span class="special">)</span> <span class="special">{</span> 61 <span class="identifier">BOOST_CONTRACT_OLD_PTR_IF_COPYABLE</span><span class="special">(</span><span class="identifier">old_type_a</span><span class="special">)</span><span class="special">(</span><span class="identifier">old_var_a</span><span class="special">)</span><span class="special">;</span> 62 <span class="identifier">BOOST_CONTRACT_OLD_PTR_IF_COPYABLE</span><span class="special">(</span><span class="identifier">old_type_b</span><span class="special">)</span><span class="special">(</span><span class="identifier">v</span><span class="special">,</span> <span class="identifier">old_var_b</span><span class="special">,</span> 63 <span class="identifier">old_expr_b</span><span class="special">)</span><span class="special">;</span> 64 <span class="identifier">BOOST_CONTRACT_PUBLIC_FUNCTION</span><span class="special">(</span><span class="identifier">v</span><span class="special">,</span> <span class="keyword">this</span><span class="special">)</span> 65 <span class="special">...</span> 66 <span class="identifier">BOOST_CONTRACT_OLD</span><span class="special">(</span><span class="special">[</span><span class="special">&</span><span class="special">]</span> <span class="special">{</span> 67 <span class="identifier">old_var_a</span> <span class="special">=</span> <span class="identifier">BOOST_CONTRACT_OLDOF</span><span class="special">(</span><span class="identifier">v</span><span class="special">,</span> <span class="identifier">old_expr_a</span><span class="special">)</span><span class="special">;</span> 68 <span class="special">...</span> 69 <span class="special">}</span><span class="special">)</span> 70 <span class="special">...</span> <span class="comment">// In postconditions or exception guarantees:</span> 71 <span class="keyword">if</span><span class="special">(</span><span class="identifier">old_var_a</span><span class="special">)</span> <span class="special">...</span> <span class="comment">// Always null for non-copyable types.</span> 72 <span class="keyword">if</span><span class="special">(</span><span class="identifier">old_var_b</span><span class="special">)</span> <span class="special">...</span> <span class="comment">// Always null for non-copyable types.</span> 73 <span class="special">...</span> 74 <span class="special">;</span> 75 76 <span class="special">...</span> <span class="comment">// Function body.</span> 77 <span class="special">}</span> 78 79 <span class="special">...</span> 80<span class="special">}</span><span class="special">;</span> 81</pre> 82<p>This is an overloaded variadic macro and it can be used in the following different ways (note that no code is generated when <code class="computeroutput"><a class="link" href="BOOST_CONTRACT_NO_OLDS.html" title="Macro BOOST_CONTRACT_NO_OLDS">BOOST_CONTRACT_NO_OLDS</a></code> is defined).</p> 83<p>1. <code class="computeroutput">BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(old_type)(old_var)</code> expands to code equivalent to the following (this leaves the old value pointer null):</p> 84<pre class="programlisting"><span class="preprocessor">#ifndef</span> <span class="identifier">BOOST_CONTRACT_NO_OLDS</span> 85 <span class="comment">// This declaration does not need to use `v`.</span> 86 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">contract</span><span class="special">::</span><span class="identifier">old_ptr_if_copyable</span><span class="special"><</span><span class="identifier">old_type</span><span class="special">></span> <span class="identifier">old_var</span> 87<span class="preprocessor">#endif</span> 88</pre> 89<p>2. <code class="computeroutput">BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(old_type)(old_var, old_expr)</code> 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):</p> 90<pre class="programlisting"><span class="preprocessor">#ifndef</span> <span class="identifier">BOOST_CONTRACT_NO_OLDS</span> 91 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">contract</span><span class="special">::</span><span class="identifier">old_ptr_if_copyable</span><span class="special"><</span><span class="identifier">old_type</span><span class="special">></span> <span class="identifier">old_var</span> <span class="special">=</span> 92 <span class="identifier">BOOST_CONTRACT_OLDOF</span><span class="special">(</span><span class="identifier">old_expr</span><span class="special">)</span> 93<span class="preprocessor">#endif</span> 94</pre> 95<p>3. <code class="computeroutput">BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(old_type)(v, old_var, old_expr)</code> expands to code equivalent to the following (this initializes the pointer to the old value copy for virtual public functions and public function overrides):</p> 96<pre class="programlisting"><span class="preprocessor">#ifndef</span> <span class="identifier">BOOST_CONTRACT_NO_OLDS</span> 97 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">contract</span><span class="special">::</span><span class="identifier">old_ptr_if_copyable</span><span class="special"><</span><span class="identifier">old_type</span><span class="special">></span> <span class="identifier">old_var</span> <span class="special">=</span> 98 <span class="identifier">BOOST_CONTRACT_OLDOF</span><span class="special">(</span><span class="identifier">v</span><span class="special">,</span> <span class="identifier">old_expr</span><span class="special">)</span> 99<span class="preprocessor">#endif</span> 100</pre> 101<p>Where:</p> 102<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 103<li class="listitem"><p><code class="computeroutput"><span class="bold"><strong>old_type</strong></span></code> is the type of the pointed old value. If this type is not copyable (i.e., <code class="computeroutput">boost::contract::is_old_value_copyable<old_type>::value</code> is <code class="computeroutput">false</code>), this pointer will always be null, but this library will not generate a compile-time error when this pointer is dereferenced (see <code class="computeroutput"><a class="link" href="BOOST_CONTRACT_OLD_PTR.html" title="Macro BOOST_CONTRACT_OLD_PTR">BOOST_CONTRACT_OLD_PTR</a></code>). (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.) </p></li> 104<li class="listitem"><p><code class="computeroutput"><span class="bold"><strong>v</strong></span></code> is the extra trailing parameter of type <code class="computeroutput"><a class="link" href="boost/contract/virtual_.html" title="Class virtual_">boost::contract::virtual_</a></code><code class="computeroutput">*</code> and default value <code class="computeroutput">0</code> 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.) </p></li> 105<li class="listitem"><p><code class="computeroutput"><span class="bold"><strong>old_var</strong></span></code> 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.) </p></li> 106<li class="listitem"><p><code class="computeroutput"><span class="bold"><strong>old_expr</strong></span></code> 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 <code class="computeroutput">BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(old_type)(v, old_var, (old_expr))</code> will always work.)</p></li> 107</ul></div> 108<p> 109</p> 110<p><span class="bold"><strong>See Also:</strong></span></p> 111<p> <a class="link" href="boost_contract/extras.html#boost_contract.extras.disable_contract_compilation__macro_interface_" title="Disable Contract Compilation (Macro Interface)"> 112 Disable Contract Compilation</a>, <a class="link" href="boost_contract/extras.html#boost_contract.extras.old_value_requirements__templates_" title="Old Value Requirements (Templates)"> 113 Old Value Requirements</a> </p> 114<p> 115</p> 116<p> 117</p> 118</div> 119</div> 120<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 121<td align="left"></td> 122<td align="right"><div class="copyright-footer">Copyright © 2008-2019 Lorenzo Caminiti<p> 123 Distributed under the Boost Software License, Version 1.0 (see accompanying 124 file LICENSE_1_0.txt or a copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>) 125 </p> 126</div></td> 127</tr></table> 128<hr> 129<div class="spirit-nav"> 130<a accesskey="p" href="BOOST_CONTRACT_OLD_PTR.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="reference.html#header.boost.contract_macro_hpp"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="BOOST_CONTRACT_INVARIANT.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a> 131</div> 132</body> 133</html> 134