1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Macro BOOST_CONTRACT_OLD_PTR</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.html" title="Macro BOOST_CONTRACT_OLD"> 10<link rel="next" href="BOOST_CO_idm46268584486544.html" title="Macro BOOST_CONTRACT_OLD_PTR_IF_COPYABLE"> 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.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_CO_idm46268584486544.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="refentry"> 26<a name="BOOST_CONTRACT_OLD_PTR"></a><div class="titlepage"></div> 27<div class="refnamediv"> 28<h2><span class="refentrytitle">Macro BOOST_CONTRACT_OLD_PTR</span></h2> 29<p>BOOST_CONTRACT_OLD_PTR — Program old values that can be completely disabled at compile-time for old value types that are 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(...)</pre></div> 35<div class="refsect1"> 36<a name="idm45988675752480"></a><h2>Description</h2> 37<p>This is used to program old value copies for copyable types:</p> 38<pre class="programlisting"><span class="keyword">class</span> <span class="identifier">u</span> <span class="special">{</span> 39<span class="keyword">public</span><span class="special">:</span> 40 <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> 41 <span class="identifier">BOOST_CONTRACT_OLD_PTR</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> <span class="comment">// Null...</span> 42 <span class="identifier">BOOST_CONTRACT_OLD_PTR</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> <span class="identifier">old_expr_b</span><span class="special">)</span><span class="special">;</span> <span class="comment">// Set.</span> 43 <span class="identifier">BOOST_CONTRACT_PUBLIC_FUNCTION</span><span class="special">(</span><span class="keyword">this</span><span class="special">)</span> 44 <span class="special">...</span> 45 <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> 46 <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> <span class="comment">// ...set.</span> 47 <span class="special">...</span> 48 <span class="special">}</span><span class="special">)</span> 49 <span class="special">...</span> 50 <span class="special">;</span> 51 52 <span class="special">...</span> <span class="comment">// Function body.</span> 53 <span class="special">}</span> 54 55 <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> 56 <span class="identifier">BOOST_CONTRACT_OLD_PTR</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> <span class="comment">// No `v`</span> 57 <span class="identifier">BOOST_CONTRACT_OLD_PTR</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> <span class="identifier">old_expr_b</span><span class="special">)</span><span class="special">;</span> <span class="comment">// `v`</span> 58 <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> 59 <span class="special">...</span> 60 <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> 61 <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> <span class="comment">// `v`</span> 62 <span class="special">...</span> 63 <span class="special">}</span><span class="special">)</span> 64 <span class="special">...</span> 65 <span class="special">;</span> 66 67 <span class="special">...</span> <span class="comment">// Function body.</span> 68 <span class="special">}</span> 69 70 <span class="special">...</span> 71<span class="special">}</span><span class="special">;</span> 72</pre> 73<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> 74<p>1. <code class="computeroutput">BOOST_CONTRACT_OLD_PTR(old_type)(old_var)</code> expands to code equivalent to the following (this leaves the old value pointer null):</p> 75<pre class="programlisting"><span class="preprocessor">#ifndef</span> <span class="identifier">BOOST_CONTRACT_NO_OLDS</span> 76 <span class="comment">// This declaration does not need to use `v`.</span> 77 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">contract</span><span class="special">::</span><span class="identifier">old_ptr</span><span class="special"><</span><span class="identifier">old_type</span><span class="special">></span> <span class="identifier">old_var</span> 78<span class="preprocessor">#endif</span> 79</pre> 80<p>2. <code class="computeroutput">BOOST_CONTRACT_OLD_PTR(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> 81<pre class="programlisting"><span class="preprocessor">#ifndef</span> <span class="identifier">BOOST_CONTRACT_NO_OLDS</span> 82 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">contract</span><span class="special">::</span><span class="identifier">old_ptr</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> 83 <span class="identifier">BOOST_CONTRACT_OLDOF</span><span class="special">(</span><span class="identifier">old_expr</span><span class="special">)</span> 84<span class="preprocessor">#endif</span> 85</pre> 86<p>3. <code class="computeroutput">BOOST_CONTRACT_OLD_PTR(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> 87<pre class="programlisting"><span class="preprocessor">#ifndef</span> <span class="identifier">BOOST_CONTRACT_NO_OLDS</span> 88 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">contract</span><span class="special">::</span><span class="identifier">old_ptr</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> 89 <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> 90<span class="preprocessor">#endif</span> 91</pre> 92<p>Where:</p> 93<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 94<li class="listitem"><p><code class="computeroutput"><span class="bold"><strong>old_type</strong></span></code> is the type of the pointed old value. This type must be copyable (i.e., <code class="computeroutput">boost::contract::is_old_value_copyable<old_type>::value</code> is <code class="computeroutput">true</code>), otherwise this pointer will always be null and this library will generate a compile-time error when the pointer is dereferenced (see <code class="computeroutput"><a class="link" href="BOOST_CO_idm46268584486544.html" title="Macro BOOST_CONTRACT_OLD_PTR_IF_COPYABLE">BOOST_CONTRACT_OLD_PTR_IF_COPYABLE</a></code>). (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 <code class="computeroutput">SOME_MACRO(template_params)(other_params)</code>.) </p></li> 95<li class="listitem"><p><code class="computeroutput"><span class="bold"><strong>v</strong></span></code> is the extra training 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> 96<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> 97<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(old_type)(v, old_var, (old_expr))</code> will always work.)</p></li> 98</ul></div> 99<p> 100</p> 101<p><span class="bold"><strong>See Also:</strong></span></p> 102<p> <a class="link" href="boost_contract/extras.html#boost_contract.extras.disable_contract_compilation__macro_interface_" title="Disable Contract Compilation (Macro Interface)"> 103 Disable Contract Compilation</a>, <a class="link" href="boost_contract/tutorial.html#boost_contract.tutorial.old_values" title="Old Values"> Old Values</a> </p> 104<p> 105</p> 106<p> 107</p> 108</div> 109</div> 110<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 111<td align="left"></td> 112<td align="right"><div class="copyright-footer">Copyright © 2008-2019 Lorenzo Caminiti<p> 113 Distributed under the Boost Software License, Version 1.0 (see accompanying 114 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>) 115 </p> 116</div></td> 117</tr></table> 118<hr> 119<div class="spirit-nav"> 120<a accesskey="p" href="BOOST_CONTRACT_OLD.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_CO_idm46268584486544.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a> 121</div> 122</body> 123</html> 124