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