1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Class template 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.old_hpp" title="Header <boost/contract/old.hpp>"> 9<link rel="prev" href="old_ptr.html" title="Class template old_ptr"> 10<link rel="next" href="old_value.html" title="Class old_value"> 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="old_ptr.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../reference.html#header.boost.contract.old_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="old_value.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="refentry"> 26<a name="boost.contract.old_ptr_if_copyable"></a><div class="titlepage"></div> 27<div class="refnamediv"> 28<h2><span class="refentrytitle">Class template old_ptr_if_copyable</span></h2> 29<p>boost::contract::old_ptr_if_copyable — Old value pointer that does not require the pointed old value type 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.old_hpp" title="Header <boost/contract/old.hpp>">boost/contract/old.hpp</a>> 33 34</span><span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> T<span class="special">></span> 35<span class="keyword">class</span> <a class="link" href="old_ptr_if_copyable.html" title="Class template old_ptr_if_copyable">old_ptr_if_copyable</a> <span class="special">{</span> 36<span class="keyword">public</span><span class="special">:</span> 37 <span class="comment">// types</span> 38 <span class="keyword">typedef</span> <span class="identifier">T</span> <a name="boost.contract.old_ptr_if_copyable.element_type"></a><span class="identifier">element_type</span><span class="special">;</span> <span class="comment">// Pointed old value type. </span> 39 40 <span class="comment">// <a class="link" href="old_ptr_if_copyable.html#boost.contract.old_ptr_if_copyableconstruct-copy-destruct">construct/copy/destruct</a></span> 41 <a class="link" href="old_ptr_if_copyable.html#idm46268584825648-bb"><span class="identifier">old_ptr_if_copyable</span></a><span class="special">(</span><span class="special">)</span><span class="special">;</span> 42 <a class="link" href="old_ptr_if_copyable.html#idm46268584825040-bb"><span class="identifier">old_ptr_if_copyable</span></a><span class="special">(</span><a class="link" href="old_ptr.html" title="Class template old_ptr">old_ptr</a><span class="special"><</span> <span class="identifier">T</span> <span class="special">></span> <span class="keyword">const</span> <span class="special">&</span><span class="special">)</span><span class="special">;</span> 43 44 <span class="comment">// <a class="link" href="old_ptr_if_copyable.html#idm46268584840720-bb">public member functions</a></span> 45 <span class="identifier">T</span> <span class="keyword">const</span> <span class="special">&</span> <a class="link" href="old_ptr_if_copyable.html#idm46268584840160-bb"><span class="keyword">operator</span> <span class="special">*</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span> 46 <span class="identifier">T</span> <span class="keyword">const</span> <span class="special">*</span> <a class="link" href="old_ptr_if_copyable.html#idm46268584834560-bb"><span class="keyword">operator</span><span class="special">-></span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span> 47 <span class="keyword">explicit</span> <a class="link" href="old_ptr_if_copyable.html#idm46268584828960-bb"><span class="keyword">operator</span> <span class="keyword">bool</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span> 48<span class="special">}</span><span class="special">;</span></pre></div> 49<div class="refsect1"> 50<a name="idm45988677313168"></a><h2>Description</h2> 51<p>This pointer can be set to point to an actual old value copy using either <code class="computeroutput"><a class="link" href="../../BOOST_CONTRACT_OLDOF.html" title="Macro BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</a></code> or <code class="computeroutput"><a class="link" href="make_old_idm46268584781184.html" title="Function make_old">boost::contract::make_old</a></code>:</p> 52<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> 53<span class="keyword">class</span> <span class="identifier">u</span> <span class="special">{</span> 54<span class="keyword">public</span><span class="special">:</span> 55 <span class="keyword">virtual</span> <span class="keyword">void</span> <span class="identifier">f</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</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">T</span><span class="special">></span> <span class="identifier">old_var</span> <span class="special">=</span> 57 <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><span class="special">;</span> 58 <span class="special">...</span> 59 <span class="keyword">if</span><span class="special">(</span><span class="identifier">old_var</span><span class="special">)</span> <span class="special">...</span> <span class="comment">// Always null for non-copyable types.</span> 60 <span class="special">...</span> 61 <span class="special">}</span> 62 63 <span class="special">...</span> 64<span class="special">}</span><span class="special">;</span> 65</pre> 66<p><span class="bold"><strong>See Also:</strong></span></p> 67<p> <a class="link" href="../../boost_contract/extras.html#boost_contract.extras.old_value_requirements__templates_" title="Old Value Requirements (Templates)"> 68 Old Value Requirements</a></p> 69<p> 70</p> 71<p> 72 73</p> 74<div class="refsect2"> 75<a name="idm45988677272816"></a><h3>Template Parameters</h3> 76<div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem"> 77<pre class="literallayout"><span class="keyword">typename</span> T</pre> 78<p>Type of the pointed old value. If this type is not copyable (i.e., <code class="computeroutput">boost::contract::is_old_value_copyable<T>::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). </p> 79</li></ol></div> 80</div> 81<div class="refsect2"> 82<a name="idm45988677268112"></a><h3> 83<a name="boost.contract.old_ptr_if_copyableconstruct-copy-destruct"></a><code class="computeroutput">old_ptr_if_copyable</code> 84 public 85 construct/copy/destruct</h3> 86<div class="orderedlist"><ol class="orderedlist" type="1"> 87<li class="listitem"> 88<pre class="literallayout"><a name="idm46268584825648-bb"></a><span class="identifier">old_ptr_if_copyable</span><span class="special">(</span><span class="special">)</span><span class="special">;</span></pre>Construct this old value pointer as null. </li> 89<li class="listitem"> 90<pre class="literallayout"><a name="idm46268584825040-bb"></a><span class="identifier">old_ptr_if_copyable</span><span class="special">(</span><a class="link" href="old_ptr.html" title="Class template old_ptr">old_ptr</a><span class="special"><</span> <span class="identifier">T</span> <span class="special">></span> <span class="keyword">const</span> <span class="special">&</span> other<span class="special">)</span><span class="special">;</span></pre>Construct this old value pointer from an old value pointer that requires the old value type to be copyable. <p>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 <code class="computeroutput"><code class="computeroutput"><a class="link" href="../../BOOST_CONTRACT_OLDOF.html" title="Macro BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</a></code></code> (this constructor is usually not explicitly called by user code).</p> 91<p> 92</p> 93<div class="variablelist"><table border="0" class="variablelist compact"> 94<colgroup> 95<col align="left" valign="top"> 96<col> 97</colgroup> 98<tbody><tr> 99<td><p><span class="term">Parameters:</span></p></td> 100<td><div class="variablelist"><table border="0" class="variablelist compact"> 101<colgroup> 102<col align="left" valign="top"> 103<col> 104</colgroup> 105<tbody><tr> 106<td><p><span class="term"><code class="computeroutput">other</code></span></p></td> 107<td><p>Old value pointer that requires the old value type to be copyable. </p></td> 108</tr></tbody> 109</table></div></td> 110</tr></tbody> 111</table></div> 112</li> 113</ol></div> 114</div> 115<div class="refsect2"> 116<a name="idm45988677248640"></a><h3> 117<a name="idm46268584840720-bb"></a><code class="computeroutput">old_ptr_if_copyable</code> public member functions</h3> 118<div class="orderedlist"><ol class="orderedlist" type="1"> 119<li class="listitem"> 120<pre class="literallayout"><span class="identifier">T</span> <span class="keyword">const</span> <span class="special">&</span> <a name="idm46268584840160-bb"></a><span class="keyword">operator</span> <span class="special">*</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>Dereference this old value pointer. <p>This will generate a run-time error if this pointer is null, but no compile-time error is generated if the pointed type <code class="computeroutput">T</code> is not copyable (i.e., if <code class="computeroutput">boost::contract::is_old_value_copyable<T>::value</code> is <code class="computeroutput">false</code>).</p> 121<p> 122</p> 123<div class="variablelist"><table border="0" class="variablelist compact"> 124<colgroup> 125<col align="left" valign="top"> 126<col> 127</colgroup> 128<tbody><tr> 129<td><p><span class="term">Returns:</span></p></td> 130<td><p>The pointed old value. Contract assertions should not change the state of the program so this member function is <code class="computeroutput">const</code> and it returns the old value as a reference to a constant object (see <a class="link" href="../../boost_contract/contract_programming_overview.html#boost_contract.contract_programming_overview.constant_correctness" title="Constant-Correctness"> 131 Constant Correctness</a>). </p></td> 132</tr></tbody> 133</table></div> 134</li> 135<li class="listitem"> 136<pre class="literallayout"><span class="identifier">T</span> <span class="keyword">const</span> <span class="special">*</span> <a name="idm46268584834560-bb"></a><span class="keyword">operator</span><span class="special">-></span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>Structure-dereference this old value pointer. <p>This will return null but will not generate a compile-time error if the pointed type <code class="computeroutput">T</code> is not copyable (i.e., if <code class="computeroutput">boost::contract::is_old_value_copyable<T>::value</code> is <code class="computeroutput">false</code>).</p> 137<p> 138</p> 139<div class="variablelist"><table border="0" class="variablelist compact"> 140<colgroup> 141<col align="left" valign="top"> 142<col> 143</colgroup> 144<tbody><tr> 145<td><p><span class="term">Returns:</span></p></td> 146<td><p>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 <code class="computeroutput">const</code> and it returns the old value as a pointer to a constant object (see <a class="link" href="../../boost_contract/contract_programming_overview.html#boost_contract.contract_programming_overview.constant_correctness" title="Constant-Correctness"> 147 Constant Correctness</a>). </p></td> 148</tr></tbody> 149</table></div> 150</li> 151<li class="listitem"> 152<pre class="literallayout"><span class="keyword">explicit</span> <a name="idm46268584828960-bb"></a><span class="keyword">operator</span> <span class="keyword">bool</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>Query if this old value pointer is null or not (safe-bool operator). <p>(This is implemented using safe-bool emulation on compilers that do not support C++11 explicit type conversion operators.)</p> 153<p> 154</p> 155<div class="variablelist"><table border="0" class="variablelist compact"> 156<colgroup> 157<col align="left" valign="top"> 158<col> 159</colgroup> 160<tbody><tr> 161<td><p><span class="term">Returns:</span></p></td> 162<td><p>True if this pointer is not null, false otherwise. </p></td> 163</tr></tbody> 164</table></div> 165</li> 166</ol></div> 167</div> 168</div> 169</div> 170<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 171<td align="left"></td> 172<td align="right"><div class="copyright-footer">Copyright © 2008-2019 Lorenzo Caminiti<p> 173 Distributed under the Boost Software License, Version 1.0 (see accompanying 174 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>) 175 </p> 176</div></td> 177</tr></table> 178<hr> 179<div class="spirit-nav"> 180<a accesskey="p" href="old_ptr.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../reference.html#header.boost.contract.old_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="old_value.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> 181</div> 182</body> 183</html> 184