Imported Upstream version 1.64.0
[platform/upstream/boost.git] / libs / core / doc / html / core / checked_delete.html
1 <html>
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>checked_delete</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&#160;1.&#160;Boost.Core">
8 <link rel="up" href="../index.html" title="Chapter&#160;1.&#160;Boost.Core">
9 <link rel="prev" href="addressof.html" title="addressof">
10 <link rel="next" href="demangle.html" title="demangle">
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="addressof.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><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="demangle.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
24 </div>
25 <div class="section">
26 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
27 <a name="core.checked_delete"></a><a class="link" href="checked_delete.html" title="checked_delete">checked_delete</a>
28 </h2></div></div></div>
29 <div class="toc"><dl class="toc">
30 <dt><span class="section"><a href="checked_delete.html#core.checked_delete.overview">Overview</a></span></dt>
31 <dt><span class="section"><a href="checked_delete.html#core.checked_delete.synopsis">Synopsis</a></span></dt>
32 <dt><span class="section"><a href="checked_delete.html#core.checked_delete.checked_delete">checked_delete</a></span></dt>
33 <dt><span class="section"><a href="checked_delete.html#core.checked_delete.checked_array_delete">checked_array_delete</a></span></dt>
34 <dt><span class="section"><a href="checked_delete.html#core.checked_delete.checked_deleter">checked_deleter</a></span></dt>
35 <dt><span class="section"><a href="checked_delete.html#core.checked_delete.checked_array_deleter">checked_array_deleter</a></span></dt>
36 <dt><span class="section"><a href="checked_delete.html#core.checked_delete.acknowledgements">Acknowledgements</a></span></dt>
37 </dl></div>
38 <div class="simplesect">
39 <div class="titlepage"><div><div><h3 class="title">
40 <a name="idp81391888"></a>Authors</h3></div></div></div>
41 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
42 <li class="listitem">
43           Beman Dawes
44         </li>
45 <li class="listitem">
46           Dave Abrahams
47         </li>
48 <li class="listitem">
49           Vladimir Prus
50         </li>
51 <li class="listitem">
52           Rainer Deyke
53         </li>
54 <li class="listitem">
55           John Maddock
56         </li>
57 </ul></div>
58 </div>
59 <div class="section">
60 <div class="titlepage"><div><div><h3 class="title">
61 <a name="core.checked_delete.overview"></a><a class="link" href="checked_delete.html#core.checked_delete.overview" title="Overview">Overview</a>
62 </h3></div></div></div>
63 <p>
64         The header <code class="computeroutput"><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">checked_delete</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
65         defines two function templates, <code class="computeroutput"><span class="identifier">checked_delete</span></code>
66         and <code class="computeroutput"><span class="identifier">checked_array_delete</span></code>,
67         and two class templates, <code class="computeroutput"><span class="identifier">checked_deleter</span></code>
68         and <code class="computeroutput"><span class="identifier">checked_array_deleter</span></code>.
69       </p>
70 <p>
71         The C++ Standard allows, in 5.3.5/5, pointers to incomplete class types to
72         be deleted with a delete-expression. When the class has a non-trivial destructor,
73         or a class-specific operator delete, the behavior is undefined. Some compilers
74         issue a warning when an incomplete type is deleted, but unfortunately, not
75         all do, and programmers sometimes ignore or disable warnings.
76       </p>
77 <p>
78         A particularly troublesome case is when a smart pointer's destructor, such
79         as <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">scoped_ptr</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::~</span><span class="identifier">scoped_ptr</span></code>, is instantiated with an incomplete
80         type. This can often lead to silent, hard to track failures.
81       </p>
82 <p>
83         The supplied function and class templates can be used to prevent these problems,
84         as they require a complete type, and cause a compilation error otherwise.
85       </p>
86 </div>
87 <div class="section">
88 <div class="titlepage"><div><div><h3 class="title">
89 <a name="core.checked_delete.synopsis"></a><a class="link" href="checked_delete.html#core.checked_delete.synopsis" title="Synopsis">Synopsis</a>
90 </h3></div></div></div>
91 <pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span>
92 <span class="special">{</span>
93     <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">void</span> <span class="identifier">checked_delete</span><span class="special">(</span><span class="identifier">T</span> <span class="special">*</span> <span class="identifier">p</span><span class="special">);</span>
94     <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">void</span> <span class="identifier">checked_array_delete</span><span class="special">(</span><span class="identifier">T</span> <span class="special">*</span> <span class="identifier">p</span><span class="special">);</span>
95     <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">struct</span> <span class="identifier">checked_deleter</span><span class="special">;</span>
96     <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">struct</span> <span class="identifier">checked_array_deleter</span><span class="special">;</span>
97 <span class="special">}</span>
98 </pre>
99 </div>
100 <div class="section">
101 <div class="titlepage"><div><div><h3 class="title">
102 <a name="core.checked_delete.checked_delete"></a><a class="link" href="checked_delete.html#core.checked_delete.checked_delete" title="checked_delete">checked_delete</a>
103 </h3></div></div></div>
104 <div class="section">
105 <div class="titlepage"><div><div><h4 class="title">
106 <a name="core.checked_delete.checked_delete.template_class_t_void_checked_de"></a><a class="link" href="checked_delete.html#core.checked_delete.checked_delete.template_class_t_void_checked_de" title="template&lt;class T&gt; void checked_delete(T * p);">template&lt;class
107         T&gt; void checked_delete(T * p);</a>
108 </h4></div></div></div>
109 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
110 <li class="listitem">
111               <span class="bold"><strong>Requires:</strong></span> <code class="computeroutput"><span class="identifier">T</span></code>
112               must be a complete type. The expression <code class="computeroutput"><span class="keyword">delete</span>
113               <span class="identifier">p</span></code> must be well-formed.
114             </li>
115 <li class="listitem">
116               <span class="bold"><strong>Effects:</strong></span> <code class="computeroutput"><span class="keyword">delete</span>
117               <span class="identifier">p</span><span class="special">;</span></code>
118             </li>
119 </ul></div>
120 </div>
121 </div>
122 <div class="section">
123 <div class="titlepage"><div><div><h3 class="title">
124 <a name="core.checked_delete.checked_array_delete"></a><a class="link" href="checked_delete.html#core.checked_delete.checked_array_delete" title="checked_array_delete">checked_array_delete</a>
125 </h3></div></div></div>
126 <div class="section">
127 <div class="titlepage"><div><div><h4 class="title">
128 <a name="core.checked_delete.checked_array_delete.template_class_t_void_checked_ar"></a><a class="link" href="checked_delete.html#core.checked_delete.checked_array_delete.template_class_t_void_checked_ar" title="template&lt;class T&gt; void checked_array_delete(T * p);">template&lt;class
129         T&gt; void checked_array_delete(T * p);</a>
130 </h4></div></div></div>
131 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
132 <li class="listitem">
133               <span class="bold"><strong>Requires:</strong></span> <code class="computeroutput"><span class="identifier">T</span></code>
134               must be a complete type. The expression <code class="computeroutput"><span class="keyword">delete</span>
135               <span class="special">[]</span> <span class="identifier">p</span></code>
136               must be well-formed.
137             </li>
138 <li class="listitem">
139               <span class="bold"><strong>Effects:</strong></span> <code class="computeroutput"><span class="keyword">delete</span>
140               <span class="special">[]</span> <span class="identifier">p</span><span class="special">;</span></code>
141             </li>
142 </ul></div>
143 </div>
144 </div>
145 <div class="section">
146 <div class="titlepage"><div><div><h3 class="title">
147 <a name="core.checked_delete.checked_deleter"></a><a class="link" href="checked_delete.html#core.checked_delete.checked_deleter" title="checked_deleter">checked_deleter</a>
148 </h3></div></div></div>
149 <pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">struct</span> <span class="identifier">checked_deleter</span>
150 <span class="special">{</span>
151     <span class="keyword">typedef</span> <span class="keyword">void</span> <span class="identifier">result_type</span><span class="special">;</span>
152     <span class="keyword">typedef</span> <span class="identifier">T</span> <span class="special">*</span> <span class="identifier">argument_type</span><span class="special">;</span>
153     <span class="keyword">void</span> <span class="keyword">operator</span><span class="special">()(</span><span class="identifier">T</span> <span class="special">*</span> <span class="identifier">p</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
154 <span class="special">};</span>
155 </pre>
156 <div class="section">
157 <div class="titlepage"><div><div><h4 class="title">
158 <a name="core.checked_delete.checked_deleter.void_checked_deleter_t_operator_"></a><a class="link" href="checked_delete.html#core.checked_delete.checked_deleter.void_checked_deleter_t_operator_" title="void checked_deleter&lt;T&gt;::operator()(T * p) const;">void
159         checked_deleter&lt;T&gt;::operator()(T * p) const;</a>
160 </h4></div></div></div>
161 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
162 <li class="listitem">
163               <span class="bold"><strong>Requires:</strong></span> <code class="computeroutput"><span class="identifier">T</span></code>
164               must be a complete type. The expression <code class="computeroutput"><span class="keyword">delete</span>
165               <span class="identifier">p</span></code> must be well-formed.
166             </li>
167 <li class="listitem">
168               <span class="bold"><strong>Effects:</strong></span> <code class="computeroutput"><span class="keyword">delete</span>
169               <span class="identifier">p</span><span class="special">;</span></code>
170             </li>
171 </ul></div>
172 </div>
173 </div>
174 <div class="section">
175 <div class="titlepage"><div><div><h3 class="title">
176 <a name="core.checked_delete.checked_array_deleter"></a><a class="link" href="checked_delete.html#core.checked_delete.checked_array_deleter" title="checked_array_deleter">checked_array_deleter</a>
177 </h3></div></div></div>
178 <pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="keyword">struct</span> <span class="identifier">checked_array_deleter</span>
179 <span class="special">{</span>
180     <span class="keyword">typedef</span> <span class="keyword">void</span> <span class="identifier">result_type</span><span class="special">;</span>
181     <span class="keyword">typedef</span> <span class="identifier">T</span> <span class="special">*</span> <span class="identifier">argument_type</span><span class="special">;</span>
182     <span class="keyword">void</span> <span class="keyword">operator</span><span class="special">()(</span><span class="identifier">T</span> <span class="special">*</span> <span class="identifier">p</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
183 <span class="special">};</span>
184 </pre>
185 <div class="section">
186 <div class="titlepage"><div><div><h4 class="title">
187 <a name="core.checked_delete.checked_array_deleter.void_checked_array_deleter_t_ope"></a><a class="link" href="checked_delete.html#core.checked_delete.checked_array_deleter.void_checked_array_deleter_t_ope" title="void checked_array_deleter&lt;T&gt;::operator()(T * p) const;">void
188         checked_array_deleter&lt;T&gt;::operator()(T * p) const;</a>
189 </h4></div></div></div>
190 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
191 <li class="listitem">
192               <span class="bold"><strong>Requires:</strong></span> <code class="computeroutput"><span class="identifier">T</span></code>
193               must be a complete type. The expression <code class="computeroutput"><span class="keyword">delete</span>
194               <span class="special">[]</span> <span class="identifier">p</span></code>
195               must be well-formed.
196             </li>
197 <li class="listitem">
198               <span class="bold"><strong>Effects:</strong></span> <code class="computeroutput"><span class="keyword">delete</span>
199               <span class="special">[]</span> <span class="identifier">p</span><span class="special">;</span></code>
200             </li>
201 </ul></div>
202 </div>
203 </div>
204 <div class="section">
205 <div class="titlepage"><div><div><h3 class="title">
206 <a name="core.checked_delete.acknowledgements"></a><a class="link" href="checked_delete.html#core.checked_delete.acknowledgements" title="Acknowledgements">Acknowledgements</a>
207 </h3></div></div></div>
208 <p>
209         The function templates <code class="computeroutput"><span class="identifier">checked_delete</span></code>
210         and <code class="computeroutput"><span class="identifier">checked_array_delete</span></code>
211         were originally part of <code class="computeroutput"><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">utility</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>,
212         and the documentation acknowledged Beman Dawes, Dave Abrahams, Vladimir Prus,
213         Rainer Deyke, John Maddock, and others as contributors.
214       </p>
215 </div>
216 </div>
217 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
218 <td align="left"></td>
219 <td align="right"><div class="copyright-footer">Copyright &#169; 2014 Peter Dimov<br>Copyright &#169; 2014 Glen Fernandes<br>Copyright &#169; 2014 Andrey Semashev<p>
220         Distributed under the <a href="http://boost.org/LICENSE_1_0.txt" target="_top">Boost
221         Software License, Version 1.0</a>.
222       </p>
223 </div></td>
224 </tr></table>
225 <hr>
226 <div class="spirit-nav">
227 <a accesskey="p" href="addressof.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><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="demangle.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
228 </div>
229 </body>
230 </html>